Skip to content

Conversation

@mshuffett
Copy link

@mshuffett mshuffett commented Dec 30, 2025

Summary

Fixes #15047
Related: #15790

Fixes the ralph-wiggum stop hook triggering across ALL Claude Code sessions instead of being isolated to individual sessions.

Problem: The stop hook checked for a state file at a CWD-relative path (.claude/ralph-loop.local.md), which caused cross-session interference:

  1. Session A starts ralph-loop in directory X
  2. Session B (in the same directory) stops → hook finds Session A's state file
  3. Session B gets hijacked into continuing Session A's loop, receiving the same prompt and continuing iterations

This made it impossible to run ralph-loop in one session while using other Claude Code sessions normally in the same directory - they would all get pulled into the same loop.

Solution: Session-based state file isolation:

  • SessionStart hook: Extracts session_id from hook input JSON and persists it as CLAUDE_SESSION_ID environment variable via CLAUDE_ENV_FILE. This makes the session ID available to command scripts.

  • Session-specific state files: State files are now stored in the plugin's state/ directory as ${session_id}.md instead of CWD-relative paths.

  • Stop hook isolation: Extracts session_id from its JSON input and only checks for state files matching that specific session.

Changes

  • hooks/session-start-hook.sh (NEW) - Persists session_id as CLAUDE_SESSION_ID
  • hooks/hooks.json - Added SessionStart hook configuration
  • hooks/stop-hook.sh - Uses session-specific state files
  • scripts/setup-ralph-loop.sh - Uses CLAUDE_SESSION_ID for state file naming
  • commands/ralph-loop.md - Updated state file path reference
  • .gitignore (NEW) - Ignores state/ directory

Test plan

  • Start a ralph-loop in Session A
  • Verify Session B can exit normally without being hijacked into the loop
  • Verify Session A's ralph-loop continues working as expected
  • Verify state files are created in <plugin-root>/state/<session-id>.md

🤖 Generated with Claude Code

The ralph-wiggum stop hook was triggering across ALL Claude Code sessions
instead of being isolated to individual sessions. This happened because
the state file was stored at a CWD-relative path (.claude/ralph-loop.local.md).

This fix introduces session-based state file isolation:

1. SessionStart hook: Extracts session_id from hook input and persists it
   as CLAUDE_SESSION_ID environment variable via CLAUDE_ENV_FILE. This makes
   the session ID available to command scripts.

2. Session-specific state files: State files are now stored in the plugin's
   state/ directory as ${session_id}.md instead of a CWD-relative path.

3. Stop hook isolation: The stop hook now extracts session_id from its JSON
   input and only checks for state files matching that specific session.

This ensures that starting a ralph-loop in one session doesn't block
other Claude Code sessions from exiting normally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mshuffett mshuffett marked this pull request as ready for review December 30, 2025 23:42
nazt added a commit to laris-co/ralph-local that referenced this pull request Jan 6, 2026
Merge upstream changes with our improvements:

NEW FILES:
- .gitignore: Ignore state/ directory
- hooks/session-start-hook.sh: Extract session_id from hook input

MODIFIED FILES:
- hooks/hooks.json: Add SessionStart hook
- hooks/stop-hook.sh: Use session-specific state files
- scripts/setup-ralph-loop.sh: Use CLAUDE_SESSION_ID for state path
- commands/ralph-loop.md: Update state file path reference

KEY CHANGES:
- State files now stored in ${PLUGIN_ROOT}/state/${SESSION_ID}.md
- Each session has isolated state (no cross-session interference)
- SessionStart hook captures session_id and persists as CLAUDE_SESSION_ID
- Kept our extensive error handling from original fork

Synced with: anthropics/claude-code#15853
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.

[BUG] ralph-wiggum stop hook triggered in separate session

1 participant