From claude-optimize
Use when running /optimize:context to analyze and reduce token consumption in Claude Code configuration. Measures CLAUDE.md token count, skill description bloat, MCP tool count, and recommends compaction strategies. Triggers on context optimization, token reduction, or CLAUDE.md bloat analysis. Do NOT trigger on general coding tasks.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-optimize:context-optimizerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Analyzes Claude Code environment for token efficiency and recommends reductions. Powers `/optimize:context` and the context efficiency dimension of `/optimize:audit`.
Analyzes Claude Code environment for token efficiency and recommends reductions. Powers /optimize:context and the context efficiency dimension of /optimize:audit.
Claude Code reserves a buffer of ~33K-45K tokens for system instructions, CLAUDE.md content, skill descriptions, and tool definitions. Every token used by configuration is a token unavailable for actual work. Bloated configurations lead to:
ALWAYS use the bundled script for token measurement — it provides deterministic, consistent results across all runs. Do NOT estimate tokens manually, generate ad-hoc counting code, or run shell commands like wc, cat, ls, find, or for loops.
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/token_counter.py --claude-md --json
For specific files:
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/token_counter.py <file1> <file2> --json --summary
The script automatically applies word-based token estimation (words × 1.3) and classifies into bands:
Use the CLAUDE.md validator to detect stale references and cross-reference issues:
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/claude_md_validator.py --auto-discover --json
The script detects stale file paths and invalid commands automatically. For the remaining qualitative analysis, Read each CLAUDE.md file (the token_counter output from Step 1 lists all discovered files) and look for:
ALWAYS use the bundled script for skill description analysis. Do NOT manually count words or parse YAML frontmatter.
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/skill_analyzer.py --auto-discover --json
The script automatically:
ALWAYS use the bundled script for MCP analysis. Do NOT manually parse .mcp.json or estimate tool counts.
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/mcp_health_check.py --json
The script automatically:
The permission_auditor output (Step 1 --json output) includes a precompact_hook field. Check has_precompact_hook — if false, recommend creating one that preserves:
## Context Efficiency Report
**Overall Grade**: [A-F] ([score]/100)
### CLAUDE.md Token Budget ([score]/40)
| File | Lines | Est. Tokens | Status |
|------|-------|-------------|--------|
| CLAUDE.md | XX | ~XXXX | [grade] |
| .claude.local.md | XX | ~XXXX | [grade] |
| Total | XX | ~XXXX | [grade] |
### Instruction Quality ([score]/25)
| Issue | Count | Impact |
|-------|-------|--------|
| Redundant instructions | X | ~XXX tokens recoverable |
| Verbose instructions | X | ~XXX tokens recoverable |
| Stale instructions | X | ~XXX tokens recoverable |
| Default-behavior duplicates | X | ~XXX tokens recoverable |
### Skill Description Efficiency ([score]/20)
| Skill | Description Words | Status |
|-------|-------------------|--------|
| [name] | XX | [OK/Bloated/Vague] |
### MCP Tool Load ([score]/15)
| Server | Tools (est.) | Loading | Impact |
|--------|--------------|---------|--------|
| [name] | XX | Always/Deferred | ~XXX tokens |
### Compaction Resilience
- PreCompact hook: Present/Missing
- Critical context preservation: Yes/No
### Recommended Actions
1. [Action] - saves ~XXX tokens
2. [Action] - saves ~XXX tokens
Total recoverable: ~XXXX tokens
Reference: ${CLAUDE_PLUGIN_ROOT}/skills/context-optimizer/references/compaction-strategies.md
Context efficiency dimension (15% of total score):
npx claudepluginhub btcdlabs/btcd-cc-marketplace --plugin claude-optimizeAudits Claude Code setup for token waste and context bloat. Checks MCP servers, CLAUDE.md, skills, and settings. Trigger with 'audit my context', 'usage audit', or similar phrases.
Audits Claude Code context window usage across agents, skills, rules, MCP servers, and CLAUDE.md. Detects bloat, redundancy, and recommends prioritized token-saving optimizations.
Optimizes .claude/ configurations to cut token usage: compresses CLAUDE.md under 150 lines, deduplicates content, prunes unused skills with confirmation, extracts verbose sections to on-demand skills. Requires prior /evaluate.