---
title: "Comment by Kartik N V J K on \"My AI coding agent kept grepping my repo to find one function — so I cut its token usage by 90%\" | Hashnode"
description: "The Tree-sitter + SQLite combo for AST symbol lookup is the right call, and swapping blind grep/cat for a definition resolver is exactly where most of my agent"
url: "https://hashnode.com/posts/ai-agent-codebase-indexer-skill-spelunk/6a609b9ba874e83d3cbc81e5/comment/6a6113d8377eaf776b54f181"
---

[Discussion](https://hashnode.com/posts/ai-agent-codebase-indexer-skill-spelunk/6a609b9ba874e83d3cbc81e5)

Comment [My AI coding agent kept grepping my repo to find one function — so I cut its token usage by 90%](https://hashnode.com/posts/ai-agent-codebase-indexer-skill-spelunk/6a609b9ba874e83d3cbc81e5)

[Kartik N V J K](https://hashnode.com/@kartik-nvj)

[Jul 22](https://hashnode.com/posts/ai-agent-codebase-indexer-skill-spelunk/6a609b9ba874e83d3cbc81e5/comment/6a6113d8377eaf776b54f181)

The Tree-sitter + SQLite combo for AST symbol lookup is the right call, and swapping blind grep/cat for a definition resolver is exactly where most of my agent token spend was hiding too. One thing I'd love to hear you dig into: how you handle stale index invalidation on partial writes, since that's the failure mode that eventually made me distrust the tool and re-grep anyway. The <100ms target is only useful if a returned symbol is guaranteed to reflect the file on disk at call time.

[Priyanshu Roy](https://hashnode.com/@roypriyanshu02)

[Jul 23](https://hashnode.com/posts/ai-agent-codebase-indexer-skill-spelunk/6a609b9ba874e83d3cbc81e5/comment/6a6113d8377eaf776b54f181#reply-6a62491ea043a23a8d93266b)

Thanks Kartik. Stale index invalidation was the exact issue that broke my earlier manual workarounds.

Spelunk handles disk changes by checking mtimes and diffing the AST on call time, while the agent keeps its own active session edits in working memory. Together, those cover most stale read scenarios.

Good point to bring up.
