The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Claude no longer dispatches skill mentions from handoff history (#34497)
Julius Marminge committed
Nov 13, 2026 at 08:52 UTC
139ec8080f37781bf4576f63186022b0a8472b71
5 files changed
+81
-12
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+50
@@ -109,6 +109,7 @@ import * as ClaudeAdapterV2 from "./ClaudeAdapterV2.ts";
109
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
110
import * as ProviderInstallationGate from "../../provider/ProviderInstallationGate.ts";
111
import { ClaudeOrchestratorReplayHarness } from "./ClaudeAdapterV2.testkit.ts";
112
+import { withInlineContext } from "../ContextHandoffDelivery.ts";
113
import { provideDeterministicTestRuntime } from "../testkit/DeterministicRuntime.ts";
114
import { runOrchestratorV2Scenario } from "../testkit/OrchestratorScenario.ts";
115
import { layerProviderReplay } from "../testkit/ProviderReplayHarness.ts";
@@ -5483,6 +5484,55 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5484
),
5485
);
5486
5487
+ // regression: #34393 a provider switch replayed a $skill from the handoff history
5488
+ it.effect("dispatches only skills from the user's text, not from inline handoff history", () =>
5489
+ Effect.gen(function* () {
5490
+ const fs = yield* FileSystem.FileSystem;
5491
+ const path = yield* Path.Path;
5492
+ const homePath = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skill-handoff-" });
5493
+ const directory = path.join(homePath, "skills", "review");
5494
+ yield* fs.makeDirectory(directory, { recursive: true });
5495
+ yield* fs.writeFileString(
5496
+ path.join(directory, "SKILL.md"),
5497
+ "---\nname: review\n---\nFollow the review instructions.\n",
5498
+ );
5499
+ const harness = yield* makeWakeHarnessWithOptions({
5500
+ settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath },
5501
+ });
5502
+ const history = "Context handoff:\n[Historical user; user_message]\n$review the diff";
5503
+ const text = withInlineContext(history, "continue");
5504
+ yield* harness.runtime.startTurn({
5505
+ ...makeClaudeTestTurnInput({
5506
+ threadId: harness.threadId,
5507
+ providerThread: harness.providerThread,
5508
+ now: yield* DateTime.now,
5509
+ attemptId: RunAttemptId.make("skill-handoff"),
5510
+ text,
5511
+ attachments: [],
5512
+ runtimePolicy: { ...CLAUDE_TEST_RUNTIME_POLICY, cwd: homePath },
5513
+ }),
5514
+ inlineContextLength: text.length - "continue".length,
5515
+ });
5516
+
5517
+ const content = harness.offeredMessages[0]?.message.content;
5518
+ const blocks =
5519
+ typeof content === "string"
5520
+ ? [content]
5521
+ : (content ?? []).map((block) => (block.type === "text" ? block.text : ""));
5522
+ assert.isFalse(blocks.some((text) => text.startsWith("/review")));
5523
+ assert.include(blocks.join("\n"), "$review the diff");
5524
+ }).pipe(
5525
+ Effect.provide(
5526
+ Layer.mergeAll(
5527
+ IdAllocator.layer,
5528
+ McpProviderSessions.layer,
5529
+ NodeServices.layer,
5530
+ NodeCrypto.layer,
5531
+ ),
5532
+ ),
5533
+ ),
5534
+ );
5535
+
5536
// regression: #15475 MCP title arriving after the tool starts must survive to completion
5537
it.effect.each([
5538
{ isError: false, title: "Check weather" },
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+23
-7
@@ -2631,12 +2631,15 @@ export function makeClaudeUserMessage(input: {
2631
readonly text: string;
2632
readonly priority?: SDKUserMessage["priority"];
2633
readonly skills?: ReadonlyMap<string, ClaudeSkillTarget>;
2634
+ readonly skillMentionsFrom?: number;
2635
readonly uuid?: SDKUserMessage["uuid"];
2636
}): SDKUserMessage {
2637
// Claude expands a skill only when `/name` starts the last text block.
2638
// Keep the whole request before that block; see ClaudeSkillDispatch.
2639
const dispatch =
2639
- input.skills === undefined ? undefined : planClaudeSkillDispatch(input.text, input.skills);
2640
+ input.skills === undefined
2641
+ ? undefined
2642
+ : planClaudeSkillDispatch(input.text, input.skills, input.skillMentionsFrom);
2643
// Claude runs `/goal` only when it opens the prompt, so a goal stays one block.
2644
const isGoalCommand = parseGoalCommand({ text: input.text }) !== null;
2645
return {
@@ -2801,11 +2804,15 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
2804
readonly fileSystem: FileSystem.FileSystem;
2805
readonly pdfReservation: Effect.Success<ReturnType<typeof reserveClaudePdfBudget>>;
2806
readonly skills?: ReadonlyMap<string, ClaudeSkillTarget>;
2807
+ readonly skillMentionsFrom?: number;
2808
}) {
2809
if (input.attachments.length === 0) {
2810
const message = makeClaudeUserMessage({
2811
text: input.text,
2812
...(input.skills === undefined ? {} : { skills: input.skills }),
2813
+ ...(input.skillMentionsFrom === undefined
2814
+ ? {}
2815
+ : { skillMentionsFrom: input.skillMentionsFrom }),
2816
...(input.priority === undefined ? {} : { priority: input.priority }),
2817
...(input.uuid === undefined ? {} : { uuid: input.uuid }),
2818
});
@@ -2829,7 +2836,7 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
2836
const dispatch =
2837
input.skills === undefined
2838
? undefined
2832
- : planClaudeSkillDispatch(textWithAttachmentPaths, input.skills);
2839
+ : planClaudeSkillDispatch(textWithAttachmentPaths, input.skills, input.skillMentionsFrom);
2840
const content: Array<ClaudeUserContentBlock> = [];
2841
// Base64 adds a third to the payload. Leave room below Anthropic's 32 MB
2842
// request limit for text, instructions, and SDK framing. The SDK does not
@@ -12422,15 +12429,24 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12429
pdfBudgets.get(nativeThreadId)!,
12430
persistAttachmentBudget(nativeThreadId),
12431
);
12432
+ const promptText = applyClaudePromptEffortPrefix(
12433
+ turnInput.message.text,
12434
+ compileClaudeModelSelection(turnInput.modelSelection, modelCatalog).promptEffort,
12435
+ );
12436
const userMessage =
12437
promptUuid === null
12438
? null
12439
: yield* makeClaudeUserMessageWithAttachments({
12429
- text: applyClaudePromptEffortPrefix(
12430
- turnInput.message.text,
12431
- compileClaudeModelSelection(turnInput.modelSelection, modelCatalog)
12432
- .promptEffort,
12433
- ),
12440
+ text: promptText,
12441
+ // Mentions in inline handoff history are history, not this turn's skill.
12442
+ ...(turnInput.inlineContextLength === undefined
12443
+ ? {}
12444
+ : {
12445
+ skillMentionsFrom:
12446
+ promptText.length -
12447
+ turnInput.message.text.slice(turnInput.inlineContextLength).trimEnd()
12448
+ .length,
12449
+ }),
12450
attachments: turnInput.message.attachments,
12451
attachmentsDir,
12452
fileSystem,
apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+3
-4
@@ -1639,12 +1639,11 @@ export const layer: Layer.Layer<
1639
.filter((part) => part !== "")
1640
.join("\n\n");
1641
const { restartContinuationOfRunId: _resumedRunId, ...promptedInput } = turnInput;
1642
+ const text = goalCommand ? userText : withInlineContext(context, userText);
1643
yield* start({
1644
...(noteContinuation ? promptedInput : turnInput),
1644
- message: {
1645
- ...turnInput.message,
1646
- text: goalCommand ? userText : withInlineContext(context, userText),
1647
- },
1645
+ message: { ...turnInput.message, text },
1646
+ ...(text === userText ? {} : { inlineContextLength: text.length - userText.length }),
1647
}).pipe(
1648
// Clear pending handoff markers for refused prompts so the next turn retains the native session.
1649
Effect.tapError((error) =>
apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts
+3
-1
@@ -22,12 +22,14 @@ export interface ClaudeSkillDispatch {
22
export function planClaudeSkillDispatch(
23
prompt: string,
24
skills: ReadonlyMap<string, ClaudeSkillTarget>,
25
+ /** Mentions before this offset, such as inline handoff history, stay plain text. */
26
+ mentionsFrom = 0,
27
): ClaudeSkillDispatch | undefined {
28
const mentions = [...prompt.matchAll(SKILL_MENTION_PATTERN)].flatMap((match) => {
29
const name = match[2] ?? "";
30
const skill = skills.get(name);
29
- if (!skill) return [];
31
const start = (match.index ?? 0) + (match[1]?.length ?? 0);
32
+ if (!skill || start < mentionsFrom) return [];
33
return [{ name, skill, start, end: (match.index ?? 0) + match[0].length }];
34
});
35
const last = mentions.at(-1);
packages/provider-core/src/server/ProviderAdapter.ts
+2
@@ -535,6 +535,8 @@ export interface ProviderAdapterV2TurnInput {
535
readonly rootNodeId: NodeId;
536
readonly providerThread: OrchestrationV2ProviderThread;
537
readonly message: ProviderAdapterV2TurnMessage;
538
+ /** Leading characters of `message.text` that are inline handoff context, not the user's words. */
539
+ readonly inlineContextLength?: number;
540
readonly modelSelection: ModelSelection;
541
readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
542
readonly appContext?: ReadonlyArray<{ readonly key: string; readonly text: string }>;