Skip to content

Commit 0c8a500

Browse files
committed
fix(command-loader): preserve model field for opencode commands only
- Claude Code commands (user, project scope): sanitize model to undefined - OpenCode commands (opencode, opencode-project scope): preserve model as-is 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
1 parent 2292a61 commit 0c8a500

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/features/claude-code-command-loader/loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ $ARGUMENTS
3434

3535
const formattedDescription = `(${scope}) ${data.description || ""}`
3636

37+
const isOpencodeSource = scope === "opencode" || scope === "opencode-project"
3738
const definition: CommandDefinition = {
3839
name: commandName,
3940
description: formattedDescription,
4041
template: wrappedTemplate,
4142
agent: data.agent,
42-
model: sanitizeModelField(data.model),
43+
model: sanitizeModelField(data.model, isOpencodeSource ? "opencode" : "claude-code"),
4344
subtask: data.subtask,
4445
argumentHint: data["argument-hint"],
4546
}

src/shared/model-sanitizer.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
/**
2-
* Sanitizes model field from frontmatter.
3-
* Always returns undefined to let SDK use default model.
4-
*
5-
* Claude Code and OpenCode use different model ID formats,
6-
* so we ignore the model field and let OpenCode use its configured default.
7-
*
8-
* @param _model - Raw model value from frontmatter (ignored)
9-
* @returns Always undefined to inherit default model
10-
*/
11-
export function sanitizeModelField(_model: unknown): undefined {
1+
type CommandSource = "claude-code" | "opencode"
2+
3+
export function sanitizeModelField(model: unknown, source: CommandSource = "claude-code"): string | undefined {
4+
if (source === "claude-code") {
5+
return undefined
6+
}
7+
8+
if (typeof model === "string" && model.trim().length > 0) {
9+
return model.trim()
10+
}
1211
return undefined
1312
}

src/tools/slashcommand/tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ function discoverCommandsFromDir(commandsDir: string, scope: CommandScope): Comm
2424
const content = readFileSync(commandPath, "utf-8")
2525
const { data, body } = parseFrontmatter(content)
2626

27+
const isOpencodeSource = scope === "opencode" || scope === "opencode-project"
2728
const metadata: CommandMetadata = {
2829
name: commandName,
2930
description: data.description || "",
3031
argumentHint: data["argument-hint"],
31-
model: sanitizeModelField(data.model),
32+
model: sanitizeModelField(data.model, isOpencodeSource ? "opencode" : "claude-code"),
3233
agent: data.agent,
3334
subtask: Boolean(data.subtask),
3435
}

0 commit comments

Comments
 (0)