Skip to content

feat: add claude_code.anthropic_provider config for custom model routing#3295

Open
kilhyeonjun wants to merge 2 commits intocode-yeongyu:devfrom
kilhyeonjun:fix/claude-code-agent-model-provider-override
Open

feat: add claude_code.anthropic_provider config for custom model routing#3295
kilhyeonjun wants to merge 2 commits intocode-yeongyu:devfrom
kilhyeonjun:fix/claude-code-agent-model-provider-override

Conversation

@kilhyeonjun
Copy link
Copy Markdown
Contributor

@kilhyeonjun kilhyeonjun commented Apr 10, 2026

Summary

Claude Code agent files (.claude/agents/*.md) use model aliases like opus, sonnet, haiku which are hardcoded to anthropic/ prefix in claude-model-mapper.ts. Users proxying Anthropic models through custom gateways (e.g., Kiro) get Model not found: anthropic/claude-opus-4-6 errors because they don't have an anthropic provider configured.

Changes

Add claude_code.anthropic_provider config option that overrides the default anthropic provider prefix when resolving agent model aliases.

Files Changed

File Change
src/config/schema/claude-code.ts Add anthropic_provider field to schema
src/features/claude-code-agent-loader/claude-model-mapper.ts Accept optional anthropicProvider param, use it instead of hardcoded ANTHROPIC_PREFIX
src/features/claude-code-agent-loader/loader.ts Pass anthropicProvider through loadAgentsFromDirmapClaudeModelToOpenCode
src/plugin-handlers/agent-config-handler.ts Read claude_code.anthropic_provider from config and pass to loaders
src/features/claude-code-agent-loader/claude-model-mapper.test.ts Add 6 test cases for anthropicProvider override
assets/oh-my-opencode.schema.json Auto-generated schema update

Example Config

{
  "claude_code": {
    "anthropic_provider": "kiro"
  }
}

Behavior

Input Without config With "anthropic_provider": "kiro"
model: opus anthropic/claude-opus-4-6 kiro/claude-opus-4-6
model: sonnet anthropic/claude-sonnet-4-6 kiro/claude-sonnet-4-6
model: haiku anthropic/claude-haiku-4-5 kiro/claude-haiku-4-5
model: claude-opus-4-6 anthropic/claude-opus-4-6 kiro/claude-opus-4-6
model: openai/gpt-5.2 openai/gpt-5.2 (unchanged) openai/gpt-5.2 (unchanged)

Explicit provider/model format is always preserved regardless of config.

Testing

  • 28 unit tests pass (22 existing + 6 new)
  • bun run typecheck passes
  • bun run build succeeds
  • Verified locally with OpenCode + Kiro gateway: all 3 agent types (opus/sonnet/haiku) route correctly through kiro/ provider

Summary by cubic

Adds claude_code.anthropic_provider to route Claude Code agent aliases (opus, sonnet, haiku) and bare claude-* models through a custom provider, fixing “Model not found: anthropic/…” errors with gateways like Kiro. Adds validation to prevent malformed provider values.

  • New Features

    • Overrides the default anthropic/ prefix for aliases and bare claude-* models.
    • Keeps explicit provider/model strings unchanged.
    • Loader applies the override to user and project agents.
    • Validates anthropic_provider (trimmed, non-empty, no /); added tests.
  • Migration

    • Set "claude_code.anthropic_provider": "kiro" (or your gateway) to map model: opuskiro/claude-opus-4-6.

Written for commit 166e104. Summary will update on new commits.

Claude Code agent files (.claude/agents/*.md) use model aliases like
'opus', 'sonnet', 'haiku' which are hardcoded to 'anthropic/' prefix.
Users proxying Anthropic models through custom gateways (e.g., Kiro)
get 'Model not found: anthropic/claude-opus-4-6' errors.

Add claude_code.anthropic_provider config option that overrides the
default 'anthropic' provider prefix when resolving agent model aliases.

Example config:
  { "claude_code": { "anthropic_provider": "kiro" } }

This maps 'model: opus' -> 'kiro/claude-opus-4-6' instead of
'anthropic/claude-opus-4-6', while preserving explicit provider/model
format (e.g., 'openai/gpt-5.2') unchanged.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files

Confidence score: 3/5

  • There is a concrete regression risk in src/config/schema/claude-code.ts: anthropic_provider currently accepts arbitrary strings, and values with whitespace or / can generate malformed model IDs for Claude Code aliases.
  • Given the issue’s medium severity (6/10) and high confidence (9/10), this carries user-facing impact in provider/model resolution, so the merge risk is moderate rather than minimal.
  • Pay close attention to src/config/schema/claude-code.ts - tighten provider-name validation to prevent malformed alias model IDs.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/config/schema/claude-code.ts">

<violation number="1" location="src/config/schema/claude-code.ts:14">
P2: Validate `anthropic_provider` as a provider name instead of accepting arbitrary strings; whitespace or `/` here produces malformed model IDs for every Claude Code alias.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Address review feedback: anthropic_provider now trims whitespace,
requires min length 1, and rejects values containing '/' to prevent
malformed model IDs.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Auto-approved: Safe addition of a config option with clear fallback to default behavior. Tests cover both existing and new functionality, ensuring no regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant