DEV Community

Cover image for Claude Code subagents: set model and tools
Mihai Perdum
Mihai Perdum

Posted on Originally published at leanzero.net

Claude Code subagents: set model and tools

A Claude Code subagent runs on the model named in the model: line of its file in .claude/agents/, unless Claude passes a model of its own when it starts it. You can check which model really ran in the subagent's own transcript under ~/.claude/projects/. Google's suggestions for "claude code subagents" on 24 November 2026 include "model" and "model selection", and on GitHub issue #10993 (closed for inactivity in January) asked how the model field and the CLAUDE_CODE_SUBAGENT_MODEL setting interact. Below is a run that shows both the file and the check.

A subagent is a helper Claude starts for one task. It works in its own context window, with its own instructions. You can give it its own model and a short list of tools. When it's done it hands one answer back, and the main conversation never sees its searching and reading. You define one as a Markdown file with YAML frontmatter (a few settings lines between two --- lines) in .claude/agents/.

I wanted the answer from a run, so we wrote a subagent that finds TODO comments, told it to use Haiku and only two tools, and ran it from a session on Opus. Everything below comes from that run: Claude Code 2.1.330 on macOS 27.2.1, 24 November 2026.

Note

Prerequisites: Claude Code installed and signed in (claude --version printed 2.1.330 for us), on a plan that can use Haiku. A terminal. About 10 minutes.

Claude Code subagent frontmatter: the model and tools fields

From the subagents page of the Claude Code docs, the four you'll set first:

Field What it does If you leave it out
name The id Claude and you use to call the agent Required
description When Claude should hand work to it Required
tools Comma-separated list of the tools the agent may use It inherits every tool available to subagents; in background mode, the default, that is a smaller built-in set than a foreground subagent gets
model sonnet, opus, haiku, fable, inherit or a full model id Claude Code walks its model order (below) and ends at the main conversation's model

inherit means the subagent uses whatever model the main conversation uses. When more than one thing names a model, the docs give an order in which the first match wins. First comes a model that Claude itself passes when it starts the subagent. Then the model field in your agent file. Then the CLAUDE_CODE_SUBAGENT_MODEL environment variable. Last, the main conversation's model.

The exception is CLAUDE_CODE_SUBAGENT_MODEL_FORCE set to 1 (Claude Code 2.1.257 or later): then Claude Code ignores the model field and Claude can't pass a model, so CLAUDE_CODE_SUBAGENT_MODEL wins. Set FORCE alone and subagents run on the main conversation's model.

That order is newer than many forum answers. The Claude Code changelog entry for 2.1.251 says the environment variable used to override everything and now only sets the default. It isn't set in our settings.json or shell.

Build and run the subagent

[[steps]]

  1. Create the project — a folder with a Python file holding two TODO comments. Result: grep -n TODO calc.py prints lines 2 and 5.
  2. Write .claude/agents/todo-finder.md — frontmatter with tools: Grep, Read and model: haiku, then the instructions. Result: head -6 shows the four settings between two --- lines.
  3. Ask Claude to use the agent — start claude, then name the agent in your request. Result: Claude reports the two TODO lines from calc.py.
  4. Check which model ran — run cat on the subagent's .meta.json file, then the grep over its transcript. Result: "model":"claude-haiku-5-5" in both.
  5. Check which tools it used — run the grep that lists the subagent's tool calls. Result: one Grep call and the handback.

Step 1: Create the project

  1. In a terminal, run:
mkdir agents-demo && cd agents-demo
printf 'def add(a, b):\n    # TODO: handle strings\n    return a + b\n\n# TODO: add a subtract function\n' > calc.py
grep -n TODO calc.py
Enter fullscreen mode Exit fullscreen mode
  1. You should see:
2:    # TODO: handle strings
5:# TODO: add a subtract function
Enter fullscreen mode Exit fullscreen mode

Step 2: Write the agent file

  1. Make the folder:
