Feature Request: Support for spawning fresh-context sessions from Stop hooks
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
claudeprocess - Access
/dev/ttyfor 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:
- End the current session
- Start a new session with fresh context
- 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
- Ralph Wiggum loops - Iterative AI development with fresh context each iteration
- Long-running tasks - Prevent context overflow on tasks with many iterations
- Reproducible testing - Ensure each run starts from clean state
Related
- Plugin issue: https://github.com/anthropics/claude-plugins-official/issues/125
- Closed PR attempt: https://github.com/anthropics/claude-plugins-official/pull/126
- Original technique: https://ghuntley.com/ralph/
Environment
- Claude Code version: 2.0.76+
- Plugin: ralph-wiggum
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