claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Task tool `model` parameter returns 404 - Blocks cost-optimized workflows (10-30x unnecessary spending)

Open aitonydev opened this issue 10 months ago • 2 comments

What's Wrong?

The Task tool's model parameter is completely broken in Claude Code 2.1.12+, creating a catch-22 that blocks cost-effective mixed model architectures and causes 10-30x unnecessary spending on simple operations.

The problem:

  • CLI validation requires short model names: "haiku", "sonnet", "opus"
  • API rejects those same short names with 404 errors: {"type":"not_found_error","message":"model: haiku"}
  • Full model IDs (e.g., "claude-haiku-4-5-20251001") are rejected by CLI validation

Result: Users cannot use Opus/Sonnet for main session while delegating simple tasks (file searches, exploration) to Haiku. All sub-agent operations inherit the expensive parent model, causing massive cost waste.


What Should Happen?

The Task tool's model parameter should:

  1. Accept short model names ("haiku", "sonnet", "opus")
  2. Map them to full model IDs using ANTHROPIC_DEFAULT_*_MODEL environment variables
  3. Allow cost-optimized workflows: Expensive models for reasoning, cheap models for execution

Expected workflow:

// Main session uses Opus for architecture
// But delegate simple tasks to Haiku
Task({
  subagent_type: "Explore",
  model: "haiku",  // Should work, currently returns 404
  prompt: "Find authentication code"
})

Cost Impact (HIGH PRIORITY)

This bug forces 10-30x unnecessary spending on routine operations for power users.

Scenario 1: Opus Main Session (Architecture Work)

Task Type Intended Model Forced to Use Cost Multiplier Daily Operations
Deep reasoning, planning Opus Opus ✅ 1x (correct) ~5/day
File searches Haiku Opus ❌ 30x ~10/day
Code exploration Haiku Opus ❌ 30x ~8/day
Browser automation Haiku Opus ❌ 30x ~3/day

Monthly waste for active Opus users: Hundreds of thousands of unnecessary Opus tokens

Scenario 2: Sonnet Main Session (Standard Development)

Task Type Intended Model Forced to Use Cost Multiplier Daily Operations
Implementation Sonnet Sonnet ✅ 1x (correct) ~10/day
File searches Haiku Sonnet ❌ 10x ~15/day
Simple queries Haiku Sonnet ❌ 10x ~10/day

Impact multipliers:

  • Individual developers: 10-30x cost increase on 50%+ of daily operations
  • Teams: Multiplied across entire team
  • Rate limits: Burning Opus/Sonnet limits on trivial file searches

Blocked Workflows

This bug prevents:

  1. Cost-optimized development

    • ❌ Opus for architecture decisions + Haiku for codebase exploration
    • ❌ Sonnet for implementation + Haiku for testing/verification
  2. Rate limit management

    • ❌ Users hitting Opus limits cannot offload simple tasks to Haiku
    • ❌ Forced to wait for Opus rate limits even with Sonnet capacity available
  3. Team cost control

    • ❌ Cannot implement "Opus for architects, Sonnet for developers, Haiku for automation"
    • ❌ All-or-nothing model selection per session
  4. Budget-conscious usage

    • ❌ Educational/hobbyist users cannot use occasional Opus reasoning with Haiku for bulk operations

Steps to Reproduce

Environment:

  • Claude Code version: 2.1.12
  • Platform: macOS (also confirmed on Linux)
  • Session model: Sonnet or Opus (set in ~/.claude/settings.json)

Setup:

  1. Configure environment variables in ~/.claude/settings.json:
{
  "env": {
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-5-20250929"
  },
  "model": "sonnet"
}
  1. Verify environment variable is loaded:
$ echo $ANTHROPIC_DEFAULT_HAIKU_MODEL
claude-haiku-4-5-20251001  # Confirmed loaded

Test 1: Short model name (documented approach)

  1. Attempt to spawn Haiku subagent:
Task({
  subagent_type: "Explore",
  model: "haiku",
  description: "Test haiku model",
  prompt: "List files in src/"
})

Expected: Haiku subagent launches Actual: API Error: 404 {"type":"error","error":{"type":"not_found_error","message":"model: haiku"}}

Test 2: Full model ID

  1. Try using full model ID directly:
Task({
  subagent_type: "Explore",
  model: "claude-haiku-4-5-20251001",
  description: "Test full model ID",
  prompt: "List files in src/"
})

Expected: Should work with full model ID Actual: InputValidationError: Invalid option: expected one of "sonnet"|"opus"|"haiku"

Test 3: Omit model parameter (current workaround)

  1. Omit model parameter:
Task({
  subagent_type: "Explore",
  description: "Test without model",
  prompt: "List files in src/"
})

Result: ✅ Works, but inherits Sonnet/Opus (defeats the purpose, 10-30x cost waste)


Error Messages/Logs

// Attempt 1: Short name "haiku"
{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "model: haiku"
  },
  "request_id": "req_011CXDVkqrUchawYnkT2Yfq3"
}

// Attempt 2: Full model ID
{
  "code": "invalid_value",
  "values": ["sonnet", "opus", "haiku"],
  "path": ["model"],
  "message": "Invalid option: expected one of \"sonnet\"|\"opus\"|\"haiku\""
}

Technical Analysis

The Catch-22

Short model names ("haiku", "sonnet", "opus"):
  ✅ Pass CLI validation
  ❌ Fail at API → 404 "model not found"

Full model IDs ("claude-haiku-4-5-20251001"):
  ❌ Fail CLI validation
  ✅ Would work at API (never gets there)

Omit model parameter:
  ✅ Works (inherits parent model)
  ❌ Defeats cost optimization purpose

Root Cause Hypothesis

The Task tool's model parameter uses a different code path than:

  • Main session model selection (works correctly)
  • Agent frontmatter model: field (works with full IDs)

Evidence suggests the Task tool:

  1. ✅ Validates input accepts only short names
  2. ❌ Skips environment variable resolution step
  3. ❌ Passes raw short name directly to API
  4. ❌ API rejects unrecognized short name

Environment Variable Testing

Configured:

"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001"

Verified loaded:

$ echo $ANTHROPIC_DEFAULT_HAIKU_MODEL
claude-haiku-4-5-20251001  # ✅ Present

Task tool result:

model: "haiku" → Still returns 404

Conclusion: Task tool's model parameter does not consult ANTHROPIC_DEFAULT_*_MODEL environment variables.


Related Issues (4+ Months Old, Still Not Fixed)

This is the parent issue for multiple related problems:

Issue Status Date Description
#9243 OPEN Oct 9, 2025 Invalid Model Name 'sonnet' (original report)
#11682 Closed (dup) Nov 15, 2025 Task Tool Model Parameter 404 Error
#9749 Open Unknown Feature: Allow Sonnet/Haiku combo like opusplan
#5456 Unknown Unknown Sub-agents don't inherit model config
#8932 Unknown Unknown general-purpose agent sets model wrong
#10993 Unknown Unknown Subagent model selection behavior unclear

Timeline:

  • First reported: October 9, 2025 (Issue #9243)
  • Still broken: January 17, 2026 (4+ months)
  • Risk: Issue #9243 has 30-day inactivity notice (may auto-close)

Business Impact

For Individual Developers

  • 💰 Cost overrun: Paying 10-30x more for simple file searches and exploration
  • 🚫 Rate limits: Hitting Opus limits on trivial tasks, blocking real architecture work
  • ⚠️ Workflow inefficiency: Cannot use optimal model for each task type

For Teams & Enterprise

  • 📊 Budget impact: 10-30x waste multiplied across entire team's daily operations
  • ❌ Policy enforcement impossible: Cannot mandate "cheap models for automation, expensive for reasoning"
  • 🏢 Barrier to enterprise adoption: Teams evaluating Claude Code see uncontrolled costs

For Claude Code Adoption

  • 📉 Competitive disadvantage: Other tools allow model optimization
  • 😤 User frustration: Documented feature doesn't work for 4+ months
  • 🔴 Reputation risk: "opusplan removed, now can't even mix models manually"

Requested Fix

Primary Solution

Fix the Task tool's model name resolution to:

  1. Consult ANTHROPIC_DEFAULT_*_MODEL environment variables
  2. Map short names to full model IDs (same logic as main session)
  3. Use the same resolution code path as main session model selection

Alternative Solutions

Option A: Accept full model IDs in CLI validation

  • Update validation to accept both short names and full model IDs
  • Map short names via environment variables, pass full IDs directly

Option B: Add explicit model_id parameter

  • Keep model for short names (fix the resolution)
  • Add model_id for full model IDs (bypass validation)

Testing Checklist

  • [ ] model: "haiku" launches Haiku subagent
  • [ ] model: "sonnet" launches Sonnet subagent
  • [ ] model: "opus" launches Opus subagent
  • [ ] Environment variables are consulted for resolution
  • [ ] Custom models (AWS Bedrock, Azure) work via env vars
  • [ ] Omitting model still inherits parent (backward compatibility)

Workarounds (All Inadequate)

Workaround 1: Omit model parameter

Task({ subagent_type: "Explore", prompt: "..." })

✅ Pros: Works, no errors ❌ Cons: Inherits parent model, 10-30x cost increase, defeats purpose

Workaround 2: Switch main session model

/model haiku  # For exploration
Task(...)
/model opus   # Switch back

✅ Pros: Uses correct model ❌ Cons: Manual, breaks flow, context loss, main session suboptimal

Workaround 3: Custom agents with frontmatter

---
model: claude-haiku-4-5-20251001  # Works in YAML
---

✅ Pros: Full model IDs work in frontmatter ❌ Cons: Only for custom agents, can't use Task tool, no dynamic selection


Why This Needs Priority

This bug blocks a documented, advertised feature (Task tool model parameter) and causes real financial harm:

  1. ✅ Easy to fix: Main session and agent frontmatter already work correctly
  2. 💰 High cost impact: 10-30x waste on 50%+ of operations for power users
  3. ⏰ Long-standing: 4+ months without fix (Issue #9243)
  4. 🏢 Blocks enterprise: Teams cannot control costs effectively
  5. 📉 Adoption barrier: Cost-conscious users cannot use Claude Code optimally

The fix is likely straightforward - just use the same model resolution code path that already works for main sessions and agent frontmatter.


Environment Details

  • Claude Code Version: 2.1.12
  • Platform: macOS (confirmed), Linux (confirmed)
  • API: Anthropic API (not AWS Bedrock or Azure)
  • Affects: All users trying to use Task tool model parameter
  • Severity: HIGH - Causes 10-30x cost waste, blocks documented feature

Additional Context

What works:

  • ✅ Main session model selection via "model": "sonnet" in settings
  • ✅ Environment variables load correctly (ANTHROPIC_DEFAULT_*_MODEL)
  • ✅ Agent frontmatter with full model IDs: model: claude-haiku-4-5-20251001
  • ✅ Task tool without model parameter (inherits parent, expensive but functional)

What's broken:

  • ❌ Task tool model: "haiku" → 404 error
  • ❌ Task tool model: "claude-haiku-4-5-20251001" → CLI validation error
  • ❌ Environment variables not consulted by Task tool

Community validation:

  • Multiple independent reports (Issues #9243, #11682, #8932)
  • Users creating validation hooks specifically to enforce model parameter (to prevent inheritance)
  • Feature requests for "sonnetplan" (15+ comments in #9749)

Request for Timeline:

  • When will this be fixed?
  • Can this be prioritized given the cost impact?
  • Any interim solution if fix requires major refactoring?

Thank you for your attention to this critical cost and functionality issue.

aitonydev avatar Jan 17 '26 20:01 aitonydev

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16115
  2. https://github.com/anthropics/claude-code/issues/11682
  3. https://github.com/anthropics/claude-code/issues/9243

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Jan 17 '26 20:01 github-actions[bot]

This is not a simple duplicate - it provides critical business case analysis and new evidence that other issues lack:

Why This Issue Adds Unique Value

1. Cost Quantification (NEW)

  • 10-30x waste tables with specific daily operation counts
  • Monthly impact calculations for active Opus users
  • Cost multiplier breakdowns by task type
  • None of the related issues (#9243, #11682, #16115) include this financial analysis

2. New Technical Evidence

  • Environment variable testing: Documented that ANTHROPIC_DEFAULT_HAIKU_MODEL loads correctly but Task tool doesn't consult it
  • This is a new finding - we verified the env vars are present but bypassed by Task tool's model parameter

3. Business Impact Analysis (NEW)

  • Enterprise adoption barriers (teams cannot control costs)
  • Rate limit management impossibility (burning Opus on file searches)
  • Team cost control policies cannot be enforced
  • Budget-conscious usage blocked (educational/hobbyist users)

4. Comprehensive Workarounds Documentation

All 3 workarounds documented with detailed pros/cons:

  • Omit model parameter (works but defeats purpose)
  • Switch main session model (manual, breaks flow)
  • Custom agents with frontmatter (limited to agent definitions)

Other issues just mention "omit model parameter" without explaining why this defeats the cost optimization purpose.

Why the Core Issue Needs Priority

While the underlying bug is the same as #9243 (model name resolution failure), this issue:

  • Makes the business case for prioritization with real cost data
  • Demonstrates this is causing measurable financial harm (10-30x waste)
  • Shows this has been broken for over 3 months (Oct 9, 2025 → Jan 17, 2026)
  • Highlights that #9243 is at risk of auto-closure (30-day inactivity notice since Dec 7)

Recommendation

Keep this issue open as a detailed business case companion to #9243. The cost analysis and business impact documentation could help:

  • Justify prioritizing the fix
  • Demonstrate real-world impact on users
  • Show enterprise adoption barriers

If the team prefers to consolidate, I can move the cost analysis and business case sections to #9243 as a comprehensive comment, but this detailed analysis shouldn't be lost in the duplicate closure.

This isn't just a bug report - it's a case for why this bug matters financially.

aitonydev avatar Jan 17 '26 22:01 aitonydev

+1 - Confirmed this issue. Spawning agents with model: sonnet still uses Opus. Billing shows zero Sonnet usage. Significant cost impact for batch operations.

ThanosKitsios avatar Jan 22 '26 21:01 ThanosKitsios

The model parameter on the Agent tool worked correctly in v2.1.68 but regressed in v2.1.69 (and remains broken in v2.1.70).

In 2.1.68, specifying "model": "sonnet" on an Agent tool call dispatches to Sonnet 4.6 as expected. In 2.1.69+, the same parameter is silently ignored and all subagents run on the parent session's model (Opus 4.6). The parameter still exists in the tool schema, it just has no effect.

This suggests it was fixed at some point between the earlier reports here and 2.1.68, then accidentally re-broken. The fix didn't survive whatever changed in 2.1.69.

Tested on Linux (WSL2), Claude Max plan.

willfindlay avatar Mar 06 '26 01:03 willfindlay

Is the fix planned in the near future ? The token cost if of course through the roof, but the difference of speed between a high-effort opus and a haiku subagent is huge, and because of this everything is so slow even for subagents that have extremely simple tasks.

In the meantime, I guess I'll stick with 2.1.68.

ThomasCusson avatar Mar 09 '26 13:03 ThomasCusson

Also, when asking claude 2.1.68 to test it, it seems to work, however "haiku" seems to use more tokens. Probably a different problem, but in Claude's own wordings :

● Not order-dependent. Results are consistent:
                                                 
  ┌────────┬────────┬────────┐
  │ Model  │ Test 1 │ Test 2 │                                                                                                                               
  ├────────┼────────┼────────┤
  │ Haiku  │ 57,602 │ 57,600 │                                                                                                                               
  ├────────┼────────┼────────┤                                                                                                                             
  │ Sonnet │ 17,421 │ 17,419 │                                                                                                                             
  ├────────┼────────┼────────┤
  │ Opus   │ 17,506 │ 17,504 │
  └────────┴────────┴────────┘

  Haiku is consistently ~57.6k tokens vs ~17.5k for Sonnet/Opus, regardless of call order. The numbers within each model are near-identical across runs (±2
  tokens).

  So the difference is model-specific, not ordering. Two hypotheses:

  1. Haiku uses a different tokenizer — the same system prompt/context tokenizes to ~3x more tokens on Haiku's tokenizer
  2. Different system prompt packaging — Haiku might receive a larger system prompt (more guardrails/instructions injected for the smaller model)

  Either way, it's a ~40k token overhead baked into every Haiku subagent call. At Haiku pricing ($0.25/M input) that's ~$0.01 per call — still cheap, but the
   "token savings" of using Haiku are less dramatic than the model pricing alone would suggest. Sonnet/Opus start from a much smaller base.

  Worth noting for cost-conscious subagent dispatch: Haiku's per-call overhead means it's only worth it for genuinely simpler tasks where Sonnet would be
  overkill, not as a blanket "cheaper" default.

This is regardless of effort level set with /model (subagents not inheriting effort level ?)

ThomasCusson avatar Mar 09 '26 13:03 ThomasCusson

I just updated to 2.1.72... Seems to be fixed :

I asked claude to dispatch multiple subagents, ask their identities without hinting them, and test their capabilities.

  ┌─────────────────┬──────────────────────┬─────────────────────────────────────────────────────┬──────────────────────────────┬──────────────────┐         
  │ Model requested │    Self-reported     │                     Sheep trick                     │        12-ball puzzle        │ Tokens (context) │         
  ├─────────────────┼──────────────────────┼─────────────────────────────────────────────────────┼──────────────────────────────┼──────────────────┤         
  │ haiku           │ Haiku 4.5 ✅         │ ✅ (stochastic — failed once, passed once on rerun) │ ✅ correct                   │ ~63k             │
  ├─────────────────┼──────────────────────┼─────────────────────────────────────────────────────┼──────────────────────────────┼──────────────────┤         
  │ sonnet          │ claude-sonnet-4-6 ✅ │ ✅                                                  │ ✅ correct                   │ ~12k             │       
  ├─────────────────┼──────────────────────┼─────────────────────────────────────────────────────┼──────────────────────────────┼──────────────────┤
  │ opus            │ Opus 4.6 ✅          │ ✅                                                  │ ✅ correct, best explanation │ ~12k             │
  └─────────────────┴──────────────────────┴─────────────────────────────────────────────────────┴──────────────────────────────┴──────────────────┘

  Latency: not a useful signal for short outputs — all three are indistinguishable (~2.2s avg). Differences only emerge on long generations (e.g. the 12-ball
   puzzle: Sonnet 44s, Opus 33s), but those conflate output length with speed.

  Conclusion: model routing is working. Each subagent receives and reports the correct model, and behavioral differences (reasoning quality, token counts)
  are consistent with the expected model tier.

Timing however doesn't seem like a big difference (haiku is supposed to be faster), maybe on longer, more token-intensives tasks ? Is the testing methodology sound ? Also, is the number of tokens overhead for haiku normal ? Do you plan on adding possibility to specify "effort level" for subagents as well as model ?

ThomasCusson avatar Mar 10 '26 11:03 ThomasCusson

If anyone's hitting this — I built claude-alias-patch which fixes the Task tool's model parameter and adds support for custom model aliases beyond the hardcoded sonnet/opus/haiku.

It's a single install script — run it locally and it auto-patches your Claude instance. After that, the Task tool correctly resolves model aliases (including custom ones from ANTHROPIC_DEFAULT_*_MODEL env vars) so subagents actually use the model you specify.

Related: #34821

East-rayyy avatar Mar 16 '26 21:03 East-rayyy

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Apr 13 '26 22:04 github-actions[bot]

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Apr 22 '26 14:04 github-actions[bot]