Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a Claude agent stops when the server that started it dies #23389

Mergedshivamhwp(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/23389/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHub

Showing 2 changed files with 64 additions and 10 deletions.

x
0 of 2 viewed, 2 left
24 additions and 9 deletionsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsModified
View file
@@ -314,26 +314,41 @@
// subagents to move to the background before it is sent.
const BACKGROUND_MOVE_TIMEOUT_MS = 5_000;
​
+const CLAUDE_GROUP_WATCH_SCRIPT = [
+ "{ trap '' TERM; read -r _ <&3; kill -TERM 0; sleep 5; kill -KILL 0; } </dev/null >/dev/null 2>&1 &",
+ 'exec "$@" 3<&-',
+].join("\n");
+​
/**
* When the CLI exits it stops the MCP servers it started, but not their children: a plugin's
* `bun run start` wrapper dies and its `bun server.ts` keeps running, writing to a pipe nobody
* reads (#3089). Those stay in the CLI's group, so the rest of the group gets SIGKILL once the
* CLI exits for any reason.
+ *
+ * That cleanup needs this server alive, and the CLI finishes its turn after its pipes close. A
+ * server that crashes or is killed would leave the CLI working next to the session it resumes
+ * (#23370), so a watcher in the group reads a pipe only this server holds and stops the group at
+ * its end-of-file.
-function spawnClaudeProcessGroup(options: ClaudeSpawnOptions): ClaudeSpawnedProcess {
- const child = NodeChildProcess.spawn(options.command, options.args, {
- cwd: options.cwd,
- env: options.env,
- signal: options.signal,
- stdio: ["pipe", "pipe", "ignore"],
- detached: true,
- });
+export function spawnClaudeProcessGroup(options: ClaudeSpawnOptions): ClaudeSpawnedProcess {
+ const child = NodeChildProcess.spawn(