fix: resolve ${CLAUDE_PLUGIN_ROOT} in plugin commands, agents, and skills

When loading Claude Code plugins, the hooks JSON config already had
${CLAUDE_PLUGIN_ROOT} replaced via resolvePluginPath. However, command
markdown bodies, agent prompts, and skill content were passed through
as-is, leaving the variable unresolved. This caused plugin commands
(e.g. codex:review) to fail when executed in OpenCode because the shell
had no CLAUDE_PLUGIN_ROOT environment variable set.

Apply resolvePluginPath to:
- command-loader.ts: command body before wrapping in template
- agent-loader.ts: agent prompt body
- skill-loader.ts: skill body after @path resolution
This commit is contained in:
Biem
2026-05-04 19:47:08 +08:00
parent 6b9731923d
commit a26117d944
3 changed files with 8 additions and 3 deletions
@@ -4,6 +4,7 @@ import { parseFrontmatter } from "../../shared/frontmatter"
import { isMarkdownFile } from "../../shared/file-utils"
import { log } from "../../shared/logger"
import { parseToolsConfig } from "../../shared/parse-tools-config"
import { resolvePluginPath } from "./plugin-path-resolver"
import type { AgentFrontmatter, ClaudeCodeAgentConfig } from "../claude-code-agent-loader/types"
import { mapClaudeModelToOpenCode } from "../claude-code-agent-loader/claude-model-mapper"
import type { LoadedPlugin } from "./types"
@@ -38,7 +39,7 @@ export function loadPluginAgents(plugins: LoadedPlugin[]): Record<string, Claude
const config: ClaudeCodeAgentConfig = {
description: formattedDescription,
mode: "subagent",
prompt: body.trim(),
prompt: resolvePluginPath(body.trim(), plugin.installPath),
...(modelString ? { model: modelString } : {}),
}
@@ -3,6 +3,7 @@ import { basename, join } from "path"
import { parseFrontmatter } from "../../shared/frontmatter"
import { isMarkdownFile } from "../../shared/file-utils"
import { sanitizeModelField } from "../../shared/model-sanitizer"
import { resolvePluginPath } from "./plugin-path-resolver"
import { log } from "../../shared/logger"
import type { CommandDefinition, CommandFrontmatter } from "../claude-code-command-loader/types"
import type { LoadedPlugin } from "./types"
@@ -26,7 +27,8 @@ export function loadPluginCommands(plugins: LoadedPlugin[]): Record<string, Comm
const content = readFileSync(commandPath, "utf-8")
const { data, body } = parseFrontmatter<CommandFrontmatter>(content)
const wrappedTemplate = `<command-instruction>\n${body.trim()}\n</command-instruction>\n\n<user-request>\n$ARGUMENTS\n</user-request>`
const resolvedBody = resolvePluginPath(body, plugin.installPath)
const wrappedTemplate = `<command-instruction>\n${resolvedBody.trim()}\n</command-instruction>\n\n<user-request>\n$ARGUMENTS\n</user-request>`
const formattedDescription = `(plugin: ${plugin.name}) ${data.description || ""}`
const definition = {
@@ -4,6 +4,7 @@ import { parseFrontmatter } from "../../shared/frontmatter"
import { resolveSymlink } from "../../shared/file-utils"
import { sanitizeModelField } from "../../shared/model-sanitizer"
import { resolveSkillPathReferences } from "../../shared/skill-path-resolver"
import { resolvePluginPath } from "./plugin-path-resolver"
import { log } from "../../shared/logger"
import type { CommandDefinition } from "../claude-code-command-loader/types"
import type { SkillMetadata } from "../opencode-skill-loader/types"
@@ -39,7 +40,8 @@ export function loadPluginSkillsAsCommands(
const formattedDescription = `(plugin: ${plugin.name} - Skill) ${originalDescription}`
const resolvedBody = resolveSkillPathReferences(body.trim(), resolvedPath)
const wrappedTemplate = `<skill-instruction>\nBase directory for this skill: ${resolvedPath}/\nFile references (@path) in this skill are relative to this directory.\n\n${resolvedBody}\n</skill-instruction>\n\n<user-request>\n$ARGUMENTS\n</user-request>`
const pluginResolvedBody = resolvePluginPath(resolvedBody, plugin.installPath)
const wrappedTemplate = `<skill-instruction>\nBase directory for this skill: ${resolvedPath}/\nFile references (@path) in this skill are relative to this directory.\n\n${pluginResolvedBody}\n</skill-instruction>\n\n<user-request>\n$ARGUMENTS\n</user-request>`
const definition = {
name: namespacedName,