Agent SDK: a missing `cwd` is reported as "native binary … failed to launch (libc mismatch)"
Environment
@anthropic-ai/claude-agent-sdk0.3.280 (bundled CLI 2.1.280),claude-agent-sdk-linux-x64(glibc build)- Ubuntu 24.04, glibc 2.39, x86_64, Bun runtime
Repro
import { query } from "@anthropic-ai/claude-agent-sdk";
try {
for await (const m of query({ prompt: "hi", options: { cwd: "/tmp/does-not-exist", maxTurns: 1 } })) break;
} catch (e: any) {
console.log(e.message, e.code);
}
Actual
Claude Code native binary at …/claude-agent-sdk-linux-x64/claude exists but failed to launch.
This usually means the binary does not match this system's libc — e.g. spawning a musl-linked
binary on a glibc Linux host fails because the musl dynamic loader (/lib/ld-musl-*) is missing.
Specify a matching binary with options.pathToClaudeCodeExecutable.
e.code === "ENOENT". The binary is fine: …/claude --version prints 2.1.280 (Claude Code).
Expected
If the cwd passed to spawn does not exist, say so, e.g.Working directory "/tmp/does-not-exist" does not exist (options.cwd).
Node/Bun spawn also returns ENOENT for a missing cwd. So when the binary exists, the SDK should
check whether cwd exists before it falls back to the libc hint.
Impact
In long-lived hosts, a session's cwd often points into a git worktree that is later removed. Every
resume then fails with the libc message, which sends debugging in the wrong direction (checking
binaries, musl vs glibc) instead of pointing at the missing directory.
Related
The same misleading message shows up in #96525 (virtual workspace) and #93766 (OneDrive path). A missing or unreachable cwd may be the shared root cause. This report gives a deterministic SDK-only repro.