anthropics / anthropics/claude-agent-sdk-typescript
Claude Agent SDK fails on WSL2: "process exited with code 1"
- Langage dominant
- Shell
- Étoiles
- 1.8k
- Forks
- 226
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
# Bug Report: Claude Agent SDK Process Crash on WSL2
## Environment
- **OS**: WSL2 (Windows Subsystem for Linux 2)
- Linux Kernel: 6.6.87.2-microsoft-standard-WSL2
- Distribution: Ubuntu/Debian-based
- **Node.js**: v22.20.0
- **Package**: `@anthropic-ai/claude-agent-sdk` v0.1.11
- **Platform**: linux x64
## Description
The Claude Agent SDK fails immediately when attempting to create an agent query, with the spawned child process exiting with code 1 before any IPC communication occurs. This happens consistently on WSL2 environments, even with the simplest possible configuration.
## Steps to Reproduce
1. Install the SDK in a WSL2 environment:
```bash
pnpm add @anthropic-ai/claude-agent-sdk
```
2. Create a minimal agent with no tools:
```typescript
import { query } from '@anthropic-ai/claude-agent-sdk';
const stream = query({
prompt: "Tell me a joke",
options: {
model: 'claude-3-7-sonnet-20250219',
maxTurns: 1,
systemPrompt: "You are a helpful assistant",
mcpServers: {},
allowedTools: [],
settingSources: [],
},
});
for await (const event of stream) {
console.log(event);
}
```
3. Run the code with proper environment variables set:
```bash
ANTHROPIC_API_KEY="sk-ant-..." node index.js
```
## Expected Behavior
The SDK should spawn a child process, establish IPC communication, and execute the query using the Anthropic API.
## Actual Behavior
The child process crashes immediately with:
```
Error: Claude Code process exited with code 1
at ProcessTransport.getProcessExitError (file:///.../node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs:6531:14)
at ChildProcess.exitHandler (file:///.../node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs:6668:28)
```
No stdout or stderr output is captured from the child process before it exits.
## Troubleshooting Performed
We systematically ruled out all application-level issues:
### ✅ Environment Setup
- Verified Node.js version (v22.20.0) meets requirements (v18+)
- Confirmed `ANTHROPIC_API_KEY` is properly set
- All required environment variables configured
### ✅ System Dependencies
- Installed Playwright browsers: `npx playwright install`
- Installed all Linux system dependencies for Playwright:
```bash
sudo apt-get install libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libdbus-1-3 libxkbcommon0 libxcomposite1 \
libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 \
libcairo2 libasound2 libatspi2.0-0
```
### ✅ File Permissions
- Corrected all file permissions using `chown`
- Verified node_modules integrity with clean reinstall
### ✅ Minimal Reproduction
- **Disabled all tools** - Still crashes
- **Removed all MCP servers** - Still crashes
- **Used simplest possible prompt** ("Tell me a joke") - Still crashes
- **Removed all application logic** - Still crashes
## Root Cause Analysis
The failure occurs deep within the SDK's pre-compiled binary before any of our application code executes. Since the crash persists even when:
- All tools are disabled
- All MCP servers are removed
- Using the absolute minimal configuration
This indicates a **fundamental incompatibility between the SDK's bundled binary and WSL2 environments**.
Possible causes:
1. The pre-compiled binary may require a newer glibc version than WSL2 provides
2. The binary may depend on system libraries that differ between native Linux and WSL2
3. WSL2's virtualization layer may block certain syscalls the binary requires
4. File execution permissions or security policies in WSL2 may interfere with the binary
## Workaround
We successfully worked around this issue by implementing the agent loop manually using the Anthropic Messages API (`@anthropic-ai/sdk`) instead:
```typescript
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const response = await anthropic.messages.create({
model: 'claude-3-7-sonnet-20250219',
max_tokens: 4096,
system: "You are a helpful assistant",
messages: [{ role: 'user', content: 'Tell me a joke' }],
tools: [], // Tool definitions can be provided here
});
// Handle tool use manually in a loop for multi-turn conversations
```
This approach:
- ✅ Works reliably on WSL2
- ✅ Provides full control over the agent loop
- ✅ Supports all the same functionality (tools, multi-turn, streaming)
- ✅ No binary compatibility issues
## Impact
This bug prevents the Claude Agent SDK from being used in:
- WSL2 development environments
- CI/CD pipelines running on WSL2
- Any containerized environment with similar glibc/syscall constraints
## Request
Could the Anthropic team either:
1. Provide a pure JavaScript/TypeScript implementation without pre-compiled binaries, or
2. Distribute multiple binary builds for different environments (glibc versions, musl, WSL2-specific), or
3. Add detailed error logging to the spawned process to help diagnose what specifically is failing
## Additional Context
- The error occurs before any network requests are made (API key is irrelevant)
- No diagnostic information is available from the child process
- The same code works on native Linux and macOS environments
- Issue is 100% reproducible on WSL2
---
**SDK Version**: `@anthropic-ai/claude-agent-sdk@0.1.11`
**Node Version**: `v22.20.0`
**Platform**: `linux x64` (WSL2)
**Date**: January 2025
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.