Skip to content

fix(claude): auto-detect CLAUDE_CODE_EXECUTABLE when spawning Claude ACP agent#164

Open
SiyaoZheng wants to merge 1 commit intoopenclaw:mainfrom
SiyaoZheng:fix/claude-acp-executable-detection
Open

fix(claude): auto-detect CLAUDE_CODE_EXECUTABLE when spawning Claude ACP agent#164
SiyaoZheng wants to merge 1 commit intoopenclaw:mainfrom
SiyaoZheng:fix/claude-acp-executable-detection

Conversation

@SiyaoZheng
Copy link

Summary

  • When acpx claude exec spawns claude-agent-acp, the adapter internally calls @anthropic-ai/claude-agent-sdk's query() which spawns a Claude Code CLI subprocess
  • If CLAUDE_CODE_EXECUTABLE is not set and the adapter's isStaticBinary() returns false (non-Bun environments), pathToClaudeCodeExecutable is left undefined
  • The SDK then fails to locate the CLI binary, the subprocess exits immediately, and initializationResult() throws "Query closed before response received"
  • This change auto-detects the claude CLI path via which and common install locations when spawning the Claude ACP agent, setting CLAUDE_CODE_EXECUTABLE in the child process environment

Reproduction

# Fails without the fix (non-Bun, CLAUDE_CODE_EXECUTABLE unset)
acpx claude exec "hello"
# Error: Internal error - Query closed before response received

# Works with manual workaround
CLAUDE_CODE_EXECUTABLE=$(which claude) acpx claude exec "hello"

Test plan

  • npx tsc --noEmit passes
  • npm run build succeeds
  • acpx claude exec "Reply with exactly: OK" returns correct response
  • Verified on macOS with Claude Code installed at ~/.local/bin/claude

🤖 Generated with Claude Code

…ACP agent

When claude-agent-acp is spawned via acpx, it internally calls the
Claude Agent SDK's query() which spawns a Claude Code CLI subprocess.
If CLAUDE_CODE_EXECUTABLE is not set and isStaticBinary() returns false
(non-Bun environments), pathToClaudeCodeExecutable is undefined, causing
the CLI subprocess to fail immediately with "Query closed before response
received".

This change detects when the Claude ACP agent is being spawned and
automatically resolves the claude CLI path via `which` or common install
locations, setting CLAUDE_CODE_EXECUTABLE in the child process environment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant