[BUG] When a background agent spawns its own `run_in_background: true` bash process, that process becomes orphaned when the agent exits.
Resolved 💬 3 comments Opened Jan 12, 2026 by etrippler Closed Mar 5, 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?
When a background agent spawns its own run_in_background: true bash process, that process becomes orphaned when the agent exits.
What happened:
- Spawned background haiku agent with prompt "poll pd-check.sh every 60s"
- Agent created a bash while true loop calling pd-check.sh
- Agent ran that loop with run_in_background: true (nested backgrounding)
- Agent said "polling started" and exited
- Main thread received <task-notification> that agent completed
- Bash loop (b504a70) continued running independently - no one watching
Orphaned bash process writing to a file nobody reads. Main thread loses track of it. Agent exited thinking its job was done.
What Should Happen?
- Subagent shouldn't be able to background things.
- Or: background processes spawned by background agents should be tracked/surfaced to main thread
Error Messages/Logs
⏺ Exactly. Here's what happened step by step:
1. I spawned haiku agent with "poll pd-check.sh every 60s"
2. Agent read pd-check.sh to understand it (one-shot script)
3. Agent wrote its own bash while true loop wrapping pd-check.sh
4. Agent ran that loop with run_in_background: true
5. Agent said "polling started" and exited
6. Background bash process (b504a70) continues independently
So haiku essentially recreated what pd-monitor.sh does - it wrote its own polling wrapper around the one-shot script.
The irony: we have pd-monitor.sh sitting there unused because haiku built its own equivalent on the fly.
Two options:
1. Keep pd-monitor.sh - for manual terminal use, or if you want to run monitoring without spawning an agent
2. Delete pd-monitor.sh - trust that haiku will always create a sensible loop
The agent approach is actually more flexible - haiku can adapt the loop logic (different intervals, smarter detection) based on the prompt. The static script is more predictable.
❯ I think the agent is better because right now from the perspective of this Claude code window, I don't have any access to bash script and there's nobody checking it. You would have to check it. So I think the whole point of this was that an agent checks it and looks
at the result and then reports asynchronously back to this thread, the main thread, if it finds something. Now I think we could do that. Yeah, we could actually do this without even a sub-agent, right? We could just have it running here in the background, but you
would have to check it then every now and then.
Steps to Reproduce
Pretty easy, just ask for a subagent to background a process.
Claude Model
Not sure / Multiple models
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.5
Platform
Google Vertex AI
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