@devries-cameron20 / t3code-1 / commits / fa864bfca7
Fork 0

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

fix(server): Claude goals no longer re-prompt while a delegated task will wake the thread (#30646)

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

George Nijo committed Nov 14, 2026 at 18:50 UTC fa864bfca7286a93a6963e283e6f93123acb94f0
2 files changed +94 -2
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+73
@@ -23648,6 +23648,79 @@ describe("ClaudeAdapterV2 background wake turns", () => {
23648 ),
23649 );
23650
23651 + it.effect("ends a goal check without re-prompting while T3 work will wake the thread", () =>
23652 + Effect.gen(function* () {
23653 + const harness = yield* makeWakeHarness;
23654 + const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
23655 + yield* mcpSessions.set({
23656 + environmentId: EnvironmentId.make("environment-goal-wake"),
23657 + threadId: harness.threadId,
23658 + providerSessionId: "mcp-session-goal-wake",
23659 + providerInstanceId: ProviderInstanceId.make("claudeAgent"),
23660 + endpoint: "http://127.0.0.1:43123/mcp",
23661 + authorizationHeader: "Bearer secret-claude-token",
23662 + browserToolsAvailable: true,
23663 + hasPendingWake: Effect.succeed(true),
23664 + });
23665 + const stop = Effect.promise(() =>
23666 + Promise.all(
23667 + (harness.getOpenedOptions()?.hooks?.Stop ?? []).flatMap((matcher) =>
23668 + matcher.hooks.map((hook) =>
23669 + hook(
23670 + {
23671 + hook_event_name: "Stop",
23672 + stop_hook_active: true,
23673 + session_id: WAKE_NATIVE_SESSION,
23674 + transcript_path: "/transcript.jsonl",
23675 + cwd: "/workspace",
23676 + },
23677 + undefined,
23678 + { signal: new AbortController().signal },
23679 + ),
23680 + ),
23681 + ),
23682 + ),
23683 + );
23684 + const condition = "the delegated review is addressed";
23685 + yield* harness.runtime.startTurn(
23686 + makeClaudeTestTurnInput({
23687 + threadId: harness.threadId,
23688 + providerThread: harness.providerThread,
23689 + now: yield* DateTime.now,
23690 + attemptId: RunAttemptId.make("goal-wake-attempt"),
23691 + text: `/goal ${condition}`,
23692 + attachments: [],
23693 + }),
23694 + );
23695 + // Without a goal, Stop keeps Claude Code's own behavior.
23696 + assert.deepEqual(yield* stop, [{}]);
23697 + yield* harness.offerAndWait(syntheticFrame("goal-wake-set", `Goal set: ${condition}`));
23698 + assert.deepEqual(yield* stop, [{ continue: false }]);
23699 + // The turn ends without an error and the goal waits for the wake.
23700 + yield* Queue.offer(
23701 + harness.sdkMessages,
23702 + makeResultFrame({
23703 + uuid: "goal-wake-result",
23704 + result: "Waiting for the review.",
23705 + terminalReason: "stop_hook_prevented",
23706 + }),
23707 + );
23708 + const terminal = yield* Queue.take(harness.terminalReceipts);
23709 + assert.equal(terminal.status, "completed");
23710 + assert.equal(goalStatuses(harness.events).at(-1)?.status, "active");
23711 + }).pipe(
23712 + Effect.scoped,
23713 + Effect.provide(
23714 + Layer.mergeAll(
23715 + IdAllocator.layer,
23716 + McpProviderSessions.layer,
23717 + NodeServices.layer,
23718 + NodeCrypto.layer,
23719 + ),
23720 + ),
23721 + ),
23722 + );
23723 +
23724 it.effect(
23725 "defers goal completion until an ambient subagent finishes and Claude checks again",
23726 () =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+21 -2
@@ -2132,6 +2132,7 @@ export function makeClaudeQueryOptions(input: {
2132 readonly canUseTool?: CanUseTool;
2133 readonly onUserDialog?: ClaudeQueryOptions["onUserDialog"];
2134 readonly onElicitation?: ClaudeQueryOptions["onElicitation"];
2135 + readonly onStop?: HookCallback;
2136 readonly supportedDialogKinds?: ClaudeQueryOptions["supportedDialogKinds"];
2137 readonly allowDangerouslySkipPermissions?: boolean;
2138 readonly appendSystemPromptFileText?: string;
@@ -2284,8 +2285,15 @@ export function makeClaudeQueryOptions(input: {
2285 ...launchAppendSystemPrompt,
2286 ].join("\n\n"),
2287 },
2287 - ...(deviceInstructions
2288 - ? { hooks: { SubagentStart: [{ hooks: [subagentDeviceInstructions] }] } }
2288 + ...(deviceInstructions || input.onStop !== undefined
2289 + ? {
2290 + hooks: {
2291 + ...(deviceInstructions
2292 + ? { SubagentStart: [{ hooks: [subagentDeviceInstructions] }] }
2293 + : {}),
2294 + ...(input.onStop === undefined ? {} : { Stop: [{ hooks: [input.onStop] }] }),
2295 + },
2296 + }
2297 : {}),
2298 ...(Object.keys(extraArgs).length === 0 ? {} : { extraArgs }),
2299 };
@@ -12479,6 +12487,16 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12487 queryPolicy: Effect.Success<ReturnType<typeof queryPolicyForTurn>>,
12488 ) {
12489 const mcpSession = yield* mcpSessions.read(turnInput.threadId);
12490 + // Claude Code defers its goal Stop hook only for its own background tasks, so a goal
12491 + // re-prompts in a loop while T3 work that will wake this thread is still running.
12492 + const onStop: HookCallback = () =>
12493 + runPromise(
12494 + Effect.gen(function* () {
12495 + if (goalsByNativeThread.get(nativeThreadId)?.status !== "active") return {};
12496 + const pendingWake = (yield* mcpSessions.read(turnInput.threadId))?.hasPendingWake;
12497 + return pendingWake !== undefined && (yield* pendingWake) ? { continue: false } : {};
12498 + }),
12499 + );
12500 const mcpOverrides = claudeMcpQueryOverrides({
12501 mcpSession,
12502 readOnlySandbox:
@@ -12653,6 +12671,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12671 canUseTool,
12672 onUserDialog,
12673 onElicitation,
12674 + onStop,
12675 supportedDialogKinds: ["resume_return"],
12676 ...(appendSystemPromptFileText === undefined ? {} : { appendSystemPromptFileText }),
12677 ...(toolSearchOverride === undefined ? {} : { toolSearchOverride }),