[BUG] Calling `claude -p` from a `SessionEnd` hook can recursively create child sessions that trigger hooks again

Resolved 💬 2 comments Opened Apr 14, 2026 by ekzm8523 Closed May 24, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

An end-of-session automation in my local Claude Code setup appears to trigger claude -p as a child run, and that child run appears to participate in the normal Claude Code lifecycle again.

The result is recursive session creation:

  • a parent session ends
  • a SessionEnd hook or similar automation launches claude -p
  • the child run creates its own new root Claude Code session
  • that child session ends
  • the same hook fires again
  • another claude -p run is created

In my environment this caused a large number of new root session files under ~/.claude/projects/-Users-minjaewon, and the generated sessions were not normal user conversations. They were mostly meta-prompts asking Claude Code to summarize earlier sessions.

The prompt bodies also became recursively nested.

This eventually escalated into context and usage failures.

Observed impact:

  • 5996 total JSONL files including nested entries
  • 373 root sessions created within the most recent hour during investigation
  • many recent sessions started with queue-operation: enqueue
  • recent failures included Extra usage is required for 1M context
  • later follow-up sessions hit You've hit your limit

This looks like a product safety gap around child claude -p runs inheriting hooks or participating in lifecycle automation without a guard.

What Should Happen?

Claude Code should not allow lifecycle hooks or end-of-session automations to recursively re-trigger indefinitely on child claude -p executions.

Expected behavior would be one of:

  • child claude -p runs do not trigger the same lifecycle hooks by default
  • there is an official --no-hooks or equivalent mode for child runs
  • Claude Code detects repeated self-similar queue-generated meta sessions and stops the loop
  • Claude Code adds a circuit breaker for rapid repeated SessionEnd-spawned runs

At minimum, there should be a safe default that prevents recursive session explosions and prompt self-nesting from consuming context and usage.

Steps to Reproduce

  1. Configure a Claude Code environment with lifecycle hooks enabled, including a SessionEnd hook.
  2. Make the SessionEnd automation invoke claude -p to summarize or post-process the just-finished session.
  3. Let the original session end.
  4. Observe that the child claude -p execution creates a new root Claude Code session instead of behaving as an isolated helper call.
  5. If the child run is also subject to the same lifecycle hooks, observe that ending the child run triggers the same SessionEnd automation again.
  6. Repeat for several generations.
  7. Observe:
  • rapid creation of many new root session files
  • queue-style sessions with meta-only prompts
  • recursive prompt nesting if earlier transcript or summary content is re-inserted
  • eventual context or usage exhaustion

A simplified reproduction shape is:

  1. SessionEnd hook fires
  2. hook runs claude -p "<summarize previous session>"
  3. child run creates a new Claude Code session artifact
  4. child run ends
  5. child's SessionEnd fires
  6. same hook runs again
  7. recursion continues

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

2.1.104

Claude Code Version

2.1.104

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

_No response_

View original on GitHub ↗

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