---
title: "Comment by Mateo Ruiz on \"My AI coding agent kept grepping my repo to find one function — so I cut its token usage by 90%\" | Hashnode"
description: "One thing we've noticed is that as repositories grow, retrieval becomes a much bigger bottleneck than generation. If an agent spends most of its time grepping a"
url: "https://hashnode.com/posts/ai-agent-codebase-indexer-skill-spelunk/6a609b9ba874e83d3cbc81e5/comment/6a60a7df0865fa0f4a1513cc"
---

[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)

[Mateo Ruiz](https://hashnode.com/@mateoruiz)

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

One thing we've noticed is that as repositories grow, retrieval becomes a much bigger bottleneck than generation. If an agent spends most of its time grepping and re-reading files, you're paying in both latency and tokens before it even starts reasoning.

Using AST-based indexing is a smart approach because it gives the agent structural context instead of raw text. It would also be interesting to see benchmarks on incremental re-indexing for large monorepos and how it performs alongside RAG- or embedding-based code retrieval. Nice first project looking forward to seeing how it evolves.

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

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

Thanks Mateo! Completely agree that retrieval overhead is where most latency and token burn happen on larger projects.

Testing incremental re-indexing on large codebases is high on my list. Spelunk tracks mtimes and file hashes in SQLite, so rescans only re-parse modified files instead of running full passes.

Combining AST indexing with RAG or embeddings is a great idea. AST gives exact symbol resolution while RAG handles semantic search. I'm focusing on Amar right now, but I've noted this down for when I get back to Spelunk features. If you have thoughts on how that hybrid setup should work, feel free to open a GitHub issue.
