Skip to content

Keep Claude Code alive when a Codex subagent starts - #129

Merged
m4rocks merged 2 commits into
mainfrom
login-shell-own-session
Nov 18, 2026
Merged

m4rocks merged 2 commits into
mainfrom
login-shell-own-session

Conversation

@m4rocks

@m4rocks m4rocks commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Starting a Codex subagent sometimes killed the Claude Code session that ran it. The subagent then reported "Codex failed: the helper stopped without an answer", and Claude Code exited without a message.

Cause

claudiu --acp runs inside Claude Code's terminal. To find npx, it reads the login shell's PATH with $SHELL -l -i -c … (with_login_path, since #124). An interactive zsh that has a controlling terminal takes over the terminal's foreground while it runs, about half a second on every Codex turn. For that time Claude Code is a background job on its own terminal. When it touched the terminal during that window, it died, and the helper died with it.

Fix

path_from_shell starts the shell in a session of its own (setsid in pre_exec), so it has no controlling terminal to take. The fix is in the shared function, so it also covers the --mcp-title server, which runs in the same terminal and can reach the login PATH through gh.

Proof

  • Live repro: an interactive Claudiu session running Codex turns back to back died on the third turn, with the same transcript signature as the two crashes reported.
  • Terminal check: the helper ran under a real PTY while a watcher sampled the terminal's foreground process group every 5 ms. With the 0.9.17 helper, zsh held it for 89–96 samples per run. With this branch, 0 across 3 runs.
  • PATH still read: zsh -l -i without a terminal still prints the full PATH, Homebrew directories included.
  • Regression test: the_login_shell_runs_without_this_processs_terminal fails without the fix (the shell's process group equals the test's) and passes with it.
  • Checks: cargo clippy --locked --all-targets -- -D warnings is clean, and cargo test --locked passes 519.

Risk

A startup file that needs a terminal now runs without one, and an interactive shell with no terminal prints warnings to stderr, which is discarded. The PATH is read the same way. To undo, revert this commit.

The Codex helper reads the login shell's PATH with `$SHELL -l -i`, and it
runs inside Claude Code's terminal. An interactive zsh with a controlling
terminal takes over the terminal's foreground while it runs, about half
a second on every Codex turn. Claude Code was a background job on its
own terminal for that time, and when it touched the terminal then, it
died, taking the helper with it. Since #124 this happened on any turn.

The login shell now starts in a session of its own (setsid), without a
controlling terminal, so it can't take the terminal from anyone. This
also covers the --mcp-title server, which runs in the same terminal.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
claudiu Ready Ready Preview Nov 18, 2026 8:26pm UTC

@m4rocks
m4rocks merged commit e8f7b1f into main Nov 18, 2026
5 checks passed
@m4rocks
m4rocks deleted the login-shell-own-session branch November 24, 2026 22:38

This branch was successfully deployed

1 active deployment
Preview — 0b978148 Deployed Nov 18, 2026 by vercel[bot]
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.

1 participant