| name | evaluate |
| description | Evaluate .claude/ directory token efficiency and generate a score report |
| allowed-tools | Read, Grep, Glob |
Token Efficiency Evaluation
You are ctxcraft evaluator โ an expert at analyzing AI agent context configurations for token efficiency.
Trigger
User runs /evaluate or asks to analyze their .claude/ token usage.
Execution Steps
Step 0: Detect Output Language
Determine the output language for the report:
- Check
CLAUDE.md and rules/ files โ if the majority of content is in a non-English language (e.g., Korean, Japanese, Chinese), use that language for the report.
- Fallback โ default to English.
Detection heuristic: Read the first 30 lines of CLAUDE.md. If >50% of non-code lines contain CJK characters (Korean/Japanese/Chinese), set locale to that language.
| Detected | Report Language | Example Labels |
|---|
| Korean (ํ๊ตญ์ด) | Korean | ํ์ง, ๋น์ฉ, ์ฌ์ , ๊ฒฝ๊ณ , ์ฌ๊ฐ |
| Japanese (ๆฅๆฌ่ช) | Japanese | ๅ่ณช, ใณในใ, ่ฏๅฅฝ, ่ญฆๅ, ้ๅคง |
| Chinese (ไธญๆ) | Chinese | ่ดจ้, ๆๆฌ, ่ฏๅฅฝ, ่ญฆๅ, ไธฅ้ |
| Default | English | Quality, Cost, Comfortable, Warning, Critical |
Apply the detected language to ALL report output: headings, labels, descriptions, and recommendations.
Step 1: Scan Directory Structure
Scan the project's .claude/ directory:
.claude/
โโโ CLAUDE.md โ always loaded (+ @imports, max depth 4)
โโโ rules/**/*.md without paths: โ always loaded (recursive, subdirs OK)
โโโ rules/**/*.md with paths: โ on-demand (loads only when matching files are read)
โโโ skills/ โ descriptions always loaded; bodies on-demand
โ (exception: disable-model-invocation skills load NO description)
โโโ agents/ โ descriptions always loaded; body on spawn
โ (note: a spawned subagent reloads the full CLAUDE.md hierarchy + rules)
โโโ commands/ โ legacy custom commands (merged into skills; still work, on-demand)
โโโ hooks/ โ shell scripts, not loaded as context
โโโ scratch/ โ temporary, not loaded
โโโ other .md files
Also check auto memory at ~/.claude/projects/<project-path-with-dashes>/memory/MEMORY.md โ only the first 200 lines or 25KB load at session start.
Also check the project root for CLAUDE.md โ this is always loaded, and follow its @path imports (they load at launch too; imports inside backticks or code fences don't count).
Step 2: Measure Token Usage
For each file, estimate tokens:
- Rule of thumb: 1 line โ 10-15 tokens (avg for markdown with code)
- Count total lines per file using the Read tool (do NOT use Bash
wc -l)
- Exclude block-level HTML comments (
<!-- ... -->) โ they are stripped before injection and cost 0 tokens
- Categorize as:
- Always-loaded:
CLAUDE.md (root + .claude/) plus its @path import chain (max depth 4), rules/ files WITHOUT paths: frontmatter, skill descriptions (except disable-model-invocation: true skills)
- On-demand:
rules/ files WITH paths: frontmatter, skill bodies, agent bodies
- Inactive:
hooks/, scratch/, config files โ not counted as context tokens
- Remember: every spawned subagent reloads the full CLAUDE.md hierarchy + always-on rules in its own context, so always-on weight is multiplied by subagent usage
Step 3: Detect Issues โ Quality
Quality issues affect adherence regardless of plan tier.
๐ด Critical
CLAUDE.md exceeds 200 lines (official: "target under 200 lines per CLAUDE.md file" โ https://code.claude.com/docs/en/memory.md)
- Duplicate paragraphs or sections across files (risk of contradiction)
- Broken cross-references:
/skill-name in rules/CLAUDE.md pointing to non-existent skills/
๐ก Warning
- Any single
rules/ file exceeds 150 lines (focus degradation)
CLAUDE.md contains content that duplicates rules/ files
- No progressive disclosure (everything in rules, nothing in skills)
- Agents that duplicate skill functionality
๐ข Info
- Content in
rules/ that could be a skill (only needed for specific tasks)
- Skills with very large SKILL.md files (>150 lines without references/ split; official cap is 500)
- Rules that are too granular (could be merged)
- Skills that haven't been referenced recently (check learning-log if available)
Step 4: Run 25-Point Checklist and Calculate Quality Score
Quality score measures structural health โ same for all plan tiers.
Run ALL 25 checks below. Each check results in PASS (0), WARN (-1), or FAIL (-3).
Token Efficiency (1โ8)
| # | Check | PASS | WARN | FAIL |
|---|
| 1 | CLAUDE.md size | โค 200 lines | 201โ500 | > 500 |
| 2 | Always-on tokens (CLAUDE.md + rules/) | โค 8,000 | 8,001โ12,000 | > 12,000 |
| 3 | Rules file size (individual) | all โค 100 lines | any 101โ150 | any > 150 |
| 4 | Rules file count | โค 15 | 16โ20 | > 20 |
| 5 | Duplicate sections (CLAUDE.md โ rules/) | 0 | 1โ2 | โฅ 3 |
| 6 | Progressive disclosure (on-demand โฅ 50%) | โฅ 50% | 30โ49% | < 30% |
| 7 | Skills file size (official cap 500 lines; ctxcraft strict 150) | all โค 150 lines | any 151โ500 | any > 500 |
| 8 | Token allocation (always-on โค 30% of total) | โค 30% | 31โ50% | > 50% |
Structural Validity (9โ25)
| # | Check | PASS | WARN | FAIL |
|---|
| 9 | Agent frontmatter (valid YAML --- block) | all valid | โ | any invalid |
| 10 | Agent required fields (name/description โ tools is optional per spec) | all present | any missing | โ |
| 11 | Skill frontmatter (valid YAML --- block) | all valid | โ | any invalid |
| 12 | Skill references links (files exist) | all exist | โ | any missing |
| 13 | Rules skill references (> See also / > ์ฌํ pattern) | all rules have ref | most have | < 50% have |
| 14 | Rules conditional loading (paths: frontmatter โ official lazy-load) | scoped rules used, or always-on rules small | large always-on rules, none scoped | โ |
| 15 | Skills orphan directories (SKILL.md exists) | none orphaned | โ | any orphaned |
| 16 | Skill description length (description + when_to_use โค 1,536 chars โ excess is truncated in listing) | all within | any over | โ |
| 17 | Agent skills references valid | all valid | โ | any invalid |
| 18 | Agent least privilege (read-only agents) | correct | โ | Write/Edit on reviewer/auditor |
| 19 | Rules enforcement keywords (MUST/SHOULD/NEVER) | present | โ | missing |
| 20 | CLAUDE.md โ Skills sync | all referenced skills exist | โ | any missing |
| 21 | Auto memory (MEMORY.md within 200-line/25KB load limit) | within limit or absent | over limit | โ |
| 22 | Agent model specified | all specified | โ | any missing |
| 23 | Context saving (scratch dir + save rules) | present | partial | missing |
| 24 | Agent model cost (opus โค 2) | โค 2 opus | 3 opus | > 3 opus |
| 25 | Cross-reference validity | all valid | โ | any broken |
Score calculation (same formula as evaluate.sh):
Each scored check earns: PASS = 10, WARN = 5, FAIL = 0
Checks marked "N/A" (ํด๋น ์์) are EXCLUDED from scoring โ no free points
Quality Score = (earned points / (scored_checks ร 10)) ร 100
Grades: A (90โ100), A- (80โ89), B+ (70โ79), B (60โ69), C (50โ59), D (40โ49), F (0โ39)
IMPORTANT: Do NOT penalize on-demand skills/agents for being "unused" โ they are designed to be loaded only when needed. Only penalize always-loaded files.
Step 5: Assess Cost Impact โ by Plan Tier
Cost impact is informational, not scored. Show how much of the plan's context budget is consumed.
Plan Tier Thresholds
| Plan | Context Window | Comfortable | Warning | Critical |
|---|
| Pro | 200K | < 15,000 tokens | 15,000โ25,000 | > 25,000 |
| Max 5x | 200K | < 20,000 tokens | 20,000โ35,000 | > 35,000 |
| Max 20x | 200K | < 25,000 tokens | 25,000โ40,000 | > 40,000 |
| Team | 200K | < 20,000 tokens | 20,000โ35,000 | > 35,000 |
| Opus 1M | 1M | < 50,000 tokens | 50,000โ80,000 | > 80,000 |
Agent Model Cost (informational)
- opus/fable=5x, sonnet=1x, haiku=0.2x (base: sonnet);
inherit (default) follows the session model
- Show weighted cost breakdown per agent
- More than 2 opus-tier agents โ suggest reviewing if all need opus
Subagent Multiplier (informational)
Every spawned subagent reloads the FULL CLAUDE.md hierarchy + always-on rules into its own context (built-in Explore/Plan agents are the exception). Report this as:
Subagent respawn cost: ~{always_tokens} tokens per spawn
- Heavy always-on config ร frequent subagent use = multiplied waste โ this is the strongest quantitative argument for trimming always-on files
Detect Plan Tier
Check the current model to infer plan context:
- If model contains "1m" or "1M" โ Opus 1M tier
- Otherwise, ask user or default to "Max 5x" as baseline
Step 6: Generate Report
Output a clean, readable report with two separate sections:
English (default):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ctxcraft โ Token Efficiency Report โ
โ โ
โ Quality: XX/100 (Grade X) โ structural health โ
โ Cost: Comfortable|Warning|Critical โ plan tier โ
โ โ
โ ๐ Token Analysis โ
โ Always-loaded: ~X,XXX tokens (XX files) โ
โ On-demand: ~X,XXX tokens (XX files) โ
โ โ
โ ๐๏ธ Quality Issues โ
โ ๐ด Critical (N) โ
โ โข [specific issue + fix] โ
โ ๐ก Warning (N) โ
โ โข [specific issue + fix] โ
โ ๐ข Info (N) โ
โ โข [optimization opportunity] โ
โ โ
โ ๐ฐ Cost Impact (Opus 1M tier) โ
โ Always-loaded: XX,XXX / 50,000 tokens โ Comfy โ
โ opus agents: N (weighted cost XX%) โ
โ โ
โ ๐ก Quick Wins โ
โ โข [top 3 easiest improvements] โ
โ โ
โ Run /optimize to apply improvements. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Korean (when detected):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ctxcraft โ ํ ํฐ ํจ์จ ๋ฆฌํฌํธ โ
โ โ
โ ํ์ง: XX/100 (๋ฑ๊ธ X) โ ๊ตฌ์กฐ์ ๊ฑด๊ฐ๋ (ํ๋ ๋ฌด๊ด) โ
โ ๋น์ฉ: ์ฌ์ |๋ณดํต|์ฃผ์ โ ํ๋ ๊ธฐ์ค โ
โ โ
โ ๐ ํ ํฐ ๋ถ์ โ
โ ์์ ๋ก๋: ~X,XXX ํ ํฐ (XX ํ์ผ) โ
โ ์จ๋๋งจ๋: ~X,XXX ํ ํฐ (XX ํ์ผ) โ
โ โ
โ ๐ด ์ฌ๊ฐ (N๊ฑด) / ๐ก ๊ฒฝ๊ณ (N๊ฑด) / ๐ข ์ฐธ๊ณ (N๊ฑด) โ
โ โ
โ /optimize ์คํ์ผ๋ก ๊ฐ์ ์ ์ ์ฉํ์ธ์. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Step 7: Save Report
Save the full report to .claude/scratch/ctxcraft-report.md for reference.
Also save the machine-readable before-state to .claude/scratch/ctxcraft-before.json so /optimize can show a before/after comparison:
{
"score": 0, "grade": "", "always_tokens": 0, "ondemand_tokens": 0,
"total_tokens": 0, "pass": 0, "warn": 0, "fail": 0, "saveable_tokens": 0
}
Important Rules
- DO NOT modify any files during evaluation โ read only
- Be specific in recommendations โ "CLAUDE.md line 45-80 duplicates rules/architecture.md" not "there is duplication"
- Always show estimated token savings for each recommendation
- Quality score and cost impact are SEPARATE โ never mix them into one number
- If
.claude/ directory doesn't exist, inform the user and exit gracefully