Skip to content

feat(claude): map Claude Code model strings to OpenCode format when importing agents#2333

Open
devxoul wants to merge 4 commits intocode-yeongyu:devfrom
devxoul:feat/claude-model-mapper
Open

feat(claude): map Claude Code model strings to OpenCode format when importing agents#2333
devxoul wants to merge 4 commits intocode-yeongyu:devfrom
devxoul:feat/claude-model-mapper

Conversation

@devxoul
Copy link
Contributor

@devxoul devxoul commented Mar 6, 2026

Summary

  • When importing Claude Code agents (from .claude/agents/ or plugins), the model frontmatter field was parsed but silently dropped
  • Added mapClaudeModelToOpenCode() that converts Claude Code model strings to OpenCode's provider/model format
  • Handles all Claude Code model conventions per official docs:
    • Aliases: sonnetanthropic/claude-sonnet-4-6, opusanthropic/claude-opus-4-6, haikuanthropic/claude-haiku-4-5 (case-insensitive)
    • inherit: returns undefined (no model override, lets OpenCode decide)
    • Bare Claude model IDs: claude-sonnet-4-5-20250514anthropic/claude-sonnet-4-5-20250514 (adds provider prefix)
    • Dot normalization: claude-3.5-sonnetanthropic/claude-3-5-sonnet
    • Already-prefixed: anthropic/claude-sonnet-4-6 passes through unchanged
    • Non-Claude models: dot normalization only, no prefix guessing
  • Integrated into both claude-code-agent-loader and claude-code-plugin-loader agent loaders
  • 19 tests covering aliases, inherit, bare IDs, dot normalization, passthrough, and edge cases

Copy link

@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.

2 issues found across 4 files

Confidence score: 2/5

  • There are two high-severity, high-confidence compatibility problems that are likely user-impacting, so merge risk is elevated rather than routine.
  • In src/features/claude-code-agent-loader/claude-model-mapper.test.ts, normalizing gpt-5.2 to a dashed form breaks OpenCode’s expected model ID, which can cause model resolution failures for non-Claude models.
  • In src/features/claude-code-plugin-loader/agent-loader.ts, missing the required anthropic/ provider prefix on bare Claude model IDs can prevent the OpenCode SDK from resolving models correctly.
  • Pay close attention to src/features/claude-code-agent-loader/claude-model-mapper.test.ts, src/features/claude-code-plugin-loader/agent-loader.ts - model ID normalization/prefix handling is likely to break OpenCode compatibility.
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/features/claude-code-agent-loader/claude-model-mapper.test.ts">

<violation number="1" location="src/features/claude-code-agent-loader/claude-model-mapper.test.ts:62">
P1: Custom agent: **Opencode Compatibility**

The model mapper incorrectly normalizes dots to dashes in non-Claude models like `gpt-5.2`, breaking compatibility with OpenCode where the ID is explicitly `gpt-5.2`.</violation>
</file>

<file name="src/features/claude-code-plugin-loader/agent-loader.ts">

<violation number="1" location="src/features/claude-code-plugin-loader/agent-loader.ts:56">
P1: Custom agent: **Opencode Compatibility**

OpenCode SDK requires model IDs to include the provider prefix (e.g., `anthropic/claude-sonnet-4-5`). Prepend `anthropic/` to bare Claude models so the SDK can correctly resolve the provider.</violation>
</file>

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

Copy link

@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 2 files (changes from recent commits).

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/features/claude-code-agent-loader/claude-model-mapper.ts">

<violation number="1" location="src/features/claude-code-agent-loader/claude-model-mapper.ts:19">
P2: Unsafe object property access - built-in object properties like 'constructor', 'toString', or 'valueOf' will be returned from prototype chain instead of `undefined`, violating the `string | undefined` return type.</violation>
</file>

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

@devxoul devxoul changed the title map Claude Code model strings to OpenCode format when importing agents feat(claude) map Claude Code model strings to OpenCode format when importing agents Mar 6, 2026
@devxoul devxoul changed the title feat(claude) map Claude Code model strings to OpenCode format when importing agents feat(claude): map Claude Code model strings to OpenCode format when importing agents Mar 6, 2026
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