cd /news/developer-tools/why-we-built-deterministic-ast-refac… · home › topics › developer-tools › article
[ARTICLE · art-142734] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=↑ positive

Why We Built Deterministic AST Refactoring Instead of Prompting LLMs

A developer built TokenCap, a refactoring tool that uses deterministic tree-sitter AST traversal instead of LLM token prediction to perform code transformations such as renaming symbols across a call graph. The tool resolves exact symbol references while skipping string literals and comments, and includes a dead-code pruning command based on an AST call-resolution graph, leaving the LLM to handle only high-level decisions.

by read1 min views1 publishedSep 30, 2026

When developers ask an AI agent to "rename handleUser to processUser across the project", most agents perform fuzzy grep searches and attempt sequential file rewrites.

This approach is prone to edge-case errors:

handleUser inside string literals or unrelated comments. In TokenCap, refactoring commands are executed by deterministic tree-sitter AST traversal rather than generative token prediction.

tokencap refactor rename src/auth.js:validateSession authenticateSession --dry-run

Output:

Inspecting 58 files...
Resolved 12 exact symbol references:
  ✓ src/auth.js:24: declaration
  ✓ src/middleware/session.js:15: call site
  ✓ src/routes/api.js:82: call site
  - Skipping string literal at src/tests/mock.js:12 ("validateSession")
Dry run complete: 12 references updated across 3 files with 0 syntax errors.

Similarly, tokencap refactor rm-dead uses our AST call-resolution graph to detect uncalled, unexported dead functions and prune them safely.

By using the LLM for high-level decision making and TokenCap for deterministic syntax-tree transforms, refactor operations remain safe and reproducible.

Documentation available at tokencap.vansharora.app

── more in #developer-tools 4 stories · sorted by recency
── more on @tokencap 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/why-we-built-determi…] indexed:0 read:1min 2026-09-30 · —