why your ai agent's file search costs so much

why your ai agent's file search costs so much


you put your agent on the best model money can buy. then it went to look something up, and the lookup ran on the best model money can buy too. reading a file and listing a directory is not work that needs a frontier brain, but by default that’s exactly what it gets.

the gotcha

when an agent has to search a big codebase, the smart move is to hand that off. it spins up a subagent, an “explore” agent, to do the grepping and file-reading, then passes the findings back up. good pattern. it keeps the main context clean and lets the real work stay focused.

the catch is that the subagent doesn’t choose its own model. it inherits yours. as of recent claude code (v2.1.198 onward), the built-in explore agent runs on whatever your main session runs on, capped at opus on the claude api. so if you’re driving on opus, your file searches are on opus.

nobody tells you this. it isn’t a line item or a warning. it just quietly happens every time your agent goes looking for something.

why it’s the wrong model for the job

searching a codebase is fetch-and-filter work. grep, read, list, report back. a small fast model does that fine, and it does it cheaper and quicker. the expensive model earns its keep on the hard part, the reasoning and the plan and the actual decision. spending it on “find me every file that imports this” is like flying a surgeon in to read you the phone book.

and searches aren’t rare. a working agent searches constantly. every “where is this defined,” every “what calls this,” every sweep across a repo is another round on the meter. the one operation you do most is the one you least want on the priciest engine.

the fix is one file

drop a project-level explore agent that pins its own model. in .claude/agents/explore.md:

---
name: Explore
description: fast read-only search agent
tools: Read, Grep, Glob
model: haiku
---

you search codebases and report findings. you don't edit files.

a user- or project-level agent named Explore overrides the built-in one and keeps its own model field. now your main session stays on opus for the thinking, and every search underneath it runs on haiku. if you’d rather flip it session-wide, the CLAUDE_CODE_SUBAGENT_MODEL env var does the same for all subagents at once.

the bigger idea

one model for everything is the lazy default, and it’s usually the wrong one. a real team doesn’t put its principal engineer on data entry. you match the person to the task. frontier brains for judgment, cheap hands for legwork. agents are no different, and the model each part of the work runs on is the knob that decides it.

on 5dive an agent is the unmodified claude code harness running on its own box, so this config is yours to set. the .claude/agents file lives in your repo, on your machine, under your control. we’ve said before that the model your agent runs should be a setting, not a marriage. this is the same idea one level down: not just which model your agent runs, but which model each slice of its work runs.

the takeaway

go check what your searches are running on. if your main model is opus and you never set an explore override, the answer is opus, and you’ve been paying frontier rates to list directories. one file fixes it.

try it: spin up an agent on 5dive, point it at a repo, and set an explore agent on a small model before you turn it loose.

5dive is open source (MIT) — the whole thing is on github if you’d rather read the code or self-host it.