fix(ralph-loop): lazy-claim session_id for cross-session isolation#981
Open
carpenstreet-leo wants to merge 1 commit intoanthropics:mainfrom
Open
fix(ralph-loop): lazy-claim session_id for cross-session isolation#981carpenstreet-leo wants to merge 1 commit intoanthropics:mainfrom
carpenstreet-leo wants to merge 1 commit intoanthropics:mainfrom
Conversation
CLAUDE_CODE_SESSION_ID env var is not available to plugin setup scripts, so ralph-loop state files are created with an empty session_id. This causes the stop hook to fire in ALL sessions within the same project, not just the one that started the loop. The stop hook already receives session_id via stdin JSON. This change adds a "lazy claim" — on first stop hook invocation, if the state file has no session_id, the hook writes the current session's ID into the state file. Subsequent invocations from other sessions see a mismatch and pass through. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CLAUDE_CODE_SESSION_IDenv var is not available to plugin setup scripts, soralph-loopstate files are created with an emptysession_idsession_idvia stdin JSON — this change adds a "lazy claim" on first invocation to bind the loop to the correct sessionRoot Cause
setup-ralph-loop.shwritessession_id: ${CLAUDE_CODE_SESSION_ID:-}but the env var is never set, resulting insession_id:(empty). The existing guard (-n "$STATE_SESSION") then fails, allowing every session's stop hook to match.Fix
On first stop hook invocation, if the state file has no
session_idbut the hook input JSON does, write it into the state file ("lazy claim"). Subsequent invocations from other sessions see a mismatch and pass through (exit 0).Test plan
CLAUDE_CODE_SESSION_IDis not set in plugin script envsession_id(UUID)🤖 Generated with Claude Code