Bug Description
Ralph's session continuity feature can accidentally resume an actively in-use Claude Code session, causing ralph to inject PROMPT.md into an ongoing human conversation instead of doing autonomous work.
Root Cause
Multiple issues were found:
1. --continue flag hijacks any active session
Ralph uses --continue which resumes the "most recent conversation in the current directory" - this can be ANY active Claude Code session, not just Ralph's own sessions.
Fix: Use --resume <session_id> with an explicit session ID instead of --continue.
2. log_status writes to stdout, corrupting function return values
The init_claude_session() function returns session IDs via stdout, but log_status() also writes to stdout. This causes log messages like "[INFO] Starting new Claude session" to be captured as the session ID.
Fix: Change log_status to write to stderr (>&2).
3. Ctrl+C takes too long to stop Ralph
When interrupted, the cleanup function doesn't kill the Claude subprocess, causing hangs.
Fix: Track Claude PID globally and kill it in the cleanup handler.
4. Live output only shows tool names, not details
The jq filter only shows ⚡ [ToolName] without showing what the tool is actually doing.
Fix: Enhanced jq filter to show tool inputs as they stream.
Steps to Reproduce
- Open a Claude Code session in a terminal and start working
- In that same session (or same directory), run any ralph command
- Ralph saves the current session ID
- Run
ralph --monitor from another terminal
- Ralph resumes the user's active session instead of starting fresh
- User sees PROMPT.md injected into their conversation
The Fix
See PR #153 for the complete fix. Key changes to ralph_loop.sh:
# Before (buggy):
CLAUDE_CMD_ARGS+=("--continue")
# After (fixed):
if [[ -n "$session_id" ]]; then
CLAUDE_CMD_ARGS+=("--resume" "$session_id")
fi
# Before (buggy):
echo -e "${color}[$timestamp] [$level] $message${NC}"
# After (fixed):
echo -e "${color}[$timestamp] [$level] $message${NC}" >&2
Environment
- ralph-claude-code version: 0.11.2
- OS: macOS
- Shell: zsh
Bug Description
Ralph's session continuity feature can accidentally resume an actively in-use Claude Code session, causing ralph to inject PROMPT.md into an ongoing human conversation instead of doing autonomous work.
Root Cause
Multiple issues were found:
1.
--continueflag hijacks any active sessionRalph uses
--continuewhich resumes the "most recent conversation in the current directory" - this can be ANY active Claude Code session, not just Ralph's own sessions.Fix: Use
--resume <session_id>with an explicit session ID instead of--continue.2.
log_statuswrites to stdout, corrupting function return valuesThe
init_claude_session()function returns session IDs via stdout, butlog_status()also writes to stdout. This causes log messages like"[INFO] Starting new Claude session"to be captured as the session ID.Fix: Change
log_statusto write to stderr (>&2).3. Ctrl+C takes too long to stop Ralph
When interrupted, the cleanup function doesn't kill the Claude subprocess, causing hangs.
Fix: Track Claude PID globally and kill it in the cleanup handler.
4. Live output only shows tool names, not details
The jq filter only shows
⚡ [ToolName]without showing what the tool is actually doing.Fix: Enhanced jq filter to show tool inputs as they stream.
Steps to Reproduce
ralph --monitorfrom another terminalThe Fix
See PR #153 for the complete fix. Key changes to
ralph_loop.sh:Environment