Skip to content

Commit e88667d

Browse files
sunnyyi-macclaude
andcommitted
fix: clear CLAUDECODE env to prevent nested-session detection
When claude-agent-acp is spawned from within a Claude Code session (e.g. via acpx or other orchestrators), the parent process sets CLAUDECODE=1. This env var is inherited by the subprocess, causing Claude Code to detect a "nested session" and exit immediately. The result is a generic -32603 "Internal error" with details "Query closed before response received" on every session/new call. Fix: clear CLAUDECODE in the subprocess environment so the spawned Claude Code instance starts normally. Also improve error handling for session/new: the v0.20.0 fix for "Query closed before response received" only covered the loadSession path (resume). The same error on newSession was left unhandled, producing an opaque "Internal error". Now it returns a meaningful message suggesting to check Claude Code installation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c13edf3 commit e88667d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/acp-agent.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ export class ClaudeAcpAgent implements Agent {
12271227
...userProvidedOptions,
12281228
env: {
12291229
...process.env,
1230+
CLAUDECODE: "", // Prevent nested-session detection when spawned from within Claude Code
12301231
...userProvidedOptions?.env,
12311232
...createEnvForGateway(this.gatewayAuthMeta),
12321233
},
@@ -1303,11 +1304,19 @@ export class ClaudeAcpAgent implements Agent {
13031304
initializationResult = await q.initializationResult();
13041305
} catch (error) {
13051306
if (
1306-
creationOpts.resume &&
13071307
error instanceof Error &&
13081308
error.message === "Query closed before response received"
13091309
) {
1310-
throw RequestError.resourceNotFound(sessionId);
1310+
if (creationOpts.resume) {
1311+
throw RequestError.resourceNotFound(sessionId);
1312+
}
1313+
// For new sessions, provide a meaningful error instead of generic "Internal error"
1314+
throw RequestError.internalError(
1315+
undefined,
1316+
"Claude Code process exited before initialization completed. " +
1317+
"Ensure Claude Code is installed and accessible. " +
1318+
"You can set CLAUDE_CODE_EXECUTABLE to the path of the Claude CLI.",
1319+
);
13111320
}
13121321
throw error;
13131322
}

0 commit comments

Comments
 (0)