Skip to content

Commit 26642f0

Browse files
committed
fix: decouple DISABLE_EXTERNAL_SKILLS from DISABLE_CLAUDE_CODE (anomalyco#12432)
OPENCODE_DISABLE_CLAUDE_CODE was blocking .agents/skills/ loading because OPENCODE_DISABLE_EXTERNAL_SKILLS chained from OPENCODE_DISABLE_CLAUDE_CODE_SKILLS. Now each directory family has its own independent flag: - .claude → OPENCODE_DISABLE_CLAUDE_CODE_SKILLS (still inherits DISABLE_CLAUDE_CODE) - .agents → OPENCODE_DISABLE_EXTERNAL_SKILLS (independent) Both flags are now dynamic getters so they respond to runtime env changes.
1 parent ac2aebe commit 26642f0

3 files changed

Lines changed: 221 additions & 17 deletions

File tree

‎packages/opencode/src/flag/flag.ts‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ export namespace Flag {
2121
export const OPENCODE_DISABLE_CLAUDE_CODE = truthy("OPENCODE_DISABLE_CLAUDE_CODE")
2222
export const OPENCODE_DISABLE_CLAUDE_CODE_PROMPT =
2323
OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_PROMPT")
24-
export const OPENCODE_DISABLE_CLAUDE_CODE_SKILLS =
25-
OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS")
26-
export const OPENCODE_DISABLE_EXTERNAL_SKILLS =
27-
OPENCODE_DISABLE_CLAUDE_CODE_SKILLS || truthy("OPENCODE_DISABLE_EXTERNAL_SKILLS")
24+
export declare const OPENCODE_DISABLE_CLAUDE_CODE_SKILLS: boolean
25+
export declare const OPENCODE_DISABLE_EXTERNAL_SKILLS: boolean
2826
export declare const OPENCODE_DISABLE_PROJECT_CONFIG: boolean
2927
export const OPENCODE_FAKE_VCS = process.env["OPENCODE_FAKE_VCS"]
3028
export declare const OPENCODE_CLIENT: string
@@ -93,6 +91,27 @@ Object.defineProperty(Flag, "OPENCODE_CLIENT", {
9391
configurable: false,
9492
})
9593

94+
// Dynamic getter for OPENCODE_DISABLE_CLAUDE_CODE_SKILLS
95+
// Evaluated at access time so tests and external tooling can toggle it
96+
Object.defineProperty(Flag, "OPENCODE_DISABLE_CLAUDE_CODE_SKILLS", {
97+
get() {
98+
return truthy("OPENCODE_DISABLE_CLAUDE_CODE") || truthy("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS")
99+
},
100+
enumerable: true,
101+
configurable: false,
102+
})
103+
104+
// Dynamic getter for OPENCODE_DISABLE_EXTERNAL_SKILLS
105+
// Independent of OPENCODE_DISABLE_CLAUDE_CODE so disabling Claude Code
106+
// doesn't block .agents/skills/ loading
107+
Object.defineProperty(Flag, "OPENCODE_DISABLE_EXTERNAL_SKILLS", {
108+
get() {
109+
return truthy("OPENCODE_DISABLE_EXTERNAL_SKILLS")
110+
},
111+
enumerable: true,
112+
configurable: false,
113+
})
114+
96115
// Dynamic getter for OPENCODE_EXPERIMENTAL_AGENT_TEAMS
97116
// This must be evaluated at access time, not module load time,
98117
// because integration tests and external tooling may set this env var at runtime

‎packages/opencode/src/skill/skill.ts‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,26 @@ export namespace Skill {
105105

106106
// Scan external skill directories (.claude/skills/, .agents/skills/, etc.)
107107
// Load global (home) first, then project-level (so project-level overwrites)
108-
if (!Flag.OPENCODE_DISABLE_EXTERNAL_SKILLS) {
109-
for (const dir of EXTERNAL_DIRS) {
110-
const root = path.join(Global.Path.home, dir)
111-
if (!(await Filesystem.isDir(root))) continue
112-
await scanExternal(root, "global")
113-
}
108+
// Each directory family has its own disable flag:
109+
// .claude → OPENCODE_DISABLE_CLAUDE_CODE_SKILLS (also disabled by OPENCODE_DISABLE_CLAUDE_CODE)
110+
// .agents → OPENCODE_DISABLE_EXTERNAL_SKILLS (independent)
111+
const enabledDirs = EXTERNAL_DIRS.filter((dir) => {
112+
if (dir === ".claude") return !Flag.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS
113+
return !Flag.OPENCODE_DISABLE_EXTERNAL_SKILLS
114+
})
115+
116+
for (const dir of enabledDirs) {
117+
const root = path.join(Global.Path.home, dir)
118+
if (!(await Filesystem.isDir(root))) continue
119+
await scanExternal(root, "global")
120+
}
114121

115-
for await (const root of Filesystem.up({
116-
targets: EXTERNAL_DIRS,
117-
start: Instance.directory,
118-
stop: Instance.worktree,
119-
})) {
120-
await scanExternal(root, "project")
121-
}
122+
for await (const root of Filesystem.up({
123+
targets: enabledDirs,
124+
start: Instance.directory,
125+
stop: Instance.worktree,
126+
})) {
127+
await scanExternal(root, "project")
122128
}
123129

124130
// Scan .opencode/skill/ directories
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import { describe, expect, test, beforeEach, afterEach } from "bun:test"
2+
import path from "path"
3+
import { tmpdir } from "../fixture/fixture"
4+
import { Instance } from "../../src/project/instance"
5+
import { Skill } from "../../src/skill/skill"
6+
7+
// Helper to write a minimal SKILL.md into a dir
8+
async function writeSkill(dir: string, name: string) {
9+
await Bun.write(
10+
path.join(dir, "SKILL.md"),
11+
`---
12+
name: ${name}
13+
description: Test skill ${name}
14+
---
15+
16+
# ${name}
17+
`,
18+
)
19+
}
20+
21+
describe("skill disable flags", () => {
22+
const saved: Record<string, string | undefined> = {}
23+
const envKeys = [
24+
"OPENCODE_DISABLE_CLAUDE_CODE",
25+
"OPENCODE_DISABLE_CLAUDE_CODE_SKILLS",
26+
"OPENCODE_DISABLE_EXTERNAL_SKILLS",
27+
"OPENCODE_TEST_HOME",
28+
]
29+
30+
beforeEach(() => {
31+
for (const key of envKeys) {
32+
saved[key] = process.env[key]
33+
}
34+
})
35+
36+
afterEach(() => {
37+
for (const key of envKeys) {
38+
if (saved[key] === undefined) delete process.env[key]
39+
else process.env[key] = saved[key]
40+
}
41+
})
42+
43+
test("both .claude and .agents skills load by default", async () => {
44+
delete process.env.OPENCODE_DISABLE_CLAUDE_CODE
45+
delete process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS
46+
delete process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS
47+
48+
await using tmp = await tmpdir({
49+
git: true,
50+
init: async (dir) => {
51+
await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill")
52+
await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill")
53+
},
54+
})
55+
56+
process.env.OPENCODE_TEST_HOME = tmp.path
57+
58+
await Instance.provide({
59+
directory: tmp.path,
60+
fn: async () => {
61+
const skills = await Skill.all()
62+
const names = skills.map((s) => s.name)
63+
expect(names).toContain("claude-skill")
64+
expect(names).toContain("agents-skill")
65+
},
66+
})
67+
})
68+
69+
test("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1 blocks .claude but not .agents", async () => {
70+
// Note: We need to reload the flag module to pick up env changes.
71+
// Since Flag values are computed at import time for the chained ones,
72+
// we test via the skill.ts logic which reads the flags.
73+
// The fix decoupled EXTERNAL_SKILLS from CLAUDE_CODE_SKILLS, so we
74+
// test the skill scanning code directly.
75+
delete process.env.OPENCODE_DISABLE_CLAUDE_CODE
76+
process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = "1"
77+
delete process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS
78+
79+
await using tmp = await tmpdir({
80+
git: true,
81+
init: async (dir) => {
82+
await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill")
83+
await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill")
84+
},
85+
})
86+
87+
process.env.OPENCODE_TEST_HOME = tmp.path
88+
89+
await Instance.provide({
90+
directory: tmp.path,
91+
fn: async () => {
92+
const skills = await Skill.all()
93+
const names = skills.map((s) => s.name)
94+
// .claude skills blocked
95+
expect(names).not.toContain("claude-skill")
96+
// .agents skills still load
97+
expect(names).toContain("agents-skill")
98+
},
99+
})
100+
})
101+
102+
test("OPENCODE_DISABLE_EXTERNAL_SKILLS=1 blocks .agents but not .claude", async () => {
103+
delete process.env.OPENCODE_DISABLE_CLAUDE_CODE
104+
delete process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS
105+
process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS = "1"
106+
107+
await using tmp = await tmpdir({
108+
git: true,
109+
init: async (dir) => {
110+
await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill")
111+
await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill")
112+
},
113+
})
114+
115+
process.env.OPENCODE_TEST_HOME = tmp.path
116+
117+
await Instance.provide({
118+
directory: tmp.path,
119+
fn: async () => {
120+
const skills = await Skill.all()
121+
const names = skills.map((s) => s.name)
122+
// .claude skills still load
123+
expect(names).toContain("claude-skill")
124+
// .agents skills blocked
125+
expect(names).not.toContain("agents-skill")
126+
},
127+
})
128+
})
129+
130+
test("both flags set blocks both directories", async () => {
131+
delete process.env.OPENCODE_DISABLE_CLAUDE_CODE
132+
process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = "1"
133+
process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS = "1"
134+
135+
await using tmp = await tmpdir({
136+
git: true,
137+
init: async (dir) => {
138+
await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill")
139+
await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill")
140+
},
141+
})
142+
143+
process.env.OPENCODE_TEST_HOME = tmp.path
144+
145+
await Instance.provide({
146+
directory: tmp.path,
147+
fn: async () => {
148+
const skills = await Skill.all()
149+
const names = skills.map((s) => s.name)
150+
expect(names).not.toContain("claude-skill")
151+
expect(names).not.toContain("agents-skill")
152+
},
153+
})
154+
})
155+
156+
test(".opencode skills always load regardless of disable flags", async () => {
157+
process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = "1"
158+
process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS = "1"
159+
160+
await using tmp = await tmpdir({
161+
git: true,
162+
init: async (dir) => {
163+
await writeSkill(path.join(dir, ".opencode", "skill", "opencode-skill"), "opencode-skill")
164+
},
165+
})
166+
167+
process.env.OPENCODE_TEST_HOME = tmp.path
168+
169+
await Instance.provide({
170+
directory: tmp.path,
171+
fn: async () => {
172+
const skills = await Skill.all()
173+
const names = skills.map((s) => s.name)
174+
// .opencode skills are never blocked by these flags
175+
expect(names).toContain("opencode-skill")
176+
},
177+
})
178+
})
179+
})

0 commit comments

Comments
 (0)