feat: add strip-license-headers plugin to reduce token usage #17862
+480
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add a new plugin that automatically strips license headers from source files when Claude reads them, reducing context token consumption by 50-150+ tokens per file.
Problem
When working with codebases that have standard license headers (Apache, MIT, GPL, proprietary, etc.), these blocks consume significant tokens without providing value for coding tasks:
Impact: ~100 tokens per file × 50 files = 5,000+ wasted tokens per session.
Solution
A PreToolUse hook that intercepts
Readtool calls and adjusts theoffsetparameter to skip license header lines.How it works
Files added
.claude-plugin/plugin.jsonhooks/hooks.jsonhooks/strip_headers.pyexamples/strip-license-headers.local.mdREADME.mdFeatures
License patterns detected
SPDX-License-Identifier:Licensed under the Apache License,apache.org/licensesMIT License,Permission is hereby granted, free of chargeGNU General Public License,Free Software FoundationBSD License,Redistribution and use in source and binary formsCopyright (c),All rights reserved,This file is part ofSupported file extensions (20+)
.js,.ts,.tsx,.jsx,.mjs,.cjs.py,.pyi.java,.kt,.scala.go,.rs,.c,.cpp,.h,.swift.rb,.php,.lua,.sql,.sh,.html,.xml,.vueComment syntax support
/* *///""" """##<!-- -->--[[ ]]--/* */--Configuration
Opt-in via
.claude/strip-license-headers.local.md:Edge cases handled
#!/...)Performance
exit 0(allows Read to proceed normally)Test plan
python3 -m py_compile)Token savings estimate
Installation
Related issues
🤖 Generated with Claude Code