Problem
Claude Code v2.1.39+ blocks nested sessions by checking CLAUDECODE environment variable, causing EPIPE errors when running crewx x @agent inside Claude Code.
Root Cause
- Claude Code sets
CLAUDECODE=1 env variable
- Child processes spawning
claude CLI detect this and exit immediately
- CrewX subprocess spawning fails with EPIPE error
Solution: MCP Protocol Workaround
Key Insight: MCP servers run as separate processes, not as child processes of Claude Code. This means:
- No
CLAUDECODE env variable inherited
- Can spawn
claude/gemini CLI without restrictions
- Uses Anthropic's official extension protocol (politically safe)
Architecture
Claude Code (VSCode)
├── MCP Protocol (stdio/sse)
│ └── CrewX MCP Server (별도 프로세스) ← CLAUDECODE env 없음!
│ └── tool call: "crewx_executeAgent"
│ └── claude spawn (정상 실행) ✅
│
└── Bash tool
└── crewx x @agent → EPIPE ❌ (nested session blocked)
Implementation Status
✅ Already Implemented! CrewX already has complete MCP infrastructure:
crewx_queryAgent - Query agents (read-only)
crewx_executeAgent - Execute tasks through agents
crewx_executeAgentParallel - Parallel agent execution
crewx_listAgents - List available agents
- MCP stdio and HTTP modes both supported
Setup
Option 1: stdio mode (recommended)
Add to Claude Code config (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"crewx": {
"command": "npx",
"args": ["-y", "@sowonai/crewx-cli@next"],
"env": {
"CREWX_CONFIG": "/path/to/your/crewx.yaml"
}
}
}
}
Option 2: HTTP mode (more stable)
-
Run CrewX MCP server:
crewx serve --port 3100 --protocol HTTP --log
-
Add to Claude Code config:
{
"mcpServers": {
"crewx": {
"url": "http://localhost:3100/mcp",
"transport": "http"
}
}
}
Usage in Claude Code
Use crewx_executeAgent tool:
- agentId: "crewx_claude_dev"
- task: "Implement feature X"
- projectPath: "/Users/doha/git/crewx"
Why This Is Perfect
- Technically sound: Separate process space, no env inheritance
- Politically safe: Using Anthropic's official MCP protocol, not "bypassing security"
- Zero new code: Existing MCP infrastructure works as-is
- Performance: No overhead compared to direct CLI calls
Documentation
See: docs/mcp-nested-session-workaround.md
Related Issues
Next Steps
- Update CrewX documentation to recommend MCP usage in Claude Code
- Add troubleshooting guide for common MCP setup issues
- Consider deprecating direct CLI calls in favor of MCP tools
Problem
Claude Code v2.1.39+ blocks nested sessions by checking
CLAUDECODEenvironment variable, causing EPIPE errors when runningcrewx x @agentinside Claude Code.Root Cause
CLAUDECODE=1env variableclaudeCLI detect this and exit immediatelySolution: MCP Protocol Workaround
Key Insight: MCP servers run as separate processes, not as child processes of Claude Code. This means:
CLAUDECODEenv variable inheritedclaude/geminiCLI without restrictionsArchitecture
Implementation Status
✅ Already Implemented! CrewX already has complete MCP infrastructure:
crewx_queryAgent- Query agents (read-only)crewx_executeAgent- Execute tasks through agentscrewx_executeAgentParallel- Parallel agent executioncrewx_listAgents- List available agentsSetup
Option 1: stdio mode (recommended)
Add to Claude Code config (
~/Library/Application Support/Claude/claude_desktop_config.json):{ "mcpServers": { "crewx": { "command": "npx", "args": ["-y", "@sowonai/crewx-cli@next"], "env": { "CREWX_CONFIG": "/path/to/your/crewx.yaml" } } } }Option 2: HTTP mode (more stable)
Run CrewX MCP server:
Add to Claude Code config:
{ "mcpServers": { "crewx": { "url": "http://localhost:3100/mcp", "transport": "http" } } }Usage in Claude Code
Why This Is Perfect
Documentation
See:
docs/mcp-nested-session-workaround.mdRelated Issues
CLAUDECODEenv stripping approachNext Steps