mkdir -p .claude/agents
Enter fullscreen mode Exit fullscreen mode
  1. Save this as .claude/agents/todo-finder.md:
---
name: todo-finder
description: Finds TODO comments in the project and lists them with file and line. Use when the user asks what is left to do in the code.
tools: Grep, Read
model: haiku
---

You list TODO comments. Search the project with Grep for the text TODO.
Answer with one line per hit in the form `<file>:<line>: <comment text>`, then one line with the total count.
Do not edit any file.
Enter fullscreen mode Exit fullscreen mode
  1. Check it: head -6 .claude/agents/todo-finder.md should show the four settings lines between two --- lines.

Everything after the closing --- becomes the subagent's instructions. Claude decides when to hand work over from the name and the description, as the docs put it: "Claude uses each subagent's description to decide when to delegate tasks".

A file in .claude/agents/ belongs to the project. Put it in ~/.claude/agents/ and you get it in your other projects on this machine too.

Step 3: Ask Claude to use the agent

  1. Start Claude Code in the folder:
claude
Enter fullscreen mode Exit fullscreen mode
  1. If Claude Code asks whether you trust the folder, accept. Our session ran in auto permission mode (the mode where Claude runs commands without asking each time; Shift+Tab cycles the modes); if yours asks to approve a step, approve it.

  2. Type:

Use the todo-finder agent to list what is left to do in this project.
Enter fullscreen mode Exit fullscreen mode
  1. You should see Claude start the agent and then report two TODOs. In our run Claude called the Agent tool with "subagent_type": "todo-finder" and a brief of its own, and first replied that it had started the agent in the background.

That brief widened the search. Besides TODO it asked for FIXME (a note marking broken code), XXX (the same idea) and HACK. The agent file asks for TODO only. The prompt Claude writes when it starts a subagent reaches the subagent next to its instructions. So Claude's brief can widen what the agent does.

When the subagent finished, the main session answered (lines left out are marked ...):

There are 2 TODOs left in the project, both in `calc.py`:

- `calc.py:2`: handle strings
- `calc.py:5`: add a subtract function

...

The agent's own definition file, `.claude/agents/todo-finder.md`, also contains the word "TODO", but only in its instructions, so it wasn't counted.

...
Enter fullscreen mode Exit fullscreen mode

The agent's own definition file contains the word TODO, and Grep found it. I think that one is worth remembering. When you search a project for a word, your .claude folder is part of the project.

A blue robot at a desk holds a magnifying glass while a small yellow robot in red running shoes hurries toward a stack of printed pages

Step 4: Check which model ran

Claude Code saves each session as a JSON Lines file under ~/.claude/projects/, in a folder named after the project path. Subagents get a subagents folder inside a folder named after the session id, with a transcript and a small metadata file per run.

  1. Exit Claude (/exit), then run:
ls ~/.claude/projects/*agents-demo*/*/subagents/
cat ~/.claude/projects/*agents-demo*/*/subagents/*.meta.json
Enter fullscreen mode Exit fullscreen mode
  1. You should see a .jsonl and a .meta.json file, and "model":"claude-haiku-5-5" in the metadata. Ours:
agent-adf7691bc2ef72df7.jsonl
agent-adf7691bc2ef72df7.meta.json
{"agentType":"todo-finder","isBuiltIn":false,"launchedWithDefaults":true,"description":"Find TODOs in project","toolUseId":"toolu_013vK6PzkLtsjaNSwAXN1W5Q","spawnDepth":1,"requestShape":"background","requestNonInteractive":true,"model":"claude-haiku-5-5","pickedEffortModel":"claude-opus-5-5","finished":true}
Enter fullscreen mode Exit fullscreen mode

Your ids will differ. haiku in the frontmatter became the full model id. Right model. Right file. The same file also has "pickedEffortModel":"claude-opus-5-5", a field the docs don't describe; it matches the main session's model.

I wouldn't stop at the metadata file. An open issue, #85592, reports that it records the model that was requested, which can differ from the one that ran. The subagent's own replies settle it.

  1. Run this. The first grep keeps only the lines Claude wrote ("type":"assistant"), because the request lines in the same file also mention the main session's model:
grep '"type":"assistant"' ~/.claude/projects/*agents-demo*/*/subagents/agent-*.jsonl | grep -o '"model":"[^"]*"' | sort | uniq -c
Enter fullscreen mode Exit fullscreen mode
  1. You should see one line, with every count on claude-haiku-5-5. Ours:
   3 "model":"claude-haiku-5-5"
