token-pilot

v2.0.0
io.github.Digital-Threads/token-pilot Checked 21 hours ago Published 26 days ago

Save up to 80% tokens when AI reads code via AST-aware structural reading

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

smart_read

Use INSTEAD OF Read/cat for code files. Returns code structure (classes, functions, methods with signatures and line ranges) — 60-80% fewer tokens than raw content. Use read_symbol() to drill into specific code.

ParameterTypeDescription
path *stringFile path (absolute or relative to project root)
depthnumberMax depth for nested symbols (default: 2)
forcebooleanBypass dedup — return full content even if the same path was already loaded earlier in this session. Use when the prior result was compacted out of context.
max_tokensnumberToken budget. If output exceeds this, auto-downgrades: full → outline → compact. Use for context-constrained sessions.
scopestringOutput scope: full (default, all details), nav (names + lines only, 2-3x smaller), exports (public API only)
session_idstringOptional Claude Code session_id. When provided, dedup state (already-loaded files) persists across MCP server restarts and /clear, tied to that session. Omit to use ephemeral process-scoped dedup.
show_docsbooleanInclude doc comments (default: true)
show_importsbooleanInclude import details (default: true)

read_symbol

Read source code of ONE specific function/method/class — INSTEAD OF reading the whole file. Supports Class.method syntax.

ParameterTypeDescription
path *stringFile path
symbol *stringSymbol name, e.g. "UserService.updateUser"
context_afternumberLines of context after (default: 0)
context_beforenumberLines of context before (default: 2)
forcebooleanBypass dedup (see smart_read.force).
include_edit_contextbooleanAppend raw code block for Edit old_string (saves a read_for_edit call)
session_idstringOptional Claude Code session_id for cross-restart dedup (see smart_read).
showstringDisplay mode: full (all lines), head (first 50), tail (last 30), outline (head + methods + tail). Default: auto (full ≤300 lines, outline >300)

read_symbols

Batch read MULTIPLE symbols from ONE file — saves N-1 round-trips vs calling read_symbol N times. BEST FIT: 3–8 symbols in one file when you need their bodies. For 1–2 symbols use read_symbol (simpler). If you'd request ≥70% of the file's symbols, the handler refuses and points you to smart_read — that's cheaper than a large batch. For edit preparation use read_for_edit.

ParameterTypeDescription
path *stringFile path
symbols *arrayArray of symbol names (max 10), e.g. ["UserService.create", "UserService.update", "UserService.delete"]
context_afternumberLines of context after each symbol (default: 0)
context_beforenumberLines of context before each symbol (default: 2)
showstringDisplay mode for each symbol (default: auto)

read_range

Read a specific line range from a file. Use when you know exact lines — lighter than reading the whole file.

ParameterTypeDescription
end_line *numberEnd line (1-indexed, inclusive)
path *stringFile path
start_line *numberStart line (1-indexed)
forcebooleanBypass dedup (see smart_read.force).
session_idstringOptional Claude Code session_id for cross-restart dedup (see smart_read).

read_section

Read a specific section from Markdown, YAML, JSON, or CSV files. Markdown: by heading name. YAML/JSON: by top-level key. CSV: by row range (rows:1-50). Much cheaper than reading the whole file. DOCS/DATA ONLY — `heading` is required; this does NOT read code by line/symbol. For source files use read_range (line range) or read_symbol (one symbol).

ParameterTypeDescription
heading *stringSection heading (Markdown), top-level key (YAML/JSON), or row range "rows:1-50" (CSV). Case-insensitive.
path *stringPath to .md, .yaml, .yml, .json, or .csv file

read_diff

Use INSTEAD OF re-reading whole file after edits. Shows only changed hunks. REQUIRES: call smart_read or read_for_edit BEFORE editing to create baseline snapshot.

ParameterTypeDescription
path *stringFile path
context_linesnumberLines of context around changes (default: 3)

read_for_edit

Raw text around a symbol or line, ready to paste as Edit's old_string — handy before editing one function of a large file without reading the whole file. Read works just as well when you already have the file open. Supports batch: pass "symbols" array to get multiple edit contexts in one call. Unlike read_symbols (for reading/understanding), this returns unformatted code optimized for copy-paste into Edit. Optional: include_callers, include_tests, include_changes for enriched context.

ParameterTypeDescription
path *stringFile path
contextnumberLines of context around target (default: 5)
include_callersbooleanShow top callers of this symbol (saves a separate find_usages call)
include_changesbooleanShow recent git changes in the target region
include_testsbooleanShow related test file and test names
linenumberLine number to edit (alternative to symbol)
sectionstringSection to edit: heading (Markdown), top-level key (YAML/JSON), or "rows:1-50" (CSV). Returns raw section content for Edit old_string.
symbolstringSymbol name to edit (e.g. "UserService.updateUser")
symbolsarrayArray of symbol names for batch edit context (max 10). Alternative to single "symbol" — returns all symbols in one call.

smart_read_many

Batch smart_read for multiple files at once — INSTEAD OF calling Read on each file. Returns structure for each file. Max 20 files.

ParameterTypeDescription
paths *arrayArray of file paths
forcebooleanBypass dedup (see smart_read.force).
max_tokensnumberToken budget per file. If a file exceeds this, auto-downgrades to compact outline.
session_idstringOptional Claude Code session_id for cross-restart dedup (see smart_read).

find_usages

Use INSTEAD OF Grep for finding symbol references. Semantic search — groups by: definitions, imports, usages. Supports scope, kind, limit, lang filters. Use context_lines to include surrounding code. HINT: for very short / generic symbols (≤4 chars like `id`, `err`, `Cmd`, `db`) Grep is usually cheaper than find_usages — the semantic grouping doesn't pay off when the symbol resolves ambiguously across thousands of files.

ParameterTypeDescription
symbol *stringSymbol name to find usages of
context_linesnumberLines of source context around each match (0-10). When set, shows surrounding code — saves follow-up read_symbol calls.
kindstringShow only specific section (default: "all")
langstringFilter by language/extension (e.g., "php", "typescript")
limitnumberMax results per category (default: 50, max: 500)
modestringOutput mode: full (with context, default), list (file:line only, 5-10x smaller for initial discovery)
scopestringFilter results by path prefix (e.g., "src/Domain/")

project_overview

START HERE for unfamiliar codebases. Shows project type, architecture, framework detection, quality tools, CI, directory map. Use include filter for specific sections.

ParameterTypeDescription
includearraySections to include (default: all). Use ["stack"] for quick type check, ["quality","ci"] for tooling overview.

outline

Use INSTEAD OF listing dir + reading each file. One call returns all symbols (classes, functions, methods, routes) for every code file in a directory. Supports recursive with max_depth.

ParameterTypeDescription
path *stringDirectory path
max_depthnumberMax recursion depth when recursive=true (default: 2, max: 5)
recursivebooleanRecursively outline subdirectories (default: false)

session_analytics

Show token savings report: calls, tokens saved, per-tool breakdown, top files, cache hits. Use verbose=true for full breakdown (per-intent, decision insights, savings by category).

ParameterTypeDescription
verbosebooleanShow detailed breakdown: per-intent, savings by category, decision insights (default: false)

call_tree

Recursive depth-N call hierarchy for a function. Shows who calls who transitively — complements find_usages (flat one-level refs) by revealing full chains from leaf helpers to entry points. Use for debugging, refactor impact, and verifying reachability.

ParameterTypeDescription
symbol *stringFunction / method name, unqualified (e.g. `fetchUser`).
depthnumberWalk-up depth. Default 3, max 6.

find_unused

Find dead code — functions, classes, and variables with no references across the project. Use for cleanup and refactoring.

ParameterTypeDescription
export_onlybooleanOnly check exported (capitalized) symbols
limitnumberMax results (default: 30)
modulestringFilter by module path (e.g., "src/services/")

code_audit

Find code quality issues: TODO/FIXME comments, deprecated symbols, structural code patterns (bare except:, print() calls). Use for project-wide audits.

ParameterTypeDescription
check *stringWhat to check: "pattern" (structural search via ast-grep, e.g. "except:", "print($$$ARGS)"), "todo" (TODO/FIXME comments), "deprecated" (deprecated symbols), "annotations" (find by decorator name), "a…
langstringLanguage filter for check="pattern" (e.g., "python", "typescript")
limitnumberMax results (default: 50)
namestringDecorator/annotation name for check="annotations". Example: "Deprecated", "Controller"
patternstringCode pattern for check="pattern". ast-grep syntax: "except:" finds bare excepts, "print($$$ARGS)" finds print calls.

module_info

Analyze module dependencies, dependents, public API, and unused deps. Use for architecture understanding and dependency cleanup.

ParameterTypeDescription
module *stringModule name or path pattern (e.g., "auth", "src/Domain/")
checkstringWhat to check: "deps" (dependencies), "dependents" (who depends on this), "api" (public symbols), "unused-deps" (dead dependencies), "all" (everything). Default: "all"

module_route

Show the transitive dependency path(s) between two modules — how module A reaches module B through the import graph. Use to answer 'how does X depend on Y?', trace coupling, or generate a dependency diagram. format='mermaid'/'dot' emits a diagram; default text lists the hops.

