io.github.Digital-Threads/token-pilot
Save up to 80% tokens when AI reads code via AST-aware structural reading
Ask AI about io.github.Digital-Threads/token-pilot
Powered by Claude Β· Grounded in docs
I know everything about io.github.Digital-Threads/token-pilot. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Token Pilot
Token-efficient AI coding, enforced. Cuts context consumption in AI coding assistants by up to 90% without changing the way you work.
Three layers, each useful on its own, stronger together:
- MCP tools β structural reads (
smart_read,read_symbol,read_for_edit, β¦). Ask for an outline or load one function by name instead of the whole file. - PreToolUse hooks β intercept heavy native tool calls (
Readon large files, recursiveGrep, unboundedgit diff) and redirect to token-efficient alternatives. tp-*subagents β Claude Code delegates with MCP-first behaviour and tight response budgets.
How It Works
Traditional: Read("user-service.ts") β 500 lines β ~3000 tokens
Token Pilot: smart_read("user-service.ts") β 15-line outline β ~200 tokens
read_symbol("UserService.updateUser") β 45 lines β ~350 tokens
After edit: read_diff("user-service.ts") β ~20 tokens
Files under 200 lines are returned in full β zero overhead for small files.
Benchmarks
Measured on public open-source repos. Files β₯50 lines only:
| Repo | Files | Raw Tokens | Outline Tokens | Savings |
|---|---|---|---|---|
| token-pilot (TS) | 55 | 102,086 | 8,992 | 91% |
| express (JS) | 6 | 14,421 | 193 | 99% |
| fastify (JS) | 23 | 50,000 | 3,161 | 94% |
| flask (Python) | 20 | 78,236 | 7,418 | 91% |
| Total | 104 | 244,743 | 19,764 | 92% |
smart_readoutline savings only. Real sessions additionally benefit from session cache,read_symbol, andread_for_edit. Reproduce:npx tsx scripts/benchmark.ts.
Quick Start
npx -y token-pilot init
Creates (or merges into) .mcp.json with token-pilot + context-mode, then prompts to install tp-* subagents. Restart your AI assistant to activate.
What You Get
- 22 MCP tools β structural reads, symbol search, git analysis, session analytics β tools reference
- PreToolUse hooks β block heavy
Grep/Bash/Readcalls; redirect to efficient alternatives β hooks & modes - 25
tp-*subagents (Claude Code only) β MCP-first delegates with haiku/sonnet model tiers and budget enforcement β agents reference - Tool profiles β trim advertised
tools/listto save ~2 k tokens per session β profiles & config
Client Support Matrix
| Client | MCP tools | PreToolUse hooks | tp-* subagents |
|---|---|---|---|
| Claude Code | β | β | β |
| Cursor | β | β | β |
| Codex CLI | β | β | β |
| Gemini CLI | β | β | β |
| Cline (VS Code) | β | β | β |
| Antigravity | β | β | β |
Manual config snippets for each client β installation guide
Enforcement Mode
TOKEN_PILOT_MODE controls how aggressively Token Pilot redirects heavy native tool calls:
| Value | Behaviour |
|---|---|
advisory | Allow all β hooks pass through, advisory notes only |
deny (default) | Block heavy Grep/Bash patterns; intercept large Read calls |
strict | Deny + auto-cap MCP output (smart_read β€ 2 000 tokens, find_usages β list mode, smart_log β 20 commits) |
TOKEN_PILOT_MODE=strict npx token-pilot
Ecosystem
| Tool | Role |
|---|---|
| Token Pilot | Enforcement layer β hooks, MCP structural reads, subagents |
| ast-index | Structural indexer. Auto-installed by Token Pilot; also a standalone CLI for bash-only agents |
| context-mode | Sandbox executor β runs shell/python/js, only stdout enters the context window |
Rules of thumb: read code β smart_read/read_symbol; execute code with big output β context-mode execute; bash-only agent β ast-index CLI. Never copy all three into CLAUDE.md β Token Pilot's doctor warns when CLAUDE.md exceeds 60 lines.
Supported Languages
TypeScript, JavaScript, Python, Go, Rust, Java, Kotlin, C#, C/C++, PHP, Ruby. Non-code (JSON/YAML/Markdown/TOML) gets structural summaries. Regex fallback handles most other languages.
Update / New Machine
Claude Code (plugin β recommended):
# Install on a new machine:
claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
claude plugin install token-pilot@token-pilot
# Update to latest:
claude plugin update token-pilot
Other clients (Cursor, Codex, Cline, β¦):
# Install on a new machine:
npx -y token-pilot init
# Update to latest β npx always pulls fresh, just restart your client.
# Or if installed globally:
npm i -g token-pilot@latest
npx token-pilot install-hook
npx token-pilot install-agents --scope=user --force
Troubleshooting
npx token-pilot doctor # diagnose: ast-index, config, upstream drift
# "ast-index not found" β npx token-pilot install-ast-index
# "hooks not firing" β restart your AI assistant
Credits
Built on ast-index Β· @ast-grep/cli Β· MCP SDK Β· chokidar
License
MIT
