fix: clear CLAUDECODE env to prevent nested-session detection#413
fix: clear CLAUDECODE env to prevent nested-session detection#413cyyij wants to merge 1 commit intozed-industries:mainfrom
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @sunnyyi-mac on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
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>
e88667d to
4fd2c15
Compare
|
We require contributors to sign our Contributor License Agreement, and we don't have @cyyij on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @cyyij on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @cyyij on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
Problem
When
claude-agent-acpis spawned from within an existing Claude Code session (e.g. viaacpxor other agent orchestrators), the parent process setsCLAUDECODE=1. This environment variable is inherited by the spawned subprocess, causing Claude Code to detect a "nested session" and exit immediately during initialization.The result is a generic
-32603 Internal errorwithdata.details: "Query closed before response received"on everysession/newcall. This affects bothexec(one-shot) and persistent session modes.Reproduction:
Root Cause
CLAUDECODE=1is set by Claude Code in its shell environment. Whenclaude-agent-acpspawns a new Claude Code subprocess via the SDK'squery(), it passes...process.envwhich includesCLAUDECODE=1. The child process sees this and refuses to start (nested-session protection).Fix
Clear
CLAUDECODEin subprocess env — SetCLAUDECODE: ""in the env object passed toquery(), so the spawned instance starts normally. This mirrors what other Claude Code wrappers do (e.g. cmux's wrapper script usesunset CLAUDECODE).Improve error handling for
session/new— The v0.20.0 fix for "Query closed before response received" (PR fix: throw resourceNotFound when loadSession fails to resume #363) only covered theloadSessionpath (creationOpts.resume). The same error onnewSessionwas left unhandled, producing an opaque "Internal error". Now it returns a meaningful message suggesting to check Claude Code installation.Testing
Verified on macOS arm64 with:
Before fix:
acpx claude execalways fails withInternal errorwhen run from within Claude Code.After fix: works correctly, Claude responds normally.