How nadimtuhin/claude-token-optimizer works
Claude Token Optimizer is a project-facing CLI for reducing and managing the documentation Claude Code loads into context. Users invoke commands through the CLI: initialize a framework-aware documentation layout, measure token usage, then audit or maintain it with compression, pruning, diffs, and live monitoring. It also manages Claude Code hook templates and refreshes project content. The excerpts show CLI dispatch and several command-to-library calls; README documents other command capabilities. Dashed edges mark README-described flows whose implementation details were not sampled.
Main entry points: cli.js Command router · init.js Initialize docs · tokenizer.js Token counter · hooks.js Hook manager
Components 17
CLI entry
- Command router
src/cli.js
Project setup
- Initialize docs
src/commands/init.js - Framework detection
src/lib/frameworks.js - Update content
src/commands/update.js
Token maintenance
- Measure tokens
src/commands/measure.js - Structure audit
src/commands/audit.js - Compress docs
src/commands/compress.js - Prune stale docs
src/commands/prune.js - Token comparison
src/commands/diff.js - Live dashboard
src/commands/watch.js
Hook management
- Hook manager
src/commands/hooks.js - Hook scripts
templates/hooks
Shared libraries
- Auto-load scanner
src/lib/scanner.js - Token counter
src/lib/tokenizer.js
Other components
- Project user
- Claude Code
- Project docs
Connections 31
- Project user → Command router: runs command
src/cli.js - Command router → Initialize docs: dispatches
src/cli.js - Command router → Measure tokens: dispatches
src/cli.js - Command router → Structure audit: dispatches
src/cli.js - Command router → Compress docs: dispatches
src/cli.js - Command router → Prune stale docs: dispatches
src/cli.js - Command router → Token comparison: dispatches
src/cli.js - Command router → Live dashboard: dispatches
src/cli.js - Command router → Hook manager: dispatches
src/cli.js - Command router → Update content: dispatches
src/cli.js - Initialize docs → Framework detection: detects framework
src/commands/init.js - Initialize docs → Hook manager: installs hooks
src/commands/init.js - Measure tokens → Auto-load scanner: scans files
src/commands/measure.js - Measure tokens → Token counter: counts tokens
src/commands/measure.js - Structure audit → Token counter: counts tokens
src/commands/audit.js - Structure audit → Framework detection: checks ignore rules
src/commands/audit.js - Structure audit → Initialize docs: builds missing docs
src/commands/audit.js - Compress docs → Token counter: counts tokens
src/commands/compress.js - Prune stale docs → Token counter: counts tokens
src/commands/prune.js - Token comparison → Token counter: counts tokens
src/commands/diff.js - Live dashboard → Token counter: counts tokens
src/commands/watch.js - Measure tokens → Project docs: reads docs
src/commands/measure.js - Compress docs → Project docs: rewrites docs
README.md - Prune stale docs → Project docs: archives sections
README.md - Token comparison → Project docs: compares versions
README.md - Live dashboard → Project docs: monitors changes
README.md - Hook manager → Hook scripts: copies scripts
src/commands/hooks.js - Hook manager → Claude Code: configures hooks
README.md - Update content → Initialize docs: appends sections
src/commands/update.js - Update content → Hook manager: refreshes hooks
src/commands/update.js - Initialize docs → Project docs: writes docs
src/commands/init.js