@devries-cameron20 / t3code Mirror · read-only / commits / 26a88af5cb
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 23:15 UTC

fix(server): Claude no longer refuses earlier skills the user invoked in a prompt (#19485)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

(CJ) Chukwudi Nwobodo committed Oct 20, 2026 at 06:01 UTC 26a88af5cb0e8732d2bffe19b40816cf8e2ab345
5 files changed +145 -31
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+77
@@ -2715,6 +2715,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2715 event.type === "turn.terminal",
2716 );
2717 return {
2718 + attachmentsDir,
2719 runtime,
2720 providerThread,
2721 threadId,
@@ -2890,6 +2891,82 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2891 );
2892 });
2893
2894 + it.effect(
2895 + "carries earlier user-only skill instructions on sends and steering with attachments",
2896 + () =>
2897 + Effect.gen(function* () {
2898 + const fs = yield* FileSystem.FileSystem;
2899 + const path = yield* Path.Path;
2900 + const homePath = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skill-dispatch-" });
2901 + for (const [name, userOnly] of [
2902 + ["interrogate", true],
2903 + ["implement", true],
2904 + ["review", false],
2905 + ] as const) {
2906 + const directory = path.join(homePath, "skills", name);
2907 + yield* fs.makeDirectory(directory, { recursive: true });
2908 + yield* fs.writeFileString(
2909 + path.join(directory, "SKILL.md"),
2910 + `---\nname: ${name}\ndisable-model-invocation: ${userOnly}\n---\nFollow the ${name} instructions.\n`,
2911 + );
2912 + }
2913 + const harness = yield* makeWakeHarnessWithOptions({
2914 + settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath },
2915 + });
2916 + const input = makeClaudeTestTurnInput({
2917 + threadId: harness.threadId,
2918 + providerThread: harness.providerThread,
2919 + now: yield* DateTime.now,
2920 + attemptId: RunAttemptId.make("skill-dispatch"),
2921 + text: "$interrogate then $review then $implement the fixes",
2922 + attachments: [],
2923 + runtimePolicy: { ...CLAUDE_TEST_RUNTIME_POLICY, cwd: homePath },
2924 + });
2925 + yield* harness.runtime.startTurn(input);
2926 +
2927 + const leadingText = `Ultrathink:\n/interrogate [The user invoked this skill. Follow the instructions at: ${path.join(homePath, "skills", "interrogate", "SKILL.md")}] then /review then /implement the fixes`;
2928 + assert.deepEqual(harness.offeredMessages[0]?.message.content, [
2929 + { type: "text", text: leadingText },
2930 + { type: "text", text: "/implement the fixes" },
2931 + ]);
2932 +
2933 + const attachment = ChatFileAttachment.make({
2934 + type: "file",
2935 + id: ChatAttachmentId.make("skill-dispatch-12345678-1234-1234-1234-123456789abc"),
2936 + name: "requirements.pdf",
2937 + mimeType: "application/pdf",
2938 + sizeBytes: 4,
2939 + });
2940 + const idAllocator = yield* IdAllocator.IdAllocatorV2;
2941 + yield* harness.runtime.steerTurn({
2942 + threadId: harness.threadId,
2943 + runId: input.runId,
2944 + providerThread: harness.providerThread,
2945 + providerTurnId: idAllocator.derive.providerTurn({
2946 + driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
2947 + nativeTurnId: `turn:${input.attemptId}`,
2948 + }),
2949 + message: {
2950 + createdBy: "user",
2951 + creationSource: "web",
2952 + messageId: MessageId.make("skill-dispatch-steer"),
2953 + text: input.message.text,
2954 + attachments: [attachment],
2955 + },
2956 + });
2957 + const attachmentNote = `\n\n[Attached file "requirements.pdf" is saved at: ${path.join(harness.attachmentsDir, attachmentRelativePath(attachment)!)}]`;
2958 + assert.equal(harness.offeredMessages[1]?.priority, "now");
2959 + assert.deepEqual(harness.offeredMessages[1]?.message.content, [
2960 + { type: "text", text: `${leadingText}${attachmentNote}` },
2961 + { type: "text", text: `/implement the fixes${attachmentNote}` },
2962 + ]);
2963 + }).pipe(
2964 + Effect.provide(
2965 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
2966 + ),
2967 + ),
2968 + );
2969 +
2970 it.effect.each([
2971 { isError: false, title: "Check weather" },
2972 { isError: true, title: "Check weather" },
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+15 -14
@@ -116,7 +116,10 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
116
117 import { resolveAttachmentPath } from "../../attachmentStore.ts";
118 import { resolveClaudeSdkExecutablePath } from "../../provider/Drivers/ClaudeExecutable.ts";
119 -import { planClaudeSkillDispatch } from "../../provider/Drivers/ClaudeSkillDispatch.ts";
119 +import {
120 + planClaudeSkillDispatch,
121 + type ClaudeSkillTarget,
122 +} from "../../provider/Drivers/ClaudeSkillDispatch.ts";
123 import { discoverClaudeSkills } from "../../provider/Drivers/ClaudeSkills.ts";
124 import {
125 compileClaudeModelSelection,
@@ -1676,7 +1679,7 @@ function isSupportedClaudeImageMimeType(
1679 export function makeClaudeUserMessage(input: {
1680 readonly text: string;
1681 readonly priority?: SDKUserMessage["priority"];
1679 - readonly skillNames?: ReadonlySet<string>;
1682 + readonly skills?: ReadonlyMap<string, ClaudeSkillTarget>;
1683 readonly uuid?: SDKUserMessage["uuid"];
1684 }): SDKUserMessage {
1685 // Claude Code expands a skill only from the LAST text block, and only when
@@ -1685,9 +1688,7 @@ export function makeClaudeUserMessage(input: {
1688 // it natively and the model still reads the full request. See
1689 // ClaudeSkillDispatch.
1690 const dispatch =
1688 - input.skillNames === undefined
1689 - ? undefined
1690 - : planClaudeSkillDispatch(input.text, input.skillNames);
1691 + input.skills === undefined ? undefined : planClaudeSkillDispatch(input.text, input.skills);
1692 return {
1693 type: "user",
1694 message: {
@@ -1714,12 +1715,12 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
1715 readonly uuid?: SDKUserMessage["uuid"];
1716 readonly attachmentsDir: string;
1717 readonly fileSystem: FileSystem.FileSystem;
1717 - readonly skillNames?: ReadonlySet<string>;
1718 + readonly skills?: ReadonlyMap<string, ClaudeSkillTarget>;
1719 }) {
1720 if (input.attachments.length === 0) {
1721 return makeClaudeUserMessage({
1722 text: input.text,
1722 - ...(input.skillNames === undefined ? {} : { skillNames: input.skillNames }),
1723 + ...(input.skills === undefined ? {} : { skills: input.skills }),
1724 ...(input.priority === undefined ? {} : { priority: input.priority }),
1725 ...(input.uuid === undefined ? {} : { uuid: input.uuid }),
1726 });
@@ -1733,9 +1734,9 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
1734 });
1735
1736 const dispatch =
1736 - input.skillNames === undefined
1737 + input.skills === undefined
1738 ? undefined
1738 - : planClaudeSkillDispatch(textWithAttachmentPaths, input.skillNames);
1739 + : planClaudeSkillDispatch(textWithAttachmentPaths, input.skills);
1740 const content: Array<ClaudeUserContentBlock> = [];
1741 if (dispatch?.leadingText !== undefined) {
1742 content.push({ type: "text", text: dispatch.leadingText });
@@ -3650,7 +3651,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
3651 offer: () => Effect.void,
3652 };
3653
3653 - const userInvocableSkillNames = (cwd: string | null) =>
3654 + const userInvocableSkills = (cwd: string | null) =>
3655 discoverClaudeSkills(
3656 adapterOptions.settings,
3657 cwd ?? undefined,
@@ -3658,10 +3659,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
3659 ).pipe(
3660 Effect.map(
3661 (skills) =>
3661 - new Set(
3662 + new Map(
3663 skills
3664 .filter((skill) => skill.enabled && skill.userInvocable !== false)
3664 - .map((skill) => skill.name),
3665 + .map((skill) => [skill.name, skill]),
3666 ),
3667 ),
3668 Effect.provideService(FileSystem.FileSystem, fileSystem),
@@ -9105,7 +9106,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9106 attachments: turnInput.message.attachments,
9107 attachmentsDir,
9108 fileSystem,
9108 - skillNames: yield* userInvocableSkillNames(turnInput.runtimePolicy.cwd),
9109 + skills: yield* userInvocableSkills(turnInput.runtimePolicy.cwd),
9110 uuid: promptUuid,
9111 });
9112 const querySession = yield* openQuery(turnInput, nativeThreadId);
@@ -9410,7 +9411,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9411 priority: "now",
9412 attachmentsDir,
9413 fileSystem,
9413 - skillNames: yield* userInvocableSkillNames(currentTurn.input.runtimePolicy.cwd),
9414 + skills: yield* userInvocableSkills(currentTurn.input.runtimePolicy.cwd),
9415 });
9416 yield* backgroundForegroundSubagents(existing);
9417 // The turn can end while the moves are answered. A steer offered
apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts
+25 -3
@@ -1,8 +1,13 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";
3 +import { planClaudeSkillDispatch, type ClaudeSkillTarget } from "./ClaudeSkillDispatch.ts";
4
5 -const SKILLS = new Set(["2spec", "implement", "review", "re-release-version"]);
5 +const skillPath = (name: string) => `/home/me/.claude/skills/${name}/SKILL.md`;
6 +
7 +const skillMap = (names: Iterable<string>) =>
8 + new Map<string, ClaudeSkillTarget>([...names].map((name) => [name, { path: skillPath(name) }]));
9 +
10 +const SKILLS = skillMap(["2spec", "implement", "review", "re-release-version"]);
11
12 describe("planClaudeSkillDispatch", () => {
13 it("leaves a prompt without a known skill untouched", () => {
@@ -68,7 +73,7 @@ describe("planClaudeSkillDispatch", () => {
73 });
74
75 it("ignores currency amounts and compact monetary expressions", () => {
71 - const skillsWithCurrency = new Set([...SKILLS, "20", "20k", "100M", "1e6"]);
76 + const skillsWithCurrency = skillMap([...SKILLS.keys(), "20", "20k", "100M", "1e6"]);
77 for (const symbol of ["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
78 expect(
79 planClaudeSkillDispatch(
@@ -78,4 +83,21 @@ describe("planClaudeSkillDispatch", () => {
83 ).toBeUndefined();
84 }
85 });
86 +
87 + it("bounds notes for repeated user-only skills and leaves the native dispatch unannotated", () => {
88 + const skills = new Map([
89 + ["interrogate", { path: skillPath("interrogate"), userInvocationOnly: true }],
90 + ["implement", { path: skillPath("implement"), userInvocationOnly: true }],
91 + ]);
92 + expect(
93 + planClaudeSkillDispatch(
94 + "$interrogate then $interrogate then $implement and $implement the fixes",
95 + skills,
96 + ),
97 + ).toEqual({
98 + leadingText: `/interrogate [The user invoked this skill. Follow the instructions at: ${skillPath("interrogate")}] then /interrogate then /implement and /implement the fixes`,
99 + commandText: "/implement the fixes",
100 + skillName: "implement",
101 + });
102 + });
103 });
apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts
+24 -13
@@ -1,9 +1,11 @@
1 +import type { ServerProviderSkill } from "@t3tools/contracts";
2 +
3 /**
4 * Claude Code's only user-side invocation is a text block whose first character
5 * is `/`: the harness expands `/name args` into the SKILL.md body, and every
6 * character after the name (newlines included) arrives as `ARGUMENTS`. Only one
7 * skill expands per message; a second `/x` becomes argument text
6 - * (anthropics/claude-code#87113).
8 + * ([#87113](https://github.com/anthropics/claude-code/issues/87113)).
9 */
10
11 /**
@@ -14,6 +16,8 @@
16 const SKILL_MENTION_PATTERN =
17 /(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/gu;
18
19 +export type ClaudeSkillTarget = Pick<ServerProviderSkill, "path" | "userInvocationOnly">;
20 +
21 export interface ClaudeSkillDispatch {
22 /** The whole prompt with mentions as `/name`, or `undefined` when the mention opens it. */
23 readonly leadingText: string | undefined;
@@ -24,32 +28,39 @@ export interface ClaudeSkillDispatch {
28
29 export function planClaudeSkillDispatch(
30 prompt: string,
27 - skillNames: ReadonlySet<string>,
31 + skills: ReadonlyMap<string, ClaudeSkillTarget>,
32 ): ClaudeSkillDispatch | undefined {
33 const mentions = [...prompt.matchAll(SKILL_MENTION_PATTERN)].flatMap((match) => {
34 const name = match[2] ?? "";
31 - if (!skillNames.has(name)) return [];
35 + const skill = skills.get(name);
36 + if (!skill) return [];
37 const start = (match.index ?? 0) + (match[1]?.length ?? 0);
33 - return [{ name, start, end: (match.index ?? 0) + match[0].length }];
38 + return [{ name, skill, start, end: (match.index ?? 0) + match[0].length }];
39 });
40 const last = mentions.at(-1);
41 if (!last) {
42 return undefined;
43 }
44
40 - const trailing = prompt.slice(last.end);
41 - const promptWithInlineSlashes = mentions
42 - .reduceRight(
43 - (text, mention) =>
44 - `${text.slice(0, mention.start)}/${mention.name}${text.slice(mention.end)}`,
45 - prompt,
46 - )
47 - .trimEnd();
45 + // Only the final skill gets native expansion. Earlier user-only skills need
46 + // a fallback to their raw file because Claude's Skill tool refuses them.
47 + const annotated = new Set([last.name]);
48 + let promptWithInlineSlashes = "";
49 + let cursor = 0;
50 + for (const mention of mentions) {
51 + promptWithInlineSlashes += `${prompt.slice(cursor, mention.start)}/${mention.name}`;
52 + if (mention.skill.userInvocationOnly === true && !annotated.has(mention.name)) {
53 + promptWithInlineSlashes += ` [The user invoked this skill. Follow the instructions at: ${mention.skill.path}]`;
54 + annotated.add(mention.name);
55 + }
56 + cursor = mention.end;
57 + }
58 + promptWithInlineSlashes = `${promptWithInlineSlashes}${prompt.slice(cursor)}`.trimEnd();
59
60 return {
61 leadingText:
62 prompt.slice(0, last.start).trim().length > 0 ? promptWithInlineSlashes : undefined,
52 - commandText: `/${last.name}${trailing}`.trimEnd(),
63 + commandText: `/${last.name}${prompt.slice(last.end)}`.trimEnd(),
64 skillName: last.name,
65 };
66 }
apps/server/src/provider/Drivers/ClaudeSkills.test.ts
+4 -1
@@ -106,7 +106,10 @@ it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
106 const settings = { homePath: configDir, launchArgs: `--add-dir "${extraDir}"` };
107 const skills = yield* discoverClaudeSkills(settings, workspace);
108 assert.deepEqual(
109 - planClaudeSkillDispatch("$demo", new Set(skills.map((skill) => skill.name))),
109 + planClaudeSkillDispatch(
110 + "$demo",
111 + new Map(skills.map((skill) => [skill.name, { path: skill.path }])),
112 + ),
113 {
114 leadingText: undefined,
115 commandText: "/demo",