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.
npx claudepluginhub btcdlabs/btcd-cc-marketplace --plugin claude-optimizeThis skill uses the workspace's default tool permissions.
Analyzes Claude Code environment for token efficiency and recommends reductions. Powers `/optimize:context` and the context efficiency dimension of `/optimize:audit`.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Designs, implements, and audits WCAG 2.2 AA accessible UIs for Web (ARIA/HTML5), iOS (SwiftUI traits), and Android (Compose semantics). Audits code for compliance gaps.
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):