Background task cleanup kills long-running processes started via Bash tool

Resolved 💬 3 comments Opened Feb 12, 2026 by gocon-loca Closed Feb 15, 2026

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:

  1. persistent: true flag on Bash tool — marks a background process as long-lived, excluded from session cleanup
  2. Process name/pattern allowlist in settings (e.g., ~/.claude/settings.json) — processes matching the pattern survive cleanup
  3. Don't kill background processes on context compaction — only kill on explicit session end (/exit), not on automatic compaction
  4. 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.

View original on GitHub ↗

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