Enter fullscreen mode Exit fullscreen mode

Your count will differ: each line in the file is one block of a reply (thinking, text or a tool call), and a second run of ours printed 5. What matters is that the lines say haiku and nothing else. I'd trust these lines over the metadata file.

Step 5: Check which tools it used

  1. Run:
grep '"type":"assistant"' ~/.claude/projects/*agents-demo*/*/subagents/agent-*.jsonl | grep -o '"type":"tool_use","id":"[^"]*","name":"[^"]*"' | grep -o '"name":"[^"]*"' | sort | uniq -c
Enter fullscreen mode Exit fullscreen mode
  1. You should see one Grep and one SubagentHandback. Ours:
   1 "name":"Grep"
   1 "name":"SubagentHandback"
Enter fullscreen mode Exit fullscreen mode

The subagent made one Grep call, then SubagentHandback, the call a subagent uses to send its answer back to the main session. The agent used only Grep; Read was allowed too, but Grep had already returned the matching lines with their line numbers. I can't tell you from this run what it would do if asked for a tool outside its list; we did not test that. I'd still keep the list this short for any helper that only reads.

A small robot with a magnifying glass finds two yellow sticky notes on a long printed page of code

When the subagent model in your frontmatter seems ignored

I'd check the per-message "model" lines from Step 4 first, since they come from the replies themselves. If they show a model you didn't set, look at the Agent call in the main transcript: a "model" in its input beats your frontmatter, because it's first in the order above. Ours had none. None at all. This jq command lists the input keys of the Agent call:

jq -c 'select(.type=="assistant") | .message.content[]? | select(.type=="tool_use" and .name=="Agent") | .input | keys' ~/.claude/projects/*agents-demo*/*.jsonl
Enter fullscreen mode Exit fullscreen mode

It should print one list per Agent call. Ours printed:

["description","prompt","subagent_type"]
Enter fullscreen mode Exit fullscreen mode

No "model" in that list means Claude did not pass one. Then I'd look at the frontmatter: model: has to sit between the two --- lines and be spelled as one of the values in the table. Last, check whether CLAUDE_CODE_SUBAGENT_MODEL_FORCE is set in your environment or in the env block of a settings file.

Subagents sit next to two other ways of extending Claude Code. A PreToolUse hook is a script that can block a tool call, and a skill is a set of instructions Claude loads into the main conversation. A subagent gets a separate context and, as here, a model you pick. If you're choosing which model to give a helper, our agentic benchmarks compare models on the same coding tasks.

Clean up

cd .. && rm -r agents-demo
Enter fullscreen mode Exit fullscreen mode

Check it: ls agents-demo should print No such file or directory.

[[takeaways]]

  • You have a project subagent in .claude/agents/todo-finder.md that runs on Haiku with Grep and Read allowed, and the "model" lines in its transcript under ~/.claude/projects/<project>/<session>/subagents/ show the model that ran.
  • In our run it used one Grep call, no shell, no edits.
  • Claude's own brief to the subagent can widen its task, and a model Claude passes in that call beats the frontmatter.
  • Not covered here: permissionMode, a subagent's own skills or hooks, and the /agents command.

Originally published on leanzero.net. More Atlassian, Forge and local-AI write-ups at leanzero.net/blog, and if you're planning a migration or a Forge app, that's what we do: leanzero.net/services.

Top comments (0)