Feature Request: Support for spawning fresh-context sessions from Stop hooks

Resolved 💬 3 comments Opened Jan 6, 2026 by KLIEBHAN Closed Jan 9, 2026

Summary

Request for a mechanism to spawn a fresh Claude session (with cleared context) from within a Stop hook. This is needed to implement the original Ralph Wiggum technique correctly.

Background

The original Ralph technique uses an external Bash loop:

while :; do cat PROMPT.md | npx --yes @sourcegraph/amp ; done

Each iteration is a new process with fresh context. The ralph-wiggum plugin attempts to replicate this using Stop hooks, but currently the context accumulates instead of resetting.

The Problem

Stop hooks run in a non-terminal context (-t 0 is always false), making it impossible to:

  • Spawn an interactive claude process
  • Access /dev/tty for terminal I/O
  • Start a new session that takes over the terminal

We tried:

nohup claude "$PROMPT" </dev/tty >/dev/tty 2>&1 &

This fails because the hook has no TTY access.

Proposed Solutions

Option A: New Hook Return Field

Allow Stop hooks to return a field that signals "spawn fresh session":

{
  "decision": "block",
  "spawnFreshSession": true,
  "freshSessionPrompt": "The prompt for the new session",
  "freshSessionSystemMessage": "Optional system message"
}

Claude Code would then:

  1. End the current session
  2. Start a new session with fresh context
  3. Inject the provided prompt as the first user message

Option B: CLI Flag

Add a flag like --fresh-context or --clear-on-start:

claude --fresh-context "prompt here"

This would start a completely fresh session (no conversation history) but with the given prompt.

Option C: Session Control API

Expose an API or hook mechanism to control session context:

  • Clear context between iterations
  • Query current context size
  • Trigger context compaction

Use Cases

  1. Ralph Wiggum loops - Iterative AI development with fresh context each iteration
  2. Long-running tasks - Prevent context overflow on tasks with many iterations
  3. Reproducible testing - Ensure each run starts from clean state

Related

Environment

  • Claude Code version: 2.0.76+
  • Plugin: ralph-wiggum

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