Fix Agent SDK nested session crash when launched from Claude Code#108
Open
JasonWang1124 wants to merge 1 commit intoTraderAlice:masterfrom
Open
Fix Agent SDK nested session crash when launched from Claude Code#108JasonWang1124 wants to merge 1 commit intoTraderAlice:masterfrom
JasonWang1124 wants to merge 1 commit intoTraderAlice:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #107
When OpenAlice is launched from a Claude Code terminal, the inherited
CLAUDECODEenvironment 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
CLAUDECODEenv var before spawning the Agent SDK subprocess (src/ai-providers/agent-sdk/query.ts)How it works
Claude Code sets
CLAUDECODEin its shell environment. WhenaskAgentSdk()copiesprocess.envto 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
claude auth status— logged in with claudeai (Max subscription)query()returnsexit code 1withCLAUDECODEsetdelete env.CLAUDECODE, Agent SDK returns"Hello!"successfully