Problem
When Claude Code starts a long-running process via the Bash tool with nohup ... &, it gets tracked as a background task. When the session ends, compacts, or runs out of context, all tracked background tasks are automatically SIGTERM'd — including processes that are meant to run indefinitely (bots, daemons, supervisors, workers).
There's no way for the agent to mark a process as "don't kill on cleanup." The only workaround is to never start long-running processes through Claude Code at all, which defeats the purpose of having a shell.
Real-world scenario
I use Claude Code to manage a multi-project orchestration system with:
- A Telegram bot (
node dist/bot/index.js)
- A supervisor daemon (
node dist/daemon/supervisor.js)
- Worker processes (
node dist/daemon/worker.js)
When I ask Claude Code to restart these after a code change, it starts them via nohup node ... &. Hours later, when the conversation context fills up and compacts, session cleanup kills all three — taking down my entire system silently.
Proposed solution
One or more of:
persistent: true flag on Bash tool — marks a background process as long-lived, excluded from session cleanup
- Process name/pattern allowlist in settings (e.g.,
~/.claude/settings.json) — processes matching the pattern survive cleanup
- Don't kill background processes on context compaction — only kill on explicit session end (
/exit), not on automatic compaction
detach: true flag — fully detaches the process from Claude Code's process tree so it's not tracked at all
Current workaround
Tell the user to start long-running processes from a separate terminal, never through Claude Code. This works but is a poor UX when the agent is otherwise capable of managing the full lifecycle.
Problem
When Claude Code starts a long-running process via the Bash tool with
nohup ... &, it gets tracked as a background task. When the session ends, compacts, or runs out of context, all tracked background tasks are automatically SIGTERM'd — including processes that are meant to run indefinitely (bots, daemons, supervisors, workers).There's no way for the agent to mark a process as "don't kill on cleanup." The only workaround is to never start long-running processes through Claude Code at all, which defeats the purpose of having a shell.
Real-world scenario
I use Claude Code to manage a multi-project orchestration system with:
node dist/bot/index.js)node dist/daemon/supervisor.js)node dist/daemon/worker.js)When I ask Claude Code to restart these after a code change, it starts them via
nohup node ... &. Hours later, when the conversation context fills up and compacts, session cleanup kills all three — taking down my entire system silently.Proposed solution
One or more of:
persistent: trueflag on Bash tool — marks a background process as long-lived, excluded from session cleanup~/.claude/settings.json) — processes matching the pattern survive cleanup/exit), not on automatic compactiondetach: trueflag — fully detaches the process from Claude Code's process tree so it's not tracked at allCurrent workaround
Tell the user to start long-running processes from a separate terminal, never through Claude Code. This works but is a poor UX when the agent is otherwise capable of managing the full lifecycle.