From 0c8a500de4496d911c4e4539e373b2f47238a06c Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 14 Dec 2025 12:24:59 +0900 Subject: [PATCH] fix(command-loader): preserve model field for opencode commands only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- .../claude-code-command-loader/loader.ts | 3 ++- src/shared/model-sanitizer.ts | 21 +++++++++---------- src/tools/slashcommand/tools.ts | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/features/claude-code-command-loader/loader.ts b/src/features/claude-code-command-loader/loader.ts index f981be8..3bcec78 100644 --- a/src/features/claude-code-command-loader/loader.ts +++ b/src/features/claude-code-command-loader/loader.ts @@ -34,12 +34,13 @@ $ARGUMENTS const formattedDescription = `(${scope}) ${data.description || ""}` + const isOpencodeSource = scope === "opencode" || scope === "opencode-project" const definition: CommandDefinition = { name: commandName, description: formattedDescription, template: wrappedTemplate, agent: data.agent, - model: sanitizeModelField(data.model), + model: sanitizeModelField(data.model, isOpencodeSource ? "opencode" : "claude-code"), subtask: data.subtask, argumentHint: data["argument-hint"], } diff --git a/src/shared/model-sanitizer.ts b/src/shared/model-sanitizer.ts index adb8cf6..5c587f5 100644 --- a/src/shared/model-sanitizer.ts +++ b/src/shared/model-sanitizer.ts @@ -1,13 +1,12 @@ -/** - * Sanitizes model field from frontmatter. - * Always returns undefined to let SDK use default model. - * - * Claude Code and OpenCode use different model ID formats, - * so we ignore the model field and let OpenCode use its configured default. - * - * @param _model - Raw model value from frontmatter (ignored) - * @returns Always undefined to inherit default model - */ -export function sanitizeModelField(_model: unknown): undefined { +type CommandSource = "claude-code" | "opencode" + +export function sanitizeModelField(model: unknown, source: CommandSource = "claude-code"): string | undefined { + if (source === "claude-code") { + return undefined + } + + if (typeof model === "string" && model.trim().length > 0) { + return model.trim() + } return undefined } diff --git a/src/tools/slashcommand/tools.ts b/src/tools/slashcommand/tools.ts index e03a66a..3de840d 100644 --- a/src/tools/slashcommand/tools.ts +++ b/src/tools/slashcommand/tools.ts @@ -24,11 +24,12 @@ function discoverCommandsFromDir(commandsDir: string, scope: CommandScope): Comm const content = readFileSync(commandPath, "utf-8") const { data, body } = parseFrontmatter(content) + const isOpencodeSource = scope === "opencode" || scope === "opencode-project" const metadata: CommandMetadata = { name: commandName, description: data.description || "", argumentHint: data["argument-hint"], - model: sanitizeModelField(data.model), + model: sanitizeModelField(data.model, isOpencodeSource ? "opencode" : "claude-code"), agent: data.agent, subtask: Boolean(data.subtask), }