ParameterTypeDescription
from *stringSource module — the one whose dependencies are followed (name or path, e.g. "auth", "apps/api")
to *stringTarget module to reach
allbooleanShow all simple paths instead of just the shortest (default: false)
formatstringOutput format: "text" (default, hop listing), "json", "mermaid" or "dot" (dependency diagram)
maxDepthnumberCap on path length in hops (default: 20, max: 50)
maxPathsnumberCap on number of paths returned (default: 50, max: 200)
viaKindstringRestrict traversal to a dependency kind (default: "all")

smart_diff

Use INSTEAD OF raw git diff. Shows changed files with AST symbol mapping — which functions/classes were modified/added/removed. Small diffs include hunks, large diffs show summary.

ParameterTypeDescription
pathstringFilter to specific file or directory
refstringGit ref — required for scope="commit" (commit hash) or scope="branch" (branch name)
scopestringDiff scope (default: "unstaged")

explore_area

One-call exploration of a directory: outline (all symbols), imports (external deps + who imports this area), tests (matching test files), recent git changes. Use INSTEAD OF separate outline + related_files + git log calls. Default since v0.30.0 returns only outline+changes — telemetry showed the all-4 default producing negative token reduction for small areas. Opt into imports/tests explicitly via `include` when you need them.

ParameterTypeDescription
path *stringDirectory path (or file path — will use its parent directory)
includearraySections to include. Default: ["outline","changes"]. Add "imports" for dep graph, "tests" to map test files — both can be heavy on large areas.

explore

One-shot ranked context + call/inheritance graph blast-radius for a query. Returns ranked symbols, the source heads of the top-ranked files, graph neighbours (callers + subclasses — the blast radius), and related test files in a single compact block. Use INSTEAD OF separate find_usages + read_symbol + call_tree when you need to understand an area fast — cheaper than chaining those three.

ParameterTypeDescription
query *stringSearch terms (the binary splits the string into terms itself), e.g. "AstIndexClient buildIndex"
graphbooleanInclude call/inheritance graph neighbours (blast radius). Default: true. Set false to skip the graph walk.
max_filesnumberCap on the number of source file heads returned (default: binary's own limit)

smart_log

Use INSTEAD OF raw git log. Structured commit history with category detection (feat/fix/refactor/docs), file stats, author breakdown. Filters by path and ref. HEADS UP: two verification runs measured this tool at ~39% token reduction (borderline — vs 95-99% for outline/smart_diff). Cumulative data being gathered — tool may be dropped or redesigned in v0.30.0 if numbers don't improve. Prefer scoping with `path` or `count` to tighten savings.

ParameterTypeDescription
countnumberNumber of commits (default: 10, max: 50)
pathstringFilter to specific file or directory
refstringGit ref — branch, tag, or commit (default: HEAD)

test_summary

Run tests and return structured summary: total/passed/failed/skipped + failure details. 200 lines of raw output → 10-15 lines. Parsers: vitest, jest, pytest, phpunit, go test, cargo test, node --test (rspec/mocha fall back to generic patterns). The command runs through the shell (env prefixes and && work) in the server's environment (normally your terminal's) minus CLAUDE_PLUGIN_* / TOKEN_PILOT_* variables, with CI=1, NO_COLOR=1 and FORCE_COLOR=0 set so runners print plain output and skip watch mode (an env prefix in the command overrides them); on timeout the command and everything it start…

ParameterTypeDescription
command *stringTest command to run (e.g., "npm test", "pytest", "go test ./...")
runnerstringForce specific parser (auto-detected if omitted)
timeoutnumberTimeout in ms (default: 60000, max: 300000)

session_snapshot

Capture current session state as a compact markdown block (<200 tokens). Call before compaction, when switching direction, or periodically in long sessions. Model provides the facts, tool formats them. Writes the block to .token-pilot/snapshots/<timestamp>.md (last 10 kept) and .token-pilot/snapshots/latest.md, which the next session start points to; pass persist=false to only return it.

ParameterTypeDescription
goal *stringSession goal — what and why
blockedstringCurrent blocker or obstacle
confirmedarrayEstablished facts (what has been verified)
decisionsarrayKey decisions made and why (e.g., "removed sysfee step — caused double counting"). Prevents revisiting rejected approaches.
filesarrayRelevant file paths
nextstringNext step to take
persistbooleanSave to .token-pilot/snapshots/ (default: true). false = return the block only.

session_budget

META / info-only: reports Read-hook pressure for this session (suppressed tokens, reference budget, burn fraction, effective denyThreshold). Does NOT save tokens itself — this is diagnostic, use to decide when to tighten before a big read. NOTE: burnFraction measures hook activity, not actual context-window occupancy.

ParameterTypeDescription
sessionId *stringClaude Code session_id (same id that appears in hook-events.jsonl). Pass "" to read with no session filter.