Skip to content

fix: strip CLAUDECODE env var before launching claude subprocess#12

Open
Conn-Ho wants to merge 1 commit intoryanstephen:mainfrom
Conn-Ho:fix/claudecode-env-leak
Open

fix: strip CLAUDECODE env var before launching claude subprocess#12
Conn-Ho wants to merge 1 commit intoryanstephen:mainfrom
Conn-Ho:fix/claudecode-env-leak

Conversation

@Conn-Ho
Copy link
Copy Markdown

@Conn-Ho Conn-Ho commented Mar 26, 2026

Problem

When lil-agents is launched from inside an existing Claude Code session (e.g. via a terminal where CLAUDECODE is set), the app fails silently — Claude never replies.

The root cause is two-layered:

  1. ShellEnvironment.processEnvironment() runs zsh -l -i to capture the user's full login shell environment, which includes the CLAUDECODE variable set by the parent session.
  2. This environment is passed directly to the claude subprocess, which triggers Claude Code's built-in nested-session guard:
    Error: Claude Code cannot be launched inside another Claude Code session.
    Nested sessions share runtime resources and will crash all active sessions.
    

Fix

One line in launchProcess() — remove CLAUDECODE from the environment dict before handing it to the subprocess:

var env = ShellEnvironment.processEnvironment()
env.removeValue(forKey: "CLAUDECODE")
proc.environment = env

Reproduction

  1. Open a terminal with an active Claude Code session (or any shell where CLAUDECODE is set)
  2. Launch lil-agents from that environment
  3. Click the character and send a message → no response

With this fix, the nested-session check no longer fires regardless of how lil-agents is launched.

🤖 Generated with Claude Code

When lil-agents is run inside an existing Claude Code session,
ShellEnvironment captures the full login shell environment (zsh -l -i),
which includes the CLAUDECODE variable. This variable is then passed to
the claude subprocess, triggering Claude Code's nested-session guard:
"Claude Code cannot be launched inside another Claude Code session."

Fix: remove CLAUDECODE from the process environment before launching
the claude subprocess so the nested-session check does not fire.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@ryanstephen
Copy link
Copy Markdown
Owner

Hi, I can't seem to recreate the bug this is trying to fix - I can launch CC from terminal and launch lil agents from it and they respond with outputs as expected. Any more details here?

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.

2 participants