context-surgeon
Skill0 starsChanged 7 months agoMITView on GitHub
Audit what Claude Code loads into context before the user types — total always-on tokens, per-source breakdown, and findings across four categories (clipped skill descriptions, rules that never apply, duplicates, possible conflicts). Use when the user asks about CLAUDE.md size, token budget, agent config bloat, whether a skill is being truncated, why a rule seems to be ignored, or what's eating their context window.
- Reads credentials
- Installs packages
2 other projects use a version of this.
Adopted by
Most recently taken up by
- edenbuilds/agentlooptheir own version, first seen Oct 13, 2026
- Feli2arias/context-surgeontheir own version, first seen Apr 7, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- edenbuilds/agentloop★ 0same name
- Feli2arias/context-surgeon★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
When this skill activates, do the following:
- Very specific: line 14
Run npx context-surgeon audit --json in the current working directory.
- Very specific: line 16
If npx context-surgeon is not available, tell the user: "This skill requires context-surgeon.
- Very specific: line 47
If the report contains any possible-conflict findings and the mode is "estimate", mention once per session (not per finding): "Offline mode …
- Very specific: line 55
If the user says "run in exact mode" or similar, check process.env.ANTHROPIC_API_KEY.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
context-surgeon — Claude Code skill
When this skill activates, do the following:
1. Run the audit
Run npx context-surgeon audit --json in the current working directory. If the user has set ANTHROPIC_API_KEY, the CLI auto-upgrades to exact token counts and real conflict classification; you don't need to pass anything special.
If npx context-surgeon is not available, tell the user: "This skill requires context-surgeon. Install with npm install -g context-surgeon, then re-run."
2. Parse the JSON report
The CLI writes a single JSON object to stdout with these top-level fields:
cwd,total,contextWindow,mode("estimate"or"exact")sources: array of{ path, kind, scope, bucket, tokens, label }findings: array of objects withkind,severity,estimatedTokensReclaimed, plus finding-specific fields
Group findings by kind:
clipped— skill metadata past the 1,536-char menu limitpath-mismatch— rule'spaths:frontmatter matches no files in the repolanguage-mismatch— rule references a language the repo doesn't useduplicate— paragraph-level near-identical text across two filespossible-conflict— topically-similar paragraphs (offline mode only)conflict— Claude Haiku verdict that two paragraphs contradict (exact mode)
3. Summarize in your own voice
Lead with the headline numbers:
Your always-on context is N tokens before you type. I found X warnings and Y notes — ~Z tokens reclaimable if you act on the warnings.
Then, per finding: name the file by short path, describe the issue in one sentence, and propose a concrete edit. Not "fix it" — "delete lines 15–22 of .claude/rules/python-legacy.md, or delete the file if this repo will never have Python."
For duplicate findings: show both paths + line numbers. Recommend keeping one copy.
4. Notes about possible-conflicts
If the report contains any possible-conflict findings and the mode is "estimate", mention once per session (not per finding): "Offline mode can only flag candidate pairs on similar topics. Set ANTHROPIC_API_KEY and re-run for Claude Haiku to classify real contradictions vs. just-related paragraphs."
5. Do not auto-edit
Propose edits as unified diffs or specific "delete line X" instructions. Ask before modifying files. If the user says "go ahead" or "apply them," then proceed — but one file at a time, confirming after each.
6. Exact-mode re-run
If the user says "run in exact mode" or similar, check process.env.ANTHROPIC_API_KEY. If set, re-run npx context-surgeon audit --json; the CLI picks up the key automatically. If not set, ask the user to export it first.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

