Skip to content

tower: sanitize inherited CLAUDE_CODE_* env — restarting Tower from a Claude Code session silently disables transcript saving (and resume) for every spawned agent #1219

Closed

Description

@waleedkadous

tower: sanitize inherited CLAUDE_CODE_* env — restarting Tower from a Claude Code session silently disables transcript saving (and resume) for every spawned agent

Mechanism (verified end-to-end on a live install)

Claude Code plants CLAUDE_CODE_CHILD_SESSION (and CLAUDE_CODE_SESSION_ID, _ENTRYPOINT, _EXECPATH) into the environment of every subprocess it spawns, so a nested claude can detect it was launched from inside another session and disable transcript saving.

Tower is a daemon — but it inherits the environment of whoever starts it. When Tower is started/restarted from a shell inside a Claude Code session (an extremely common operation: afx tower start, pnpm -w run local-install, crash recovery driven by an architect), the marker bakes into Tower's env and cascades:

claude session → Bash tool → afx tower start → Tower → shellper → agent claude

Every architect/builder claude session Tower spawns then believes it is a nested child session and shows:

⚠ Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker · restart with CLAUDE_CODE_FORCE_SESSION_P…

Verified with ps eww: the running Tower daemon carried the marker, and multiple shellper-spawned agent claude processes carried it (inherited at spawn). After restarting Tower via env -u CLAUDE_CODE_CHILD_SESSION -u CLAUDE_CODE_SESSION_ID -u CLAUDE_CODE_ENTRYPOINT -u CLAUDE_CODE_EXECPATH afx tower start, Tower's env is clean and new spawns are unaffected.

Why this is worse than a warning banner

Sessions with transcript saving disabled cannot be resumed. Tower's whole crash-recovery story (#1145, #1149, session_id-based resume) assumes agent sessions persist transcripts. A Tower that was ever restarted from inside a Claude session quietly produces agents that are unrecoverable after the next crash — the failure only manifests at recovery time, when it's too late. The leak also persists across Tower restarts via shellpers: daemonized shellper processes outlive Tower and keep their spawn-time env, so agents they restart keep the marker even after Tower itself is cleaned.

Proposed fix

  1. Tower sanitizes at spawn: strip CLAUDE_CODE_* (or at minimum CLAUDE_CODE_CHILD_SESSION) from the env it passes to shellper/agent processes. This is the robust fix — it protects regardless of how Tower was started, including the shellper-outlives-Tower path for newly restarted claude processes.
  2. afx tower start scrubs its own env before daemonizing, and (optionally) prints a note when it detects it was launched from inside a Claude session.
  3. codev doctor check (cheap): warn if the running Tower's env carries CLAUDE_CODE_CHILD_SESSION — detectable via ps eww on the daemon PID.

Notes

  • Any agent terminals spawned while a contaminated Tower was up have the marker baked in until their claude process restarts; the fix is forward-looking.
  • The transcript-off warning banner appears to be recent Claude Code CLI behavior; the leak itself may long predate its visibility — which is exactly why the doctor check (3) is worth having.

Area: area/tower.

Activity

  1. added
    area/tower
    on Jul 22, 2026
  2. waleedkadous commented on Sep 5, 2026

    @waleedkadous
    ContributorAuthor

    Recurred again 2026-09-05 (a pnpm -w run local-install from an architect session whose env scrub silently failed). Spawning a BUGFIX builder. Design prescription so no plan gate is needed:

    1. Sanitize at the spawn seam, not at startup. In the code path where Tower builds the env for a shellper / agent process, strip this exact set before spawn: CLAUDE_CODE_CHILD_SESSION, CLAUDE_CODE_SESSION_ID, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_EXECPATH, CLAUDE_CODE_MESSAGING_SOCKET, CLAUDE_CODE_MESSAGING_TOKEN, CLAUDECODE, CLAUDE_PID, CLAUDE_EFFORT. Denylist, not a CLAUDE* prefix wipe — CLAUDE_CONFIG_DIR and similar user settings must survive. One exported helper (sanitizeInheritedClaudeEnv(env)) used by every spawn path, with a unit test that pins the list.
    2. afx tower start scrubs its own env with the same helper before daemonizing, and prints one line when it detects it was launched from inside a Claude session.
    3. codev doctor check: read the running Tower daemon's env (ps -E -p <pid> on macOS, /proc/<pid>/environ on Linux) and warn if the marker is present, with the exact restart command.
    4. Verification is functional, not by inspection: restart Tower from inside a Claude session, spawn a builder, and confirm with ps -E that neither Tower nor the agent claude process carries the marker and the agent shows no transcript-off banner.

    Not in scope: cleaning up already-contaminated shellpers (forward-looking fix only).

  3. waleedkadous commented on Sep 5, 2026

    @waleedkadous
    ContributorAuthor

    On it! Working on a fix now.

  4. added 11 commits that reference this issue on Sep 5, 2026
    8f7bdec
    c2414a9
    3434084
    e0cde6f
    7e91467
    937d7fe
    21d3cfa
    17f1c49
    95ce516
    713c48f
    9bae421
  5. added a commit that references this issue on Sep 7, 2026
    c4ad613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions