optimize
Apply token optimization improvements based on evaluation results
Instalar con Codex o Claude Copia este prompt, pรฉgalo en Codex, Claude u otro asistente, y deja que revise la pรกgina de la skill y la instale por ti.
Menรบ
Apply token optimization improvements based on evaluation results
Instalar con Codex o Claude Copia este prompt, pรฉgalo en Codex, Claude u otro asistente, y deja que revise la pรกgina de la skill y la instale por ti.
Basado en la clasificaciรณn ocupacional SOC
| name | optimize |
| description | Apply token optimization improvements based on evaluation results |
| disable-model-invocation | true |
| allowed-tools | Read, Write, Edit, Grep, Glob |
You are ctxcraft optimizer โ you apply concrete improvements to reduce token consumption in .claude/ configurations.
User runs /optimize or /optimize --dry (preview only).
Use the same locale detection as /evaluate (Step 0):
CLAUDE.md first 30 lines โ if >50% non-code lines contain CJK characters, use that languageApply detected language to all output: plan description, change summaries, confirmation prompts.
Check if .claude/scratch/ctxcraft-report.md exists from a previous /evaluate run.
CLAUDE.md is loaded EVERY conversation. Every line costs tokens.
How to compress:
Target: Under 200 lines for CLAUDE.md (official: "target under 200 lines" โ code.claude.com/docs/en/memory.md; aim lower when possible)
Before:
## Error Handling
- We use a custom Result wrapper for all API calls
- All repositories must return Result<T> type
- Errors should be mapped to domain-specific types
- The UI layer observes error states reactively
- Always log errors with structured metadata
After:
## Error Handling
`Result<T>` wrapper for all API calls / domain-specific error mapping / reactive UI error states / structured logging
Find and merge overlapping content:
Action: Keep the most detailed version, remove duplicates, add cross-reference.
Identify skills/agents that are never or rarely used:
.claude/learning-log/ for usage data (if exists)Action: Remove with user confirmation. Never auto-delete.
Move always-loaded content to on-demand skills:
Should be in rules/ (always loaded):
Should be in skills/ (on-demand):
Action: Extract verbose sections from rules/ into new skills, leave a one-line reference.
Alternative โ path-scope instead of moving: If a rule only matters for specific file types or directories, keep it in rules/ but add paths: frontmatter (official feature). The rule then loads only when Claude reads matching files โ same token savings, no restructuring:
---
paths:
- "src/api/**/*.ts"
---
# API Development Rules
...
Dedup Check: Before adding content to a skill, check for duplicates:
Post-move Chain: After all Strategy 4 moves complete:
Before (rules/api-design.md โ 120 lines always loaded):
## Error Responses
- Use standard HTTP status codes for all endpoints...
[60 lines of examples and explanations]
After (rules/api-design.md โ 20 lines always loaded):
## Error Responses
- Use standard HTTP status codes (4xx client, 5xx server)
- Return structured error body with code + message + details
- Log server errors with correlation ID
> Deep dive: /api-error-handling
Merge granular rules files that cover related topics:
When a SKILL.md exceeds 150 lines (official hard cap: "Keep SKILL.md under 500 lines"), split verbose content into a references/ subdirectory โ this matches the Agent Skills open standard layout (scripts/, references/, assets/ โ agentskills.io):
What to extract:
Action: Keep only the core instructions in SKILL.md, move detailed content to references/*.md, and add a reference link at the bottom of SKILL.md.
When to apply:
Auto-trigger from Strategy 4: This strategy runs automatically (no separate user confirmation needed) when Strategy 4 causes a skill to exceed 150 lines. In this case:
references/Optimizations outside .claude/ markdown files (always confirm before touching settings):
claudeMdExcludes globs to .claude/settings.local.jsonAGENTS.md and CLAUDE.md with overlapping content โ replace the overlap with a single @AGENTS.md import (or symlink) โ official patternpermissions.deny ("Read(./secrets/**)") โ note: .claudeignore is NOT an official feature<!-- ... --> โ stripped before injection, 0 tokens.claude/commands/*.md still work but skills support supporting files and auto-invocation โ migrate to skills/<name>/SKILL.md1. Read .claude/scratch/ctxcraft-before.json for before state
2. Present optimization plan with estimated savings
3. Ask user: "Apply all? Select specific? Preview only?"
4. For --dry flag: show diffs without applying
5. Apply Strategy 1-3 (CLAUDE.md compress, dedup, prune unused)
6. Apply Strategy 4 with dedup check:
- Extract code blocks from rules/
- Grep target skill for key identifiers
- If duplicate โ remove from rules/ only (skip skill)
- If new โ remove from rules/ AND add to skill
7. Strategy 4โ6 chain check:
- Count lines of each skill modified in step 6
- If >150 lines โ auto-run Strategy 6 (extract to references/)
8. Apply Strategy 5 (Rule Consolidation)
9. Offer Strategy 7 (environment-level) โ settings.json changes require explicit confirmation
10. Re-run /evaluate to get after state
11. Show before/after comparison report
12. Clean up scratch files (ctxcraft-report.md, ctxcraft-backup/)
English (default):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ctxcraft โ Optimization Plan โ
โ โ
โ Quality: 64/100 (B) โ est. 85/100 (A-) โ
โ Cost: Warning โ est. Comfortable (Max 5x) โ
โ Savings: ~2,100 tokens/conversation โ
โ โ
โ ๐ Changes โ
โ 1. Compress CLAUDE.md (320โ148 lines) โ
โ Savings: ~1,200 tokens โ
โ 2. Merge 3 duplicate rules โ
โ Savings: ~500 tokens โ
โ 3. Move examples to skills โ
โ Savings: ~400 tokens โ
โ 4. Remove 2 unused skills โ
โ Freed: ~800 on-demand tokens โ
โ โ
โ Apply? [All / Select / Preview] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Korean (when detected):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ctxcraft โ ์ต์ ํ ๊ณํ โ
โ โ
โ ํ์ง: 64/100 (B) โ ์์ 85/100 (A-) โ
โ ๋น์ฉ: ๋ณดํต โ ์์ ์ฌ์ (Max 5x ๊ธฐ์ค) โ
โ ์ ๊ฐ ํ ํฐ: ~2,100 ํ ํฐ/๋ํ โ
โ โ
โ ๋ณ๊ฒฝ ์ ์ฉ? [์ ์ฒด / ์ ํ / ๋ฏธ๋ฆฌ๋ณด๊ธฐ] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Score | Grade |
|---|---|
| 90-100 | A |
| 80-89 | A- |
| 70-79 | B+ |
| 60-69 | B |
| 50-59 | C |
| 40-49 | D |
| 0-39 | F |
After all changes are applied, you MUST re-run /evaluate and display the comparison in this format:
English (default):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ctxcraft โ Optimization Complete โ
โ โ
โ Before After Change โ
โ Quality 75/100 โ 91/100 (+16 pts) โ
โ Grade B+ โ A โ
โ Cost Warning โ Comfortable โ
โ Always-on 16,848 โ 9,200 (-7,648 tokens/conv) โ
โ โ
โ PASS 9 โ 13 WARN 3 โ 1 FAIL 2 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Korean (when detected):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ctxcraft โ ์ต์ ํ ์๋ฃ โ
โ โ
โ ์ด์ ์ดํ ๋ณํ โ
โ ํ์ง 75/100 โ 91/100 (+16์ ) โ
โ ๋ฑ๊ธ B+ โ A โ
โ ๋น์ฉ ๋ณดํต โ ์ฌ์ โ
โ ์์ ๋ก๋ 16,848 โ 9,200 (-7,648 ํ ํฐ/๋ํ) โ
โ โ
โ PASS 9 โ 13 WARN 3 โ 1 FAIL 2 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Before data is read from .claude/scratch/ctxcraft-before.json.
After optimization is complete, clean up temporary scratch files only:
1. Delete .claude/scratch/ctxcraft-report.md (if exists)
2. Delete .claude/scratch/ctxcraft-backup/ (if exists)
3. Delete .claude/scratch/ctxcraft-before.json (if exists)
Note: Do NOT delete ctxcraft skills/agents โ they may be installed globally via plugin system (
~/.claude/plugins/) or locally for reuse. Only clean up temporary working files.
.claude/scratch/ctxcraft-backup/ before changes