Skip to content

Comments

fix(ralph-wiggum): isolate ralph-loop state per session#26077

Open
RooseveltAdvisors wants to merge 1 commit intoanthropics:mainfrom
RooseveltAdvisors:fix/ralph-loop-session-isolation
Open

fix(ralph-wiggum): isolate ralph-loop state per session#26077
RooseveltAdvisors wants to merge 1 commit intoanthropics:mainfrom
RooseveltAdvisors:fix/ralph-loop-session-isolation

Conversation

@RooseveltAdvisors
Copy link

Summary

  • Fixes cross-session interference when running ralph-loop in one Claude Code session while another session is open in the same project
  • The stop hook was using a shared state file (.claude/ralph-loop.local.md) that caused unrelated sessions to get hijacked into the loop when they tried to exit

Changes

  • New SessionStart hook (session-start-hook.sh): Captures session_id from hook input and exports it as CLAUDE_SESSION_ID via CLAUDE_ENV_FILE, making it available to bash commands
  • Session-specific state files: Setup script now creates .claude/ralph-loop.{SESSION_ID}.local.md instead of the shared filename
  • Stop hook session awareness: Extracts session_id from its JSON input and only looks for the matching state file — other sessions' loops are invisible
  • Updated cancel-ralph: Handles both session-specific and legacy state filenames

How it works

Before After
Session A starts loop → creates shared .claude/ralph-loop.local.md Session A starts loop → creates .claude/ralph-loop.abc123.local.md
Session B finishes task → stop hook sees shared file → hijacked Session B finishes task → stop hook looks for .claude/ralph-loop.xyz789.local.md → not found → exits normally

Test plan

  • Start a ralph-loop in Session A (/ralph-loop "test task" --max-iterations 5)
  • Open Session B in the same project, do some work, verify it exits cleanly without entering the loop
  • Verify Session A's loop continues to iterate correctly
  • Verify /cancel-ralph works in the session that started the loop
  • Verify fallback random ID when CLAUDE_SESSION_ID is unavailable (new session before restart)

🤖 Generated with Claude Code

…oss-session interference

When multiple Claude Code sessions are open in the same project, the
shared state file (.claude/ralph-loop.local.md) causes the stop hook
to hijack unrelated sessions into the ralph loop.

Fix by making state files session-specific:
- Add SessionStart hook that captures session_id via CLAUDE_ENV_FILE
- Setup script creates .claude/ralph-loop.{SESSION_ID}.local.md
- Stop hook extracts session_id from hook input JSON, only processes
  matching state file
- Update cancel-ralph to handle session-specific and legacy filenames

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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