Skip to content

Fix Agent SDK nested session crash when launched from Claude Code#108

Open
JasonWang1124 wants to merge 1 commit intoTraderAlice:masterfrom
JasonWang1124:fix/agent-sdk-nested-session
Open

Fix Agent SDK nested session crash when launched from Claude Code#108
JasonWang1124 wants to merge 1 commit intoTraderAlice:masterfrom
JasonWang1124:fix/agent-sdk-nested-session

Conversation

@JasonWang1124
Copy link
Copy Markdown

Summary

Fixes #107

When OpenAlice is launched from a Claude Code terminal, the inherited CLAUDECODE environment variable causes the Agent SDK subprocess to detect a "nested session" and exit with code 1, resulting in silent failures for all user messages.

Changes

  • Remove the inherited CLAUDECODE env var before spawning the Agent SDK subprocess (src/ai-providers/agent-sdk/query.ts)

How it works

Claude Code sets CLAUDECODE in its shell environment. When askAgentSdk() copies process.env to build the subprocess environment, this variable carries over and triggers Claude Code's nested-session guard. Deleting it from the env copy allows the subprocess to start normally.

Test plan

  • Verified claude auth status — logged in with claudeai (Max subscription)
  • Reproduced the bug: Agent SDK query() returns exit code 1 with CLAUDECODE set
  • Confirmed fix: after delete env.CLAUDECODE, Agent SDK returns "Hello!" successfully

When OpenAlice is launched from within a Claude Code terminal, the
CLAUDECODE environment variable is inherited by the Agent SDK subprocess,
causing Claude Code to reject execution with "cannot be launched inside
another Claude Code session" (exit code 1).

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.

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

2 participants