Skip to content

Commit ff599f0

Browse files
fix(server): Claude subagent results drop Claude Code's tools-used note (pingdotgg#34821)
1 parent 3bd7b04 commit ff599f0

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18160,7 +18160,26 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1816018160
),
1816118161
);
1816218162

18163-
it.effect("extracts text from direct content-block subagent results", () =>
18163+
it.effect.each([
18164+
{
18165+
label: "extracts text from direct content-block subagent results",
18166+
content: [
18167+
{ type: "text", text: "First line." },
18168+
{ type: "text", text: "Second line." },
18169+
],
18170+
expected: "First line.\nSecond line.",
18171+
},
18172+
{
18173+
label: "drops Claude Code's tools-used note from a subagent result",
18174+
content: [
18175+
{
18176+
type: "text",
18177+
text: "<tools-used-before-summary>Read</tools-used-before-summary>\n\nadd (line 1)\nmean (line 6)",
18178+
},
18179+
],
18180+
expected: "add (line 1)\nmean (line 6)",
18181+
},
18182+
])("$label", ({ content, expected }) =>
1816418183
Effect.scoped(
1816518184
Effect.gen(function* () {
1816618185
const SUBAGENT_TASK_ID = "task-direct-content-blocks";
@@ -18214,10 +18233,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1821418233
{
1821518234
type: "tool_result",
1821618235
tool_use_id: SUBAGENT_TOOL_USE_ID,
18217-
content: [
18218-
{ type: "text", text: "First line." },
18219-
{ type: "text", text: "Second line." },
18220-
],
18236+
content,
1822118237
},
1822218238
],
1822318239
},
@@ -18228,7 +18244,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1822818244
);
1822918245
yield* harness.until(() => subagentEvents().at(-1)?.subagent.status === "completed");
1823018246

18231-
assert.equal(subagentEvents().at(-1)?.subagent.result, "First line.\nSecond line.");
18247+
assert.equal(subagentEvents().at(-1)?.subagent.result, expected);
1823218248

1823318249
yield* Queue.offer(
1823418250
harness.sdkMessages,

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,7 +3593,15 @@ function claudeCommandOutputText(output: ClaudeNativeToolOutput): string {
35933593
return claudeNativeToolOutputText(output);
35943594
}
35953595

3596+
// Claude Code prefixes foreground Agent results with a note for the parent model, not the report.
3597+
const CLAUDE_TOOLS_USED_NOTE =
3598+
/^\s*<tools-used-before-summary>[^<]*<\/tools-used-before-summary>\s*/;
3599+
35963600
function claudeSubagentResultText(output: ClaudeNativeToolOutput): string {
3601+
return claudeSubagentRawResultText(output).replace(CLAUDE_TOOLS_USED_NOTE, "");
3602+
}
3603+
3604+
function claudeSubagentRawResultText(output: ClaudeNativeToolOutput): string {
35973605
const value = claudeNativeToolOutputValue(output);
35983606
const content = Array.isArray(value)
35993607
? value

0 commit comments

Comments
 (0)