Skip to content

Session continuity can hijack active Claude Code sessions #151

@dionny

Description

@dionny

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

  1. Open a Claude Code session in a terminal and start working
  2. In that same session (or same directory), run any ralph command
  3. Ralph saves the current session ID
  4. Run ralph --monitor from another terminal
  5. Ralph resumes the user's active session instead of starting fresh
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: P1High - Core features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions