token-optimizer
Skill1 starsChanged 3 months agoApache-2.0View on GitHub
Use when restructuring Claude Code setup for cost efficiency — deep 5-minute audit of CLAUDE.md, settings, MCP servers, skills, hooks, and cache patterns. Use when user says "optimize my setup", "reduce costs", "token optimizer", "why is Claude expensive", or "audit my config". Not for quick context checks (use token-hygiene instead).
24 other projects use a version of this.
Adopted by
Most recently taken up by
- blinkboxhq/Blinkboxtheir own version, first seen Nov 8, 2026
- ZhouYinLong-lab/Dog-Skillstheir own version, first seen Nov 8, 2026
- Tejas9406/vibe-coding-ostheir own version, first seen Nov 1, 2026
- vikneshwaran16032005-alt/claude-skillstheir own version, first seen Oct 23, 2026
- Anmolop97/Agent-Skillstheir own version, first seen Oct 20, 2026
- tingyulu/MyR2D2their own version, first seen Oct 16, 2026
Used with
Projects with it also use mcp-builder, webapp-testing and 1 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillmcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Also in 4 projects that use this
JetBrainsSkillwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Also in 3 projects that use this
SentrySkillskill-creator
Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.
Also in 5 projects that use this
Other versions24 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 24
- alexgreensh/token-optimizer★ 2.9ksame name
- nitinjain999/platform-skills★ 71same name
- georgekhananaev/claude-skills-vault★ 28same name
- aayushostwal/nexus★ 19same name
- tingyulu/MyR2D2★ 19same name
- thesaifalitai/claude-setup★ 9same name
- GPire/claude-skills-swarm★ 8same name
- ZhouYinLong-lab/Dog-Skills★ 7same name
- samibajwaisking/Token-Optimizer-Skill★ 6same name
- amunozdev/token-optimizer★ 4same name
14 more not listed
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.
In this repository2 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- token-hygieneSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 18 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Run the audit script first, then dispatch subagents for each phase.
- Distinctive: line 23
Run the audit script to collect raw data for all phases:
- Distinctive: line 29
If the script is not available, gather manually:
- Very specific: line 191
Use references/pricing.md for per-token costs.
“Common” is measured: kept by at least 6 in 10 of the 18 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Token Optimizer
Deep audit of your Claude Code setup for token and cost efficiency. Produces a report with specific, actionable recommendations and estimated savings.
This skill vs token-hygiene: token-hygiene is a 30-second snapshot ("how's my context right now?"). This skill is a 5-minute deep analysis ("how should I restructure my entire setup?").
Workflow
Run the audit script first, then dispatch subagents for each phase. Synthesize findings into the final report.
Step 0: Gather Metrics
Run the audit script to collect raw data for all phases:
bash skills/token-optimizer/scripts/audit-context.shIf the script is not available, gather manually:
# CLAUDE.md sizes
wc -l -w ~/.claude/CLAUDE.md 2>/dev/null
find . -maxdepth 3 -name "CLAUDE.md" -exec wc -l -w {} +
# Skills inventory
find ~/.claude/skills/ -name "SKILL.md" -exec wc -l {} + 2>/dev/null | sort -rn | head -15
# Settings
cat ~/.claude/settings.json 2>/dev/null
cat .claude/settings.json 2>/dev/null
cat .claude/settings.local.json 2>/dev/null
# MCP config
cat .mcp.json 2>/dev/null
cat ~/.claude/.mcp.json 2>/dev/null
# .claudeignore
cat .claudeignore 2>/dev/null || echo "MISSING"
# Hooks
grep -A5 '"hooks"' ~/.claude/settings.json .claude/settings.json 2>/dev/null
# Recent cache patterns from transcripts (cache_read_input_tokens: 0=miss, >0=hit)
project_dir=$(echo "$(pwd)" | sed 's/\//-/g')
find ~/.claude/projects/$project_dir -name "*.jsonl" -mtime -1 \
-exec grep -c '"cache_read_input_tokens":0' {} + 2>/dev/null | head -5Step 1: Dispatch Audit Subagents
Launch these in parallel using Haiku subagents. Pass each agent the raw metrics from Step 0.
Agent 1 — CLAUDE.md Audit:
Analyze these CLAUDE.md files for token waste. For each file report: line count, estimated token count (~0.75 tokens/word), what can be cut (generic advice, inferrable conventions, framework basics), what should move to skills or path-scoped rules, and what should stay. Reference
references/checklist.mdfor thresholds. Target: global <200 lines/<500 tokens, project <50 lines.
Agent 2 — Settings & Cache Audit:
Analyze these settings.json files against the recommended values in
references/settings-guide.md. Flag: missing/wrong autocompact threshold (should be 60-70%), missing cache TTL extension, subagent model not set to Haiku, default effort level, missing session/daily limits. Check for VS Code autosave (claudeCode.autosave: true) which causes cache invalidation.
Agent 3 — MCP & Tools Audit:
Analyze these MCP configs. For each server report two overhead estimates: (1) raw schema tokens if all tools are loaded (~1,300 tokens per 21 tools), and (2) effective overhead with Tool Search enabled (85-95% lower — Tool Search is on by default since v2.1.x and loads only relevant schemas per turn). Label both clearly so users know which applies if Tool Search is disabled. Check if each server has a zero-overhead CLI equivalent (gh, aws, gcloud, kubectl). Flag servers with >30 tools. Recommend consolidation.
Agent 4 — Skills & Hooks Audit:
Analyze the skills inventory. Flag: skills over 200 lines, skills missing
disable-model-invocation: truein frontmatter, total skill metadata overhead (~100 tokens each). Check hooks for verbose output filtering opportunities. Check .claudeignore existence and coverage.
Agent 5 — Cache Pattern Analysis (optional, if transcripts exist):
Analyze cache hit/miss data from JSONL transcripts. The key field is
cache_read_input_tokens— a value of 0 means cache miss, >0 means cache hit. Calculate hit rate per session. If hit rate is below 80%, flag it and suggest causes: model/effort switching mid-session, MCP server connect/disconnect, or VS Code autosave. Also checkcache_creation_input_tokensfor unusually large cache writes.
Agent 6 — Model Selection Audit:
Analyze session JSONL transcripts for main-thread model usage (the
modelfield per turn). For each session, report which model(s) were used, session length, and whether an escalation pattern is visible (started cheap, moved up) versus flat single-tier usage throughout. Referencereferences/model-selection.mdfor the task→model ladder. Flag sessions that ran entirely on the most expensive available tier (Opus/Fable) without any visible escalation from a cheaper model — note this only as a pattern to review, don't guess at task intent beyond what's in the transcript. Also check for/fastmode usage, which runs at frontier-model cost for speed; flag if it appears to be left on for routine work.
Step 2: Synthesize Report
Collect all subagent findings. For each recommendation, estimate savings using references/pricing.md. Produce the report in the format below.
Report Format
# Token Optimization Report
Generated: [date] | Project: [directory name]
Estimated monthly savings: $X-Y (or N% reduction)
## Executive Summary
[2-3 sentences: biggest finding, estimated impact, effort level]
## Findings
### 1. CLAUDE.md Overhead
| File | Lines | Est. Tokens | Target | Status |
|------|-------|-------------|--------|--------|
| ~/.claude/CLAUDE.md | N | N | <500 | OK/WARN/CRIT |
| ./CLAUDE.md | N | N | <250 | OK/WARN/CRIT |
**Recommendations:**
- [specific items to cut, move to skills, or scope]
- Estimated savings: N tokens/message × ~$X/month
### 2. Settings Optimization
| Setting | Current | Recommended | Impact |
|---------|---------|-------------|--------|
| autocompact threshold | 83.5% | 65% | Fewer expensive late compactions |
| subagent model | (default) | haiku | 3-5x cheaper research tasks |
| cache TTL | 5m | 1h | 82% input cost reduction |
| ... | ... | ... | ... |
**Suggested settings.json diff:**
```json
// Add to .claude/settings.json or env
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "65",
"CLAUDE_CODE_SUBAGENT_MODEL": "claude-haiku-4-5-20251001"
}
}3. MCP Server Overhead
| Server | Est. Tokens | defer_loading | CLI Alt | Action |
| github | ~46,000 | no | gh CLI | Switch to CLI |
| ... | ... | ... | ... | ... |
4. Skills Inventory
| Metric | Value | Target | Status |
| Total skills | N | - | INFO |
| Over 200 lines | N | 0 | WARN |
| Missing disable-model-invocation | N | 0 | WARN |
| Total metadata overhead | ~N tokens | - | INFO |
5. File Exclusions (.claudeignore)
| Status | Detail |
| Exists | yes/NO |
| Covers node_modules | yes/NO |
| Covers build artifacts | yes/NO |
| Covers .git | yes/NO |
6. Hooks & Output Filtering
| Check | Status | Action |
| PostToolUse Bash filter | yes/NO | Add output truncation hook |
| PreToolUse guards | yes/NO | Block expensive commands |
7. Cache Health Patterns
| Session | Hits | Misses | Hit Rate | Status |
| [session-id] | N | N | N% | OK if >80%, WARN if <80% |
If hit rate <80%: check for model/effort switching, MCP churn, VS Code autosave.
8. Model Selection (Main Thread)
| Session | Models Used | Turns | Escalation Pattern | Fast Mode | Flag |
| [session-id] | Sonnet→Opus / Opus only / ... | N | yes/no | on/off | OK/WARN/CRIT |
Flag sessions running entirely on the most expensive available tier for what looks like routine work, and any session with /fast left on without apparent need. See references/model-selection.md for the task→model ladder to cite in recommendations.
Priority Actions
| # | Action | Effort | Savings | How |
| 1 | [highest impact] | [min/hr] | [$/tokens] | [specific steps] |
| 2 | ... | ... | ... | ... |
| 3 | ... | ... | ... | ... |
Savings Estimate
| Category | Current Cost | Optimized Cost | Savings |
| CLAUDE.md overhead | ~N tokens/msg | ~N tokens/msg | N% |
| MCP schemas | ~N tokens/msg | ~N tokens/msg | N% |
| Cache misses | ~N/session | ~N/session | N% |
| Model tier (routine tasks) | ~N tokens/msg @ Opus/Fable rate | ~N tokens/msg @ Sonnet rate | N% |
| Total estimated | N% / ~$X/month |
## Savings Estimation Method
Use `references/pricing.md` for per-token costs. Key formulas:
- **CLAUDE.md savings:** (current_tokens - target_tokens) × messages_per_session × sessions_per_day × input_cost
- **MCP savings:** removed_server_tokens × messages_per_session × input_cost (or ×0.1 if cache hits)
- **Cache hit improvement:** avoided_misses × full_context_tokens × (input_cost - cache_read_cost)
- **Subagent model switch:** delegated_tokens × (current_model_cost - haiku_cost)
Assume defaults: ~50 messages/session, ~5 sessions/day, unless user provides actuals.
## Common Mistakes
- Loading all research reports into one context (use subagents to read them)
- Recommending settings without checking if user is on subscription vs API (cache TTL only helps API users)
- Suggesting `.claudeignore` patterns that would exclude needed source files
- Forgetting that path-scoped rules trigger on read, not write
- Overestimating subagent cache savings — subagent caching is hardcoded off (`enablePromptCaching: false`), so 1h cache TTL is irrelevant for multi-agent workflows. Factor this into savings estimates.
- Ignoring community tools — projects like ecotokens, token-optimizer-mcp, and foveance offer 75-95% savings via hook-based filtering and response caching. Mention these as "further optimization" options in the report.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.

