Token Optimization

Reduce Claude token usage with larkx

Stop Claude from reading raw source files. Give it a pre-built symbol map instead, then verify the savings on your own project.

Why Claude uses so many tokens

By default, Claude Code reads your source files directly to understand the codebase. A typical TypeScript file is often 200–400 lines and can be roughly 600 tokens. For a 200-file project, just exploring the structure can reach 100,000+ tokens before Claude writes a single line.

How larkx fixes it

larkx pre-indexes every file, function, class, import, and call relationship into a compact graph. Claude reads the graph - not the files. Level 2 is roughly 80 tokens per file in the index, instead of paying to read the raw source file directly. Claude only opens actual source files when it needs to edit them.

Estimated token savings by project size

Project sizeReading files directlylarkx level 2Reduction
50 files~30,000 tokens~4,000 tokens~87%
200 files~120,000 tokens~16,000 tokens~87%
500 files~300,000 tokens~40,000 tokens~87%

Estimated examples based on a rough 600-token raw-read baseline and a level-2 index. Verify the exact numbers on your own project with larkx stats and larkx bench.

Run larkx stats after indexing to see exact token estimates at each level for your own project.

Token cost per tool call

QuestionCheapest callApprox tokens
"What files exist?"get_project_index level=1~8 per file
"Where is function X?"search_symbol~30 total
"What's in this file?"get_file_summary~100 total
"What imports this?"get_impact~100 total
"What calls what?"get_call_chain~100 total
"What's unused?"get_dead_code~200 total

The three levers

  1. Context level (1–4) — controls detail per file. Level 1 is paths only (~8 tok/file). Level 2 adds symbols (~80 tok/file). Start cheap, go deeper only if needed.
  2. Folder scoping — restrict get_project_index to a subfolder. Working in src/auth? Only load that subtree.
  3. Tool choice — use search_symbol instead of get_project_index when you just need to find one function. 30 tokens vs thousands.

What does level 2 look like?

bash
# larkx context · level 2 · ~681 tokens · 17 files
src/auth/login.ts[typescript]: validateJWT@6, hashPassword@12, login@17 | +../utils/crypto,+../db/users
src/auth/middleware.ts[typescript]: authMiddleware@9, rateLimiter@19 | +./login
src/db/users.ts[typescript]: findById@8, create@18, UserRepository@7 | +../utils/logger
src/utils/crypto.ts[typescript]: sha256@3, generateToken@7, compareHash@11 | +crypto
src/utils/legacy.ts[typescript]: oldEncrypt@2

Claude gets function names, line numbers, and imports for every file in ~681 tokens. Reading those same 5 files directly would cost ~3,000+ tokens.

Measure it on your project

Run larkx bench in your project root. It reports real-time token counts from Claude, not estimates.

See best practices for prompt patterns that keep Claude picking the cheapest tool automatically.