Agent Recursion Depth Exceeded Fix (2026)
The Error
Error: Maximum agent recursion depth exceeded (depth: 10)
Subagent spawned subagent which spawned subagent — circular delegation detected.
Aborting to prevent infinite loop.
This appears when a Claude Code agent delegates a task to a subagent, which then delegates back or spawns further subagents, creating a recursive chain that exceeds the maximum depth.
The Fix
claude --max-turns 5 "Fix the bug in auth.ts"
- Use
--max-turnsto limit how many turns Claude Code can take, which caps recursion depth. - If using the Agent tool in a CLAUDE.md or custom workflow, ensure tasks are specific enough that subagents do not re-delegate.
- Restart the session with a clearer, more targeted prompt that does not require multi-level delegation.
Why This Happens
Claude Code’s agent architecture allows spawning subagents for complex tasks. When the task description is vague (like “fix all issues”), a subagent may interpret its subtask as equally broad and spawn its own subagent. Each level adds to the recursion depth until the safety limit triggers. This is especially common with custom hooks or skills that invoke Claude Code recursively.
If That Doesn’t Work
Disable subagent spawning entirely for the current task:
claude --disallowedTools "Agent" "Fix the bug in auth.ts"
Break the task into explicit sequential steps:
claude "Step 1: Read auth.ts. Step 2: Identify the null check bug on line 45. Step 3: Fix only that line."
Check for recursive hooks that might be triggering agent loops:
cat .claude/settings.json | grep -A5 "hooks"
Prevention
# CLAUDE.md rule
Never delegate tasks to subagents that are broader than the original task. Always specify exact files and line numbers when possible. Use --max-turns 10 for automated pipelines.
Related
- process exited with code 1 fix — How to fix Claude Code process exited with code 1 error
Frequently Asked Questions
Does this error affect all operating systems?
This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.
Will this error come back after updating Claude Code?
Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.
Can this error cause data loss?
No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.
How do I report this error to Anthropic if the fix does not work?
Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.
Related Error Messages
This fix also applies if you see variations of this error:
- Connection or process errors with similar root causes in the same subsystem
- Timeout variants where the operation starts but does not complete
- Permission variants where access is denied to the same resource
- Configuration variants where the same setting is missing or malformed
If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.
Set it up → Build your permission config with our Permission Configurator.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.