Skip to content

Agent SDK fails with exit code 1 when launched from Claude Code terminal #107

@JasonWang1124

Description

@JasonWang1124

Description

When OpenAlice is started from within a Claude Code terminal session (e.g., running pnpm dev inside Claude Code), the Agent SDK provider silently fails. All user messages receive no response — the SSE stream either hangs or closes abruptly.

Root Cause

Claude Code sets a CLAUDECODE environment variable in its shell. When OpenAlice's Agent SDK spawns a new Claude Code subprocess via @anthropic-ai/claude-agent-sdk, this variable is inherited through process.env, causing the subprocess to detect a "nested session" and exit immediately with code 1:

Error: Claude Code cannot be launched inside another Claude Code session.
Nested sessions share runtime resources and will crash all active sessions.

Steps to Reproduce

  1. Open a terminal inside Claude Code
  2. Run pnpm dev to start OpenAlice
  3. Send any message via the Web UI
  4. Observe: no response is returned; logs/agent-sdk.log shows "Claude Code process exited with code 1"

Expected Behavior

OpenAlice should respond normally regardless of whether it was launched from a Claude Code terminal.

Environment

  • Claude Code: v2.1.96
  • Agent SDK: v0.2.72
  • Node.js: v24.4.1
  • macOS (Darwin 25.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions