The best way to control Claude Code, Codex and more from any computer or phone
fix(server): OpenCode no longer drops a $skill read before its directory scan ends (#29535)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 2, 2026 at 18:50 UTC
78aee8a6706e14eeebde743e2a452fdec3a0493f
2 files changed
+95
-18
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+70
@@ -2298,6 +2298,76 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2298
}).pipe(Effect.scoped),
2299
);
2300
2301
+ it.effect("sends a $skill that appears once OpenCode finishes scanning the directory", () =>
2302
+ Effect.gen(function* () {
2303
+ const prompts: Array<unknown> = [];
2304
+ const greet = {
2305
+ id: "greet",
2306
+ name: "greet",
2307
+ path: `${WORK}/.opencode/skills/greet/SKILL.md`,
2308
+ content: "Say hello.",
2309
+ };
2310
+ const { runtime, thread } = yield* resumed(
2311
+ [
2312
+ out("skill.list", { "location[directory]": WORK }),
2313
+ reply("skill.list", { location: { directory: WORK }, data: [] }),
2314
+ // OpenCode answers the model list only once the directory scan has ended.
2315
+ ...directoryModels(WORK),
2316
+ out("skill.list", { "location[directory]": WORK }),
2317
+ reply("skill.list", { location: { directory: WORK }, data: [greet] }),
2318
+ out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2319
+ promptAccepted,
2320
+ event("session.execution.succeeded", { sessionID: SESSION }),
2321
+ ],
2322
+ { onPrompt: (input) => prompts.push(input) },
2323
+ );
2324
+ const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
2325
+ const started = yield* runtime
2326
+ .startTurn({
2327
+ ...turnInput(thread),
2328
+ message: { ...turnInput(thread).message, text: "$greet again please" },
2329
+ })
2330
+ .pipe(Effect.exit);
2331
+ assert.deepInclude(prompts[0], { skills: [{ id: "greet" }] });
2332
+ assert.isTrue(Exit.isSuccess(started));
2333
+ assert.equal((yield* Fiber.join(terminal))?.status, "completed");
2334
+ }).pipe(Effect.scoped),
2335
+ );
2336
+
2337
+ it.effect(
2338
+ "keeps a $skill found on the first read when the reread after the scan comes back empty",
2339
+ () =>
2340
+ Effect.gen(function* () {
2341
+ const prompts: Array<unknown> = [];
2342
+ const greet = {
2343
+ id: "greet",
2344
+ name: "greet",
2345
+ path: `${WORK}/.opencode/skills/greet/SKILL.md`,
2346
+ content: "Say hello.",
2347
+ };
2348
+ const { runtime, thread } = yield* resumed(
2349
+ [
2350
+ out("skill.list", { "location[directory]": WORK }),
2351
+ reply("skill.list", { location: { directory: WORK }, data: [greet] }),
2352
+ ...directoryModels(WORK),
2353
+ out("skill.list", { "location[directory]": WORK }),
2354
+ reply("skill.list", { location: { directory: WORK }, data: [] }),
2355
+ out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2356
+ promptAccepted,
2357
+ event("session.execution.succeeded", { sessionID: SESSION }),
2358
+ ],
2359
+ { onPrompt: (input) => prompts.push(input) },
2360
+ );
2361
+ const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
2362
+ yield* runtime.startTurn({
2363
+ ...turnInput(thread),
2364
+ message: { ...turnInput(thread).message, text: "$greet then echo $HOME" },
2365
+ });
2366
+ assert.equal((yield* Fiber.join(terminal))?.status, "completed");
2367
+ assert.deepInclude(prompts[0], { skills: [{ id: "greet" }] });
2368
+ }).pipe(Effect.scoped),
2369
+ );
2370
+
2371
it.effect("keeps a turn still running after a reconnect open for its next events", () =>
2372
Effect.gen(function* () {
2373
const { runtime, thread } = yield* resumed([
packages/provider-opencode/src/server/v2/adapter.ts
+25
-18
@@ -630,14 +630,8 @@ const commandOf = (text: string) => {
630
return match === null ? undefined : { name: match[1]!, text: match[2] ?? "" };
631
};
632
633
-const SKILL_MENTION = new RegExp(SKILL_MENTION_PATTERN.source, "u");
634
-
635
-const skillsNamed = (text: string, known: ReadonlySet<string>) => [
636
- ...new Set(
637
- [...text.matchAll(SKILL_MENTION_PATTERN)].flatMap((match) =>
638
- known.has(match[2] ?? "") ? [match[2]!] : [],
639
- ),
640
- ),
633
+const skillMentions = (text: string) => [
634
+ ...new Set([...text.matchAll(SKILL_MENTION_PATTERN)].flatMap((match) => match[2] ?? [])),
635
];
636
637
const turnTokenUsage = (turn: ActiveTurn, status: OrchestrationV2ProviderTurn["status"]) => {
@@ -3322,6 +3316,27 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3316
yield* stopStrays(state);
3317
});
3318
3319
+ const listSkills = (location: { readonly directory: string }) =>
3320
+ client.skill.list({ location }).pipe(
3321
+ Effect.timeout(INVENTORY_TIMEOUT),
3322
+ Effect.map((list) => new Set<string>(list.data.map((skill) => skill.id))),
3323
+ Effect.orElseSucceed(() => new Set<string>()),
3324
+ );
3325
+
3326
+ // A directory OpenCode is still scanning lists none or some of its skills.
3327
+ // OpenCode 2.2.5 answers its model list only once the scan has ended (observed, not documented).
3328
+ const skillsMentioned = Effect.fnUntraced(function* (
3329
+ location: { readonly directory: string },
3330
+ mentions: ReadonlyArray<string>,
3331
+ ) {
3332
+ const known = yield* listSkills(location);
3333
+ if (mentions.some((name) => !known.has(name))) {
3334
+ yield* readModels(location.directory);
3335
+ for (const name of yield* listSkills(location)) known.add(name);
3336
+ }
3337
+ return mentions.filter((name) => known.has(name));
3338
+ });
3339
+
3340
const submit = Effect.fnUntraced(function* (
3341
sessionId: string,
3342
turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
@@ -3357,16 +3372,8 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3372
return yield* client.session.command({ sessionID, ...command });
3373
}
3374
}
3360
- const skills = SKILL_MENTION.test(text)
3361
- ? skillsNamed(
3362
- text,
3363
- yield* client.skill.list({ location }).pipe(
3364
- Effect.timeout(INVENTORY_TIMEOUT),
3365
- Effect.map((list) => new Set(list.data.map((skill) => skill.id))),
3366
- Effect.orElseSucceed(() => new Set<string>()),
3367
- ),
3368
- )
3369
- : [];
3375
+ const mentions = skillMentions(text);
3376
+ const skills = mentions.length === 0 ? [] : yield* skillsMentioned(location, mentions);
3377
const files = yield* promptFiles(turnInput.message.attachments);
3378
const messageText = yield* promptText(turnInput);
3379
if (!sending()) return;