Skip to content

Fix Gemini CLI CLAUDE_PROJECT_DIR assumption across shell layer and README (#534) - #537

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/534
Sep 4, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/534

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #534.

What was wrong

pipeline/host.py's GEMINI host was already corrected (#456) to read CLAUDE_PROJECT_DIR as Gemini CLI's own compatibility-alias project-dir variable, per the installed @google/gemini-cli 0.57.0 package's own bundled docs -- but that correction was narrow and dead-code-only. The much larger, load-bearing "Codex and Gemini CLI never set CLAUDE_PROJECT_DIR" assumption baked into scripts/resolve-paths.sh, scripts/lib-env-cache.sh, scripts/session-end-hook.sh, scripts/post-tool-hook.sh, scripts/user-prompt-hook.sh, and README.md went untouched.

The two judgment calls

  1. Are the REMEMBER_HOOK_CWD fallback (resolve-paths.sh) and the cache-key fallback (lib-env-cache.sh) still correct? Yes, unchanged. Both stay correct fallbacks for any host that genuinely leaves CLAUDE_PROJECT_DIR unset -- still true of Codex, live-confirmed via tests/fixtures/codex-env-463.txt -- and Gemini setting the variable just means priority-1 resolution wins and the fallback is never reached on that host. Only the comments describing "which hosts hit this branch" were stale; fixed in every file the issue named plus scripts/session-start-hook.sh and docs/reading-the-transcript-path.md (see below).

  2. Does scripts/user-prompt-hook.sh's UserPromptSubmit JSON-envelope gate need a host-specific check instead of "is CLAUDE_PROJECT_DIR set"? I tried it, then rejected it during self-review, and I'm recording the rejection because the alternative looks obviously more correct at first glance and I want the next person who reaches for it to see why it isn't. The obvious replacement is Codex's own signature, CODEX_SESSION_ID/CODEX_THREAD_ID (the pair pipeline/host.py's CODEX.signature_vars already uses) -- and it is wrong for this call site specifically: Codex detection still fails in the hook process: the route works under an explicit override but auto resolves to claude #465 already measured, live, that neither variable survives into a process Codex spawns as a HOOK, only into a Codex TOOL-SHELL command (pipeline/haiku.py's own note; tests/test_codex_signature_463.py's docstring). scripts/user-prompt-hook.sh is registered as exactly such a hook in hooks/hooks.codex.json. Gating it on that pair would have silently disabled the JSON envelope on every real Codex UserPromptSubmit invocation and reopened Codex reports UserPromptSubmit as Failed once the hook actually produces output, because its stdout contract is not Claude Code's #451/fix: stop Codex reading UserPromptSubmit as Failed on every prompt (#451) #452 (every Codex prompt reading Failed again) -- a regression my own first commit on this branch introduced and my self-review caught before this PR was opened. The gate stays on CLAUDE_PROJECT_DIR, unchanged: Gemini setting it now simply routes Gemini through the same plain-stdout branch Claude Code already takes, which is REASONED as the safer default (Gemini CLI's own BeforeAgent stdout contract has never been observed live, and Gemini CLI: no working credentials in this environment -- blocks driving any live session for #456's remaining scope #532 blocks a live session), not a claim about what that contract actually wants.

Self-review: one real regression caught and reverted, two adjacent stale-comment findings fixed

My first commit on this branch (now superseded within this PR) changed the JSON-envelope gate to key on CODEX_SESSION_ID/CODEX_THREAD_ID. The auditor spawned for self-review caught that this reopens #451/#452 on real Codex, for the reason described above. I reverted the gate and rewrote the test file, README paragraphs, and changelog fragment to match. Two other findings, both stale prose in the same "Codex/Gemini never set it" family, both fixed directly (same subsystem, one-sentence blast radius, in scope):

One item is below the bar for a filing: the auditor also flagged, as a tooling-adjacent observation rather than a diff finding, that its sibling Explore reviewer's Read tool result carried injected text instructing it to route reads through a supertool op it was never granted -- Explore correctly disregarded it and fell back to cat via Bash. This is a below-bar observation about this loop's own tooling, not about claude-remember's code, and is recorded in the developer report under adjacent rather than as a code finding here.

Tests

tests/test_gemini_stdout_envelope_534.py (new) pins both sides of the (unchanged) gate as controls: a Gemini-shaped environment gets plain stdout, and a genuinely signal-less host (no CLAUDE_PROJECT_DIR, no Codex signature) still gets the Codex JSON envelope -- so a future re-narrowing of the gate to Codex's own signature regresses visibly instead of silently. tests/test_codex_upsubmit_stdout_451.py's _env_codex fixture documents, in its own docstring, why it deliberately does not set CODEX_SESSION_ID/CODEX_THREAD_ID.

Narrowed pytest run only (per this repo's own CLAUDE.md and this plugin's brief) -- the full test_command was not run; CI is the gate for that. python3 .oss/assemble_changelog.py --check passes.

…EADME (#534)

pipeline/host.py's GEMINI host was already corrected (#456) to read
CLAUDE_PROJECT_DIR, since gemini-cli 0.57.0's own bundled docs list it as
a compatibility alias Gemini sets -- but that correction was narrow and
dead-code-only. The much larger "Codex and Gemini CLI never set
CLAUDE_PROJECT_DIR" assumption baked into scripts/resolve-paths.sh,
scripts/lib-env-cache.sh, scripts/session-end-hook.sh,
scripts/post-tool-hook.sh, scripts/user-prompt-hook.sh, and README.md
went untouched.

The REMEMBER_HOOK_CWD fallback in resolve-paths.sh and the cache-key
fallback in lib-env-cache.sh needed only corrected comments: both stay
correct as fallbacks for any host that genuinely leaves
CLAUDE_PROJECT_DIR unset (Codex, live-confirmed via
tests/fixtures/codex-env-463.txt), and Gemini setting the variable just
means priority 1 wins and the fallback is never reached on that host.

scripts/user-prompt-hook.sh's UserPromptSubmit JSON-envelope branch
needed an actual behavioural fix: it used to key on "is
CLAUDE_PROJECT_DIR set" as a stand-in for "is this Codex", which would
have silently routed a Gemini session through Codex's JSON envelope --
unverified, since Gemini CLI's own BeforeAgent stdout contract has never
been observed and #532 blocks a live session. It now keys on Codex's own
live-verified signature (CODEX_SESSION_ID/CODEX_THREAD_ID, the same pair
pipeline/host.py's CODEX.signature_vars already uses), so the JSON
envelope is Codex-only by construction and every other host, Gemini
included, gets plain stdout -- a documented, defensible default, not a
claim about what Gemini's own contract wants.

TDD via tests/test_gemini_stdout_envelope_534.py, red on the pre-fix
gate (a host with neither CLAUDE_PROJECT_DIR nor a Codex signature used
to get the JSON envelope by default); tests/test_codex_upsubmit_stdout_451.py's
own Codex fixture updated to set the same signature, matching a real
codex exec process. README corrected everywhere it repeated the old
shared-fact claim. Changelog fragment added.

Co-Authored-By: Max <noreply>
The auditor spawned in self-review found that the previous commit's
UserPromptSubmit JSON-envelope gate change -- keying on
CODEX_SESSION_ID/CODEX_THREAD_ID instead of CLAUDE_PROJECT_DIR -- was a
real regression, not an improvement: #465 already measured, live, that
neither variable survives into a process Codex spawns as a HOOK, only
into a Codex TOOL-SHELL command (pipeline/haiku.py's own note,
tests/test_codex_signature_463.py's docstring). scripts/user-prompt-hook.sh
is registered as exactly such a hook in hooks/hooks.codex.json, so the
new gate would have silently disabled the JSON envelope on every real
Codex UserPromptSubmit invocation and reopened #451/#452 (every Codex
prompt reading Failed again). tests/fixtures/codex-env-463.txt, the
fixture that pair is pinned against, was itself captured from a Codex
tool-shell command, not from inside a hook.

Reverted the gate to CLAUDE_PROJECT_DIR set/unset, unchanged from before
this PR. That mechanism was never wrong for the behavioural question
#534 was asked to settle: Gemini setting CLAUDE_PROJECT_DIR (per its own
docs, unverified live) just moves Gemini into the same plain-stdout
branch Claude Code already takes, which was already true before any code
change here -- only the comments describing it were stale. Documented
the considered-and-rejected Codex-signature alternative in
scripts/user-prompt-hook.sh, README.md, and the changelog fragment, so
the reasoning survives for a future reader who reaches for the same
"obvious" fix.

Rewrote tests/test_gemini_stdout_envelope_534.py as a positive/negative
control pinning the gate's actual (unchanged) behaviour rather than a
red/green story for a gate that no longer changes; reverted the
CODEX_SESSION_ID/CODEX_THREAD_ID additions to
tests/test_codex_upsubmit_stdout_451.py's Codex fixture, documenting why
they were deliberately removed rather than left inert. Also corrected
docs/reading-the-transcript-path.md, an adjacent doc the auditor's
sibling Explore review found still asserting the same stale "Gemini
documents no environment variables at all" claim.

Co-Authored-By: Max <noreply>
…534)

The auditor spawned in self-review found scripts/session-start-hook.sh:122
still asserting "only Claude Code also publishes it as CLAUDE_PROJECT_DIR"
-- the same "Codex and Gemini CLI never set CLAUDE_PROJECT_DIR" shared-fact
claim this issue set out to correct everywhere, left in the one hook script
not named in the original file list because it was missed rather than
excluded. Corrected to name Codex's own live-confirmed non-setting (#463)
and Gemini CLI's own claimed compatibility alias (#456, unverified live,
#532) separately, matching the sibling comment already fixed in
scripts/session-end-hook.sh.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit a44ef62 into main Sep 4, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/534 branch September 4, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant