← All recipes
  • subagents
  • context
  • cost
  • claude-md

Subagents for codebase searches cost more and saved nothing

A three-step refactor in a 24-file API, with and without a CLAUDE.md line telling Claude to delegate searches to a subagent. Both got everything right. Delegating cost more, at least at this size.

Cost per run Bar is the average, dots are the individual runs.
No guidance$0.167Delegate in CLAUDE.md$0.207

See every run, check and diff →

The usual pitch for subagents: send one off to read a lot of files, it hands back a short summary, and your main session stays lean. We tested whether that pays off on a realistic small project.

The setup

The same notes API as our unrelated-tasks recipe: about 470 lines across 24 files. Seven settings are read from environment variables, scattered across six files and written several different ways (process.env.X, process.env['X'], destructuring, and an alias const env = process.env).

Three steps in one continuous session:

  1. List every place in src/ that reads an environment variable, with the file, the variable and its default. Change nothing yet.
  2. Move all of those reads into a new src/config.js and update every call site. Run the tests.
  3. Add a GET /version route that returns the version from package.json, with a test.

We ran it 3 times each two ways:

  • No guidance: Claude decides how to search.
  • Delegate in CLAUDE.md: one line telling Claude to hand searches across many files to a subagent and work from its summary.

What happened

No guidance Delegate in CLAUDE.md
All 7 settings moved, none left behind 3 of 3 3 of 3
Tests pass, /version correct (hidden test) 3 of 3 3 of 3
Used a subagent 0 of 3 3 of 3
Average cost, step 1 (the search) $0.049 $0.075
Average total cost $0.167 $0.207
Main conversation at its largest 30,200 tokens 31,200 tokens

Claude Code 2.1.296, Sonnet 5.5, 3 runs per column. Costs include the subagent’s own usage. Every run, check and diff: run data.

What we learned

Claude followed the instruction every time. With the CLAUDE.md line, it started a subagent for the search in all 3 runs. Each time the subagent ran in the background: Claude said it was waiting for the results, then answered once they arrived. Without the line, Claude never used a subagent; it ran a few Grep searches and, in 2 of 3 runs, opened two files to check the trickier cases.

Both ways found everything. Every run moved all seven settings, including the aliased one, where the variable name sits on a different line from process.env, and passed the hidden test.

Delegating cost more. The search step cost about 53% more with a subagent, and the whole task about 24% more. A subagent is a second Claude session with its own instructions and tools to load. Our likely explanation is that in a codebase this small, that setup cost more than the searching it took off the main session’s hands. We didn’t measure the split directly.

The main session didn’t get leaner. The point of a subagent is to keep the file dumps out of your conversation. But step 2 was a refactor, and in every delegated run the main session opened all six files itself before editing them, just as it did without a subagent. The subagent’s summary saved a search, not the reading, so the conversation peaked at about the same size either way.

This is the small-repo result. 470 lines is less than a subagent is designed for. A search across hundreds of files, or a read-through you won’t need afterwards, is where we’d expect delegation to pay. We haven’t tested that yet.

The recipe

  1. Don’t tell Claude to delegate every search. In our small codebase, a direct Grep and a few reads was cheaper.
  2. Use a subagent when the reading is big and the answer is small, such as surveying a large unfamiliar codebase, or reading logs you won’t need again.
  3. Delegate when you won’t need the files afterwards. If the next step edits the same files, the main session will read them anyway, and the summary saves little.
  4. Check your CLAUDE.md for blanket rules. Claude follows them every time, including when they cost you money.