Skip to content

fix: strip parent Claude Code session env from nested claude -p (#95)#103

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/strip-claude-session-env-95
Jun 18, 2026
Merged

fix: strip parent Claude Code session env from nested claude -p (#95)#103
fdaviddpt merged 1 commit into
mainfrom
fix/strip-claude-session-env-95

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Context

The Haiku summarizer subprocess stripped only CLAUDECODE, so the parent session's CLAUDE_JOB_DIR and CLAUDE_CODE_SESSION_ID (and the rest of the CLAUDE_CODE_* family) leaked into the nested claude -p — making it look like the parent's resumable session to anything keying off those vars (#95).

#93's --no-session-persistence removed the visible symptom (no persisted record / Recents flood) but not the inherited env. This closes the underlying leak.

Change

  • haiku.py: extract _child_env() — strip CLAUDECODE, CLAUDE_JOB_DIR, and any CLAUDE_CODE_*; pass everything else through unchanged.
  • Docstrings updated.

Test

test_call_haiku_strips_parent_session_env (TDD, red→green): sets all three vars + PATH, asserts the session vars are gone from the child env and PATH survives. Full suite green (432 passed).

Closes #95.

🤖 Generated by Max

The summarizer subprocess stripped only CLAUDECODE, so CLAUDE_JOB_DIR and
CLAUDE_CODE_SESSION_ID (and the rest of CLAUDE_CODE_*) leaked into the nested
`claude -p`, making it look like the parent's resumable session to anything
keying off those vars. #93's --no-session-persistence hid the visible symptom
(no persisted record) but not the inherited env.

Extract _child_env(): strip CLAUDECODE, CLAUDE_JOB_DIR, and CLAUDE_CODE_*;
pass everything else through. Test asserts all three are gone and an unrelated
var (PATH) survives.

Co-Authored-By: Max <noreply>
@fdaviddpt fdaviddpt merged commit b8f80ed into main Jun 18, 2026
12 checks passed
@fdaviddpt fdaviddpt deleted the fix/strip-claude-session-env-95 branch June 18, 2026 18:30
fdaviddpt pushed a commit that referenced this pull request Jun 18, 2026
…ch-up

PATH ordering can't fix the WSL-bash problem: Windows CreateProcess searches
System32 BEFORE PATH, so subprocess.run(['bash']) always hits System32\bash.exe
(the WSL launcher). Add _find_bash() (plain 'bash' on POSIX, explicit
Git-for-Windows bash.exe on Windows, mirroring test_hooks_json._find_git_bash)
and invoke it everywhere; module skipif when Git Bash is absent. Revert the
ineffective GITHUB_PATH workflow shim. Combined with the earlier MSYS path
normalization, the three modules now run on Windows (TestDispatchOwnershipChecks
stays skipped — NTFS has no POSIX mode bits).

Also bring CHANGELOG [Unreleased] current — it was untouched across this
session's 7 merged PRs (#90/#93/#99/#101/#102/#103/#104). Added Fixed/Security
entries with issue/PR links + contributor credit, plus the #79 and encoding
test-module notes.

Co-Authored-By: Max <noreply>
fdaviddpt added a commit that referenced this pull request Jun 19, 2026
* ci: run shell-subprocess tests on Windows via Git Bash on PATH (#79)

The Windows runner's PATH bash resolves to the WSL launcher (no distro
installed) → every subprocess.run(['bash', ...]) returned the UTF-16 'no
distributions' error, so #78 skipped these modules on win32 — shipping no
Windows coverage for code paths that DO run there (Claude Code invokes hooks
via Git Bash).

- tests.yml: prepend C:\Program Files\Git\bin to PATH on the Windows row so
  bash resolves to Git Bash.
- Drop the module-level skipif(win32) from test_log_sh, test_migration,
  test_security_fixes.
- Keep TestDispatchOwnershipChecks skipped on win32: POSIX ownership +
  world-writable (0o777) semantics genuinely don't map to NTFS (Git Bash
  fakes mode bits) — the dispatch() guard is a no-op there.

If a now-unskipped test surfaces a real Windows bug (CRLF, path form), it gets
a targeted fix/follow-up, not a re-skip.

Co-Authored-By: Max <noreply>

* ci: prepend Git Bash in-step + MSYS-normalize paths for Windows shell tests (#79)

Two real Windows layers surfaced once the skips were removed:
- bash still resolved to the WSL launcher (System32\bash.exe) — appending to
  GITHUB_PATH didn't override it. Prepend C:\Program Files\Git\bin to $env:PATH
  in the same pwsh step that runs pytest, so subprocess.run(['bash']) children
  inherit Git Bash.
- the tests interpolate Windows backslash/drive paths into bash scripts
  (source C:\..., export DIR=C:\...), which bash mangles (\a/\c escapes,
  spaces). Add _bash_path() (C:\x -> /c/x, backslashes -> /) and apply+quote it
  at every path injected into a bash script or path-valued env var. No-op on
  POSIX. RCE-payload paths inside safe_eval heredocs left literal (intentional).

Co-Authored-By: Max <noreply>

* ci: invoke bash by explicit Git path on Windows (#79) + CHANGELOG catch-up

PATH ordering can't fix the WSL-bash problem: Windows CreateProcess searches
System32 BEFORE PATH, so subprocess.run(['bash']) always hits System32\bash.exe
(the WSL launcher). Add _find_bash() (plain 'bash' on POSIX, explicit
Git-for-Windows bash.exe on Windows, mirroring test_hooks_json._find_git_bash)
and invoke it everywhere; module skipif when Git Bash is absent. Revert the
ineffective GITHUB_PATH workflow shim. Combined with the earlier MSYS path
normalization, the three modules now run on Windows (TestDispatchOwnershipChecks
stays skipped — NTFS has no POSIX mode bits).

Also bring CHANGELOG [Unreleased] current — it was untouched across this
session's 7 merged PRs (#90/#93/#99/#101/#102/#103/#104). Added Fixed/Security
entries with issue/PR links + contributor credit, plus the #79 and encoding
test-module notes.

Co-Authored-By: Max <noreply>

* test: use forward-slash drive paths (C:/x) for bash+Windows-Python crossing (#79)

The MSYS form (/c/x) works for Git Bash but the test scripts also invoke the
Windows python3 (jq fallback's $PYTHON, migration's REMEMBER_DIR -> Path()),
and Windows Python can't open('/c/x'). Forward-slash drive form (C:/x) is
accepted by BOTH Git Bash and Windows Python. Switch _bash_path to emit C:/x,
and route the migration data_dir config through it so REMEMBER_DIR round-trips
to Python Path(). No-op on POSIX.

Co-Authored-By: Max <noreply>

* test: instrument migration test to capture Windows runner state (#79, temp)

* fix: recognize Windows drive paths (C:/, C:\) as absolute in lib-memory-dir.sh (#79)

External-mode data_dir resolution only treated /... and ~... as absolute, so a
Windows drive path (C:/Users/.../mem/{slug}) fell through to the relative branch
and got prepended to PROJECT_DIR — REMEMBER_DIR became proj/C:/.../{{slug}} (path
doubling + slug never substituted, since substitution lives in the absolute
branch). Real Windows users with a C:/-form data_dir hit this. Add
[A-Za-z]:/* and [A-Za-z]:\\* to the absolute case. Diagnosed from a Windows-CI
state dump; instrumentation reverted.

Co-Authored-By: Max <noreply>

* docs(changelog): record the lib-memory-dir.sh Windows data_dir fix (#79)

---------

Co-authored-by: Florian DAVID <fdavid@digital-village.fr>
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.

Sandboxed claude -p summarizer leaks CLAUDE_JOB_DIR / CLAUDE_CODE_SESSION_ID into nested sessions

1 participant