claude-task-master icon indicating copy to clipboard operation
claude-task-master copied to clipboard

bug: Model ID 'claude-code/sonnet' not found when setting main model

Open fengyunzaidushi opened this issue 3 months ago • 2 comments

Bug Description When trying to set the main model to use Claude Code's Sonnet model with the command:

task-master models --set-main claude-code/sonnet

The system returns an error:

❌ Error setting main model: Model ID "claude-code/sonnet" not found

Expected Behavior The command should successfully configure Task Master to use Claude Code's free Sonnet model allocation, allowing users to work without requiring their own Anthropic API key.

Current Workaround Currently, users must use direct Anthropic API model IDs like claude-3-5-sonnet-20241022, which requires a paid Anthropic API key rather than utilizing Claude Code's free model access.

Environment

  • Task Master version: 0.26.0
  • Platform: Windows (win32)
  • Claude Code CLI: Available and authenticated

Additional Context This issue prevents users from leveraging Claude Code's free model allocation through Task Master, forcing them to use paid API keys even when Claude Code CLI is properly configured and available.

Related Issues This appears to be related to the broader Claude Code integration issues mentioned in #1175, #1174, #1173, and #1161, but specifically focuses on the model ID recognition problem.

Requested Enhancement Support for Claude Code model IDs in the format claude-code/sonnet or claude-code/opus to enable free model usage through the Claude Code CLI integration.

fengyunzaidushi avatar Sep 09 '25 15:09 fengyunzaidushi

It is not related/caused by those other issues, but by a change in the new release. The error occurs in the model validation logic.

Root Cause

Looking at the code, I found that:

  1. Claude Code models ARE supported - In supported-models.json, there's a claude-code provider section with models opus and sonnet (lines 48-71)
  2. The issue is with the model ID format - The system expects just sonnet or opus when using the claude-code provider, NOT claude-code/sonnet
  3. The validation logic in models.js (line 464) throws an error when it can't find the model ID, but it's looking for the wrong format

Solution Recommendations

The user should use one of these approaches:

Option 1: Use the correct format (Immediate workaround)

Instead of:

task-master models --set-main claude-code/sonnet

Use:

task-master models --set-main sonnet --claude-code

Option 2: Code Fix Needed

The system should be enhanced to:

  1. Automatically parse provider/model format (e.g., claude-code/sonnet)
  2. Extract the provider hint from the model ID itself
  3. Strip the provider prefix and validate just the model part

Specific Code Changes Needed

In scripts/modules/task-manager/models.js, around line 400-450, the setModelForRole function should:

  1. Check if modelId contains a / separator
  2. If it does, split it into [provider, actualModelId]
  3. Use the extracted provider as the hint if no explicit provider flag was given
  4. Validate using the actualModelId

Example enhancement pattern:

  // Parse provider from model ID if it contains a slash
  if (modelId.includes('/') && !providerHint) {
      const [extractedProvider, extractedModel] = modelId.split('/');
      if (extractedProvider === 'claude-code') {
          providerHint = CUSTOM_PROVIDERS.CLAUDE_CODE;
          modelId = extractedModel; // Use just 'sonnet' or 'opus'
      }
  }

Immediate Workaround for Users

Until the code is fixed, users should:

  1. Use separate flags: task-master models --set-main sonnet --claude-code task-master models --set-main opus --claude-code
  2. Or use the interactive setup: task-master models --setup
  3. Then select claude-code as the provider and sonnet/opus as the model

Additional Context

  • The Claude Code integration is working correctly once configured
  • The models are properly defined in supported-models.json
  • This is purely a command-line parsing/validation issue
  • The feature was added recently (v0.26.0) and this edge case wasn't covered

The issue is valid and should be fixed to improve user experience, especially since the README documentation suggests using the claude-code/sonnet format.

ben-vargas avatar Sep 10 '25 03:09 ben-vargas

Agreed with Ben, the way you set the main model for claude code sonnet is: task-master --set-main sonnet --claude-code

But we could definitely improve on that, moving it to enhancement instead of bug

Crunchyman-ralph avatar Sep 24 '25 07:09 Crunchyman-ralph