Skip to content

Instantly share code, notes, and snippets.

@yurukusa
Last active April 17, 2026 03:44
Show Gist options
  • Select an option

  • Save yurukusa/2b98fd2e90c0c13f6918c9f915e08e27 to your computer and use it in GitHub Desktop.

Select an option

Save yurukusa/2b98fd2e90c0c13f6918c9f915e08e27 to your computer and use it in GitHub Desktop.
CLAUDE.md Token Optimizer — 35-line template that reduced token consumption by 40% (800+ hours tested)

CLAUDE.md Token Optimizer — 35-line template that reduced token consumption by 40% (800+ hours tested)

Reduced token consumption by ~40% in 800+ hours of autonomous Claude Code operation. Long CLAUDE.md files cost tokens every turn. A 500-line file = ~5,000 tokens of fixed overhead per message. This 35-line template:

  • Keeps context lean → fewer tokens per turn
  • Improves cache hit rate (89% → 95% in our testing)
  • Reduces compaction frequency → longer sessions
  • Focuses on "why" rules, not "what" procedures
- Follow existing code conventions
- Run tests before committing
- Create feature branches for changes
- Never force-push or delete remote branches
- Never commit .env or credential files
- Read files before editing (never blind-edit)
- Prefer Edit over Write for existing files
- Check parent directory exists before creating files
- Python: `python -m py_compile` after changes
- JS/TS: `npx tsc --noEmit` after changes
- Commit messages: explain "why", not "what"

Move enforeable rules to hooks (automated) and keep CLAUDE.md for principles only. Rules in CLAUDE.md get forgotten after context compaction. Hooks never forget. Run /cost before and after switching to this template. Watch for:

  • Cache read ratio — should increase (target: >90%)
  • Total tokens per session — should decrease
  • Compaction frequency — should decrease
  • Token Checkup — 5 questions, 30 seconds. Shows where your tokens go
  • CLAUDE.md Analyzer — Paste your CLAUDE.md for token efficiency analysis
  • Cache Health Checker — Paste /cost output for instant diagnosis Token Book — ¥2,500 (~$17) — CLAUDE.md is just 1 of 6 optimization areas. The full guide covers context management, hook-based token guards, subagent strategy, workflow design, and troubleshooting. 10 chapters, 44,000 words, copy-paste config templates. Details and free Chapter 1 preview →

From cc-safe-setup — 667 hooks for Claude Code safety

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment