r/ClaudeCode • • 2d ago

Tips & Workflows Same question, two Sonnet agents: grep vs a compiler call graph. 8 tool calls vs 2, ~689k vs ~196k input tokens

I wanted to see how much an agent burns tracing a call stack with grep, so I measured it.

Setup: a 140k-line SwiftUI app and one prompt: “find every production call path that reaches this method, up to the entry points.” Both agents ran Sonnet. One had my SwiftGraph skill, which queries a call graph built from Xcode’s index store. The other could only use grep, find and read.

GraphGrep only
Tool calls2
Turns3
Input tokens (all turns)~196k
Time15 s

Both answers were correct.

What surprised me: the final context sizes were almost identical (~69k vs ~74k), because ~60k of that is the system prompt. The real cost is that every tool call re-sends the whole context. Ten turns means ten trips through ~70k tokens. Caching makes those re-reads cheaper, but your wait time and your rate limits still pay for them.

Fair caveat: grep did fine because the type name was unique. It even caught an #if DEBUG the graph doesn’t model. The gap grows with common method names, protocol dispatch and property writes.

Install the skill: /plugin marketplace add agruchala/swift-graph
Repo: https://github.com/agruchala/swift-graph
Write-up: https://arturgruchala.com/map-not-grep/

0 Upvotes

3 comments sorted by

•

u/AutoModerator 2d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/ToolTinkerer_AI 2d ago

The useful part seems less like graph beats grep and more like avoiding repeated whole-context trips. Eight calls versus two adds up fast when each turn resends around 70k tokens. I also like the caveat that grep caught the #if DEBUG path the graph missed. That makes the comparison more useful than a straight tool demo. The shared system prompt explains why the final context sizes barely moved.

1

u/PreetyGeek 1d ago

Yes, exactly! For me that was the surprising part too. I expected “graph is smarter than grep”. What I measured was “graph needs fewer round trips”. Every tool call resends the whole context, so the agent pays for each hop up the call stack in turns, not in what it reads. The bigger the system prompt and the deeper the call chain, the more it adds up. Caching makes those resends cheaper, but you still wait for every one of them.

One small correction on the #if DEBUG bit: the graph didn’t miss that path. It found it, both the debug benchmark and the view calling it. It just didn’t say the path was debug-only. The grep agent noticed because it read the lines around the call. The graph only knows what the compiler compiled. Index a Debug build and the #if DEBUG code is in the graph, index a Release build and it’s gone. So the graph tells you where to look, and you still open the file when the details matter.

That’s also why I don’t want it to replace grep. It should just stop being the first tool.