The Claude Code Changelog
All Episodes
Route Claude Code Workflow Agents by Step

Route Claude Code Workflow Agents by Step

0:00|0:00

Claude Code 2.1.300 adds step-aware workflow routing: mods can rewrite an agent’s prompt and choose its model, letting teams balance cost and capability across a workflow. We cover model fallbacks and allowlists, stricter hook validation, practical safeguards, and several smaller fixes—including clearer cache metrics and improved MCP tool search behavior.


Chapter 1

Per Step Model Routing With agent.spawn

Lachlan Reed

Right, so a few days ago we talked about forcing every workflow agent onto one cheap model. This one is the follow up. This is The Claude Code Changelog, brought to you by Jellypod AI. I'm Lachlan.

James Turner

And I'm James. Today it's Claude Code 2.1.300, released October 14th. The headline is that the agent.spawn mod hook can now rewrite a workflow agent's prompt and its model. Before this, per the changelog, that hook could only refuse workflow agents. It could say no, and that was it.

Lachlan Reed

And that matters because of what we covered in 2.1.296. CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL puts every workflow agent on one model. Handy for cost, but it's a blunt instrument. Your simple discovery step runs fine on Haiku 5.5, then your heavy synthesis step, or the one that needs strict structured output, falls off a cliff because it's on the same cheap model.

James Turner

So now you get step aware routing. In a TypeScript mod, you register on agent.spawn. For workflow agents, the event carries the run ID and the step index, plus the prompt. You look at those, and you return the changes. Roughly: an object with model set to haiku, and prompt set to the original event prompt plus a new line saying, rule, return strict JSON only.

Lachlan Reed

Where does that mod live? Your project's mods folder, or you can ship it inside a custom plugin. Same idea either way. And on the model value, you can use a short alias like haiku or sonnet, or a full model ID. Both resolve now, and that ties into a fix in this release.

James Turner

Right. Agent hooks used to ignore their model setting entirely. In 2.1.300, aliases like haiku resolve properly, a subagent's own frontmatter model no longer overrides it, and an unavailable model falls back to the caller's model instead of letting the action through. Before that fix, a hook that set a model wasn't something you could lean on.

Lachlan Reed

Let's make it concrete. Say you've got a workflow that fans out across a repo. Early steps are scanning files and listing candidates. Your mod checks the step index, sends those to Haiku. The final step that merges findings and writes a plan, you send to Sonnet or Opus. Same workflow, two price tiers, no env var forcing everything down.

James Turner

The prompt side is just as useful, I think. Since you can rewrite the prompt before launch, you can inject your team's formatting rules, a repo specific schema, or strip out sensitive text from the input. It's context you'd otherwise have to repeat in every workflow definition. One mod, applied everywhere.

Lachlan Reed

Now, caveats. First, the hook's model beats the model in a subagent definition file. The docs say that when a mod sets a model in agent.spawn, Claude Code uses it in place of the per invocation choice. But your organization's availableModels allowlist still applies. If you assign a model that isn't permitted, it falls back to the caller's model, and it won't warn you loudly, so check which model actually ran.

James Turner

Second, validation is stricter in 2.1.300. The changelog says updatedInput from PreToolUse and PermissionRequest hooks is now validated like Claude's own input. Unknown keys get dropped, and input the tool rejects denies the call. So don't get creative with extra fields. And third, and this is my own read of how hooks behave, treat errors seriously. If your hook throws or denies the spawn, that workflow step doesn't run. So wrap your logic and return the original values as a default.

Lachlan Reed

Quick fire on the smaller stuff. Mods can now draw virtualText in the prompt box, so ghost text or shortcut hints that never end up in your draft or the submitted prompt. OpenTelemetry api_request events now split cache writes into cache_creation_5m_tokens and cache_creation_1h_tokens, which is gold if you're watching cache costs.

James Turner

Also fixed: ENABLE_TOOL_SEARCH=auto no longer switches itself off mid conversation when MCP servers reconnect after a resume. Exiting now force kills background commands still running 1.5 seconds after being asked to stop. And /autocompact stops warning about high token usage when you pick a smaller window.

Lachlan Reed

If you've already got workflow pipelines running, update to 2.1.300, write a tiny mod that logs the step index and prompt first, and then start routing. Log before you route, so you know what you're actually sending.