Skip to content

fix: honor OPENCODE_DISABLE_CLAUDE_CODE env var#2038

Closed
gustavosmendes wants to merge 1 commit intocode-yeongyu:devfrom
gustavosmendes:fix/honor-opencode-disable-claude-code-env
Closed

fix: honor OPENCODE_DISABLE_CLAUDE_CODE env var#2038
gustavosmendes wants to merge 1 commit intocode-yeongyu:devfrom
gustavosmendes:fix/honor-opencode-disable-claude-code-env

Conversation

@gustavosmendes
Copy link
Copy Markdown
Contributor

@gustavosmendes gustavosmendes commented Feb 22, 2026

Summary

Fixes #2037 — oh-my-opencode ignored OPENCODE_DISABLE_CLAUDE_CODE and related env vars, injecting Claude Code components into the resolved config regardless of the user's OpenCode-level opt-out.

What changed

  • applyEnvVarOverrides(config, env?) — pure function (env injected as parameter, testable without global mocks) called at the end of loadPluginConfig. Honors both master and per-component env vars:
    • OPENCODE_DISABLE_CLAUDE_CODE=1|true → disables all seven component gates
    • OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1|true → disables only skills (matching OpenCode core's per-component cascade from flag.ts)
  • isTruthy(env, key) — case-insensitive env var parser ("1", "true", "TRUE", "True" all work)
  • isClaudeCodeEnabled(claudeCode, component) — consolidates the ?? true / !== false scatter across 8 call sites into a single function. Also honours the new claude_code.enabled master switch.
  • claude_code.enabled?: boolean field in ClaudeCodeConfigSchema — single JSON-level master toggle subordinating all per-component flags.

Files changed

File Change
src/config/schema/claude-code.ts enabled?: boolean field + isClaudeCodeEnabled helper
src/plugin-config.ts applyEnvVarOverrides with isTruthy + call in loadPluginConfig
src/plugin-handlers/plugin-components-loader.ts gate → isClaudeCodeEnabled
src/plugin-handlers/command-config-handler.ts 2 gates → isClaudeCodeEnabled
src/plugin-handlers/agent-config-handler.ts 2 gates → isClaudeCodeEnabled
src/plugin-handlers/mcp-config-handler.ts gate → isClaudeCodeEnabled
src/plugin/hooks/create-transform-hooks.ts gate → isClaudeCodeEnabled
src/plugin/skill-context.ts !== falseisClaudeCodeEnabled
src/plugin-config.test.ts 30 tests (84 assertions) covering overrides, case sensitivity, edge cases

Behavior

Scenario Before After
OPENCODE_DISABLE_CLAUDE_CODE=1 All 7 gates active All 7 gates disabled
OPENCODE_DISABLE_CLAUDE_CODE=TRUE All 7 gates active All 7 gates disabled (case-insensitive)
OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1 Skills active Skills disabled, other 6 unchanged
OPENCODE_DISABLE_CLAUDE_CODE=1 + SKILLS=0 N/A All 7 disabled (master wins)
claude_code.enabled: false in JSON N/A (field didn't exist) All 7 gates disabled
claude_code.mcp: false in JSON mcp disabled unchanged
No env var, no JSON override All 7 active unchanged

Existing workaround (claude_code.{ agents,commands,hooks,mcp,plugins,skills }: false) continues to work.

Test plan

  • bun test src/plugin-config.test.ts — 30 pass (84 assertions)
  • bun test — full suite passes, 0 fail
  • Typecheck clean
  • Manual: OPENCODE_DISABLE_CLAUDE_CODE=1 opencode debug config | rg "everything-claude-code" should return empty

Review feedback addressed

  • cubic P1: Added OPENCODE_DISABLE_CLAUDE_CODE_SKILLS per-component support (confirmed real env var from OpenCode core flag.ts)
  • Copilot: Fixed docstring from "pure" to "testable without global mocks"
  • Copilot: Added per-component env var support (SKILLS)
  • Code quality: Removed double shallow-copy at call site
  • Testing: Added case-insensitive tests, edge cases ("", "yes", undefined), per-component override tests

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the plugin’s Claude Code integration gating so OpenCode’s OPENCODE_DISABLE_CLAUDE_CODE opt-out is reflected in the resolved oh-my-opencode config, and consolidates the scattered per-component enable checks behind a single helper.

Changes:

  • Added applyEnvVarOverrides(config, env?) and applied it in loadPluginConfig to force-disable Claude Code components when OPENCODE_DISABLE_CLAUDE_CODE is set.
  • Added claude_code.enabled (master gate) and isClaudeCodeEnabled(...) helper, then updated handlers/hooks to use it consistently.
  • Added/expanded tests covering env overrides and the new gating helper.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/config/schema/claude-code.ts Adds enabled?: boolean master switch and introduces isClaudeCodeEnabled helper.
src/plugin-config.ts Adds applyEnvVarOverrides and applies it after merging user/project configs.
src/plugin-handlers/plugin-components-loader.ts Uses isClaudeCodeEnabled(..., "plugins") to gate Claude plugin discovery/loading.
src/plugin-handlers/command-config-handler.ts Switches Claude commands/skills gating to isClaudeCodeEnabled.
src/plugin-handlers/agent-config-handler.ts Switches Claude skills/agents gating to isClaudeCodeEnabled.
src/plugin-handlers/mcp-config-handler.ts Switches Claude MCP gating to isClaudeCodeEnabled.
src/plugin/hooks/create-transform-hooks.ts Switches Claude hooks gating to isClaudeCodeEnabled.
src/plugin/skill-context.ts Replaces !== false skills gating with isClaudeCodeEnabled.
src/plugin-config.test.ts Adds tests for applyEnvVarOverrides and isClaudeCodeEnabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/plugin-config.ts
Comment on lines +24 to +35
/**
* Applies hard overrides from OpenCode env vars onto the resolved config.
* Accepts an optional `env` parameter so the function stays pure and testable.
*/
export function applyEnvVarOverrides(
config: OhMyOpenCodeConfig,
env: NodeJS.ProcessEnv = process.env,
): OhMyOpenCodeConfig {
const masterDisabled =
env.OPENCODE_DISABLE_CLAUDE_CODE === "1" ||
env.OPENCODE_DISABLE_CLAUDE_CODE === "true";

Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

applyEnvVarOverrides currently only checks OPENCODE_DISABLE_CLAUDE_CODE ("1"/"true"). The PR description/issue mentions OPENCODE_DISABLE_CLAUDE_CODE* (e.g., *_SKILLS, *_PROMPT) and OPENCODE_DISABLE_EXTERNAL_SKILLS; if those are intended to be honored too, they should be mapped to the relevant component flags here (or the description should be narrowed to just the master env var).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in c0ba654:

  1. OPENCODE_DISABLE_CLAUDE_CODE_SKILLS is now honored — disables only the skills component. Master switch takes precedence when both are set.
  2. OPENCODE_DISABLE_CLAUDE_CODE_PROMPT was intentionally omitted — it controls ~/.claude/CLAUDE.md loading in OpenCode core, but oh-my-opencode doesn't load CLAUDE.md as a prompt, so there's no component to map it to.
  3. OPENCODE_DISABLE_EXTERNAL_SKILLS cascades from SKILLS in OpenCode core and is beyond this plugin's scope (external skill loading is handled by OpenCode itself).
  4. Parsing is now case-insensitive via isTruthy() helper ("1", "true", "TRUE", "True" all work).

Comment thread src/plugin-config.ts
Comment on lines +24 to +31
/**
* Applies hard overrides from OpenCode env vars onto the resolved config.
* Accepts an optional `env` parameter so the function stays pure and testable.
*/
export function applyEnvVarOverrides(
config: OhMyOpenCodeConfig,
env: NodeJS.ProcessEnv = process.env,
): OhMyOpenCodeConfig {
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The docstring says the function "stays pure", but the default parameter reads process.env (and loadPluginConfig calls it without passing env), so the function isn't referentially transparent by default. Consider requiring env to be passed explicitly (e.g., from loadPluginConfig) or adjust the wording to describe it as "testable without global mocks" rather than "pure".

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in c0ba654 — docstring updated from "stays pure" to "testable without global mocks", which accurately describes the design intent (env parameter injection for testing, process.env default for production).

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 9 files

Confidence score: 3/5

  • There is a concrete compatibility gap: src/plugin-config.ts ignores OPENCODE_DISABLE_CLAUDE_CODE_SKILLS, so OpenCode users can’t disable Claude Code skill loading as expected.
  • This is a user-facing behavior change for a supported integration, which raises some risk beyond a routine merge even though it’s localized.
  • Pay close attention to src/plugin-config.ts - ensure the OpenCode disable flag is honored.
Prompt for AI agents (all 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/plugin-config.ts">

<violation number="1" location="src/plugin-config.ts:32">
P1: Custom agent: **Opencode Compatibility**

The PR ignores the `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` environment variable, which OpenCode supports to selectively disable Claude Code skill loading. To maintain compatibility with OpenCode's configuration system, the plugin should also honor this specific environment variable to disable the `skills` component when set.</violation>
</file>

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

Comment thread src/plugin-config.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Closes #2037

Adds `applyEnvVarOverrides` (pure fn, injectable env) called at the end
of `loadPluginConfig`. When `OPENCODE_DISABLE_CLAUDE_CODE=1` (or `true`)
all seven Claude Code component gates are forced to `false` before any
handler runs.

Adds `isClaudeCodeEnabled(claudeCode, component)` helper that consolidates
the `?? true` / `!== false` scatter across 8 call sites into a single
function that also honours the new `claude_code.enabled` master switch.

Changes:
- `src/config/schema/claude-code.ts`: add `enabled?: boolean` field +
  `isClaudeCodeEnabled` helper
- `src/plugin-config.ts`: add `applyEnvVarOverrides`, call in
  `loadPluginConfig`
- 7 handlers/context files: replace raw `?.X ?? true` / `!== false`
  with `isClaudeCodeEnabled`
- `src/plugin-config.test.ts`: 15 new tests covering all branches
@gustavosmendes gustavosmendes force-pushed the fix/honor-opencode-disable-claude-code-env branch from c0ba654 to 93e274e Compare February 22, 2026 06:56
@code-yeongyu
Copy link
Copy Markdown
Owner

[sisyphus-bot]

PR Review Assessment

Summary

This PR fixes the OPENCODE_DISABLE_CLAUDE_CODE environment variable being ignored by oh-my-opencode. The fix properly honors both the master switch and per-component overrides.

Changes Analysis

Aspect Status
CI Status ✅ All passing (test, typecheck, build, cla, GitGuardian)
Test Coverage ✅ 30 new tests (84 assertions) covering env overrides, case-insensitivity, edge cases
Code Quality ✅ Clean consolidation of 8 scattered gate checks into isClaudeCodeEnabled() helper
Files Changed 9 files - focused, surgical changes

Technical Review

What it fixes:

  • OPENCODE_DISABLE_CLAUDE_CODE=1|true now disables all 7 Claude Code component gates
  • OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1|true disables only skills (per OpenCode core convention)
  • Added claude_code.enabled master gate in schema
  • Case-insensitive parsing ("1", "true", "TRUE" all work)

Architecture:

  • applyEnvVarOverrides() is testable (env injected as parameter)
  • Pure function approach avoids global mocks in tests
  • 8 call sites now use single isClaudeCodeEnabled() helper instead of scattered ?? true checks

Review Feedback Addressed:

  • ✅ cubic-dev-ai P1 concern: OPENCODE_DISABLE_CLAUDE_CODE_SKILLS is now supported (see src/plugin-config.ts lines 62-70)
  • ✅ Copilot docstring feedback addressed
  • ✅ Code quality: removed double shallow-copy

Risk Assessment

Risk Level Notes
Regression LOW All existing tests pass; new tests cover edge cases
Breaking Change NONE Adds new capability without changing existing behavior
Scope Creep NONE Changes are focused and surgical

Recommendation

This is a well-structured bugfix with:

  • Comprehensive test coverage
  • Clean architectural approach
  • All CI checks passing
  • Review feedback incorporated

Action Required: Needs maintainer approval to merge. The reviewDecision field is empty and mergeable is UNKNOWN, so automatic merging is blocked pending human review.

@code-yeongyu code-yeongyu added the triage:bug Confirmed bug with repro steps label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:bug Confirmed bug with repro steps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude plugin commands leak into OpenCode despite OPENCODE_DISABLE_CLAUDE_CODE*

3 participants