Skip to content

Commit 7cc40d9

Browse files
committed
fix(claude-cli): hold live turn open while native background subagents and workflows run
1 parent 94f018c commit 7cc40d9

3 files changed

Lines changed: 588 additions & 9 deletions

File tree

‎src/agents/cli-output.ts‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,12 +1294,28 @@ export function createCliJsonlStreamingParser(params: {
12941294
usage,
12951295
});
12961296
if (result) {
1297-
// The terminal result can be empty after Claude already streamed text.
1298-
// Keep that delivered text; a genuinely empty turn still remains empty.
1299-
output =
1300-
result.text || result.errorText
1301-
? result
1302-
: { ...result, text: assistantText.trim() || texts.join("\n").trim() };
1297+
if (result.errorText) {
1298+
output = result;
1299+
return;
1300+
}
1301+
// Empty terminal result can follow already-streamed text; keep that text.
1302+
const nextText = (result.text || assistantText.trim() || texts.join("\n").trim()).trim();
1303+
const previousText = output?.text?.trim() ?? "";
1304+
// Claude Code may emit an interim result while background agents run, then
1305+
// a second result after task-notification. Preserve earlier result text
1306+
// when the later envelope does not already include it.
1307+
let text = nextText;
1308+
if (
1309+
previousText &&
1310+
nextText &&
1311+
previousText !== nextText &&
1312+
!nextText.startsWith(previousText)
1313+
) {
1314+
text = `${previousText}\n${nextText}`;
1315+
} else if (!nextText) {
1316+
text = previousText;
1317+
}
1318+
output = { ...result, text };
13031319
return;
13041320
}
13051321

0 commit comments

Comments
 (0)