Background dev servers not cleaned up when session transitions to new tasks

Resolved 💬 2 comments Opened Jan 3, 2026 by jmhunter83 Closed Jan 3, 2026

Description

When Claude starts a long-running dev server (like wrangler dev) as a background task, it doesn't clean up the process when:

  1. The conversation transitions to an unrelated task
  2. The session ends

This results in orphaned processes consuming significant resources (in my case, 89% CPU and 2.5GB RAM over 2 days).

Steps to Reproduce

  1. Ask Claude to start a local dev server (e.g., "start the dev server for me")
  2. Claude runs wrangler dev as a background task
  3. Confirm the server is working ("looks good")
  4. Ask Claude to do something else ("let's commit")
  5. End the session

Expected: Claude kills the background dev server before moving to the new task or ending the session

Actual: The workerd process continues running indefinitely in the background

Environment

  • Claude Code version: 2.0.76
  • Model: claude-haiku-4-5-20251001
  • OS: macOS (Darwin 25.2.0)
  • Dev server: Wrangler/Cloudflare Workers

Evidence from session logs

# Dev server started as background task
"command":"wrangler dev"
"backgroundTaskId":"b26cb91"
timestamp: 2026-01-03T03:33:07.549Z

# Claude checked output, confirmed running
"task_id":"b26cb91"
"status":"running"
"[wrangler:info] Ready on http://localhost:8789"

# Session moved to commit without KillShell
# No KillShell call found for b26cb91

Process ran for 2+ days:

jmhunter  14016  89.1 15.2 452917440 2558160  ??  RN  Thu09PM 905:36.41 workerd serve...

Suggested Fixes

  1. Model behavior: Prompt/train model to kill dev servers before transitioning to unrelated tasks
  2. Session cleanup: Add automatic cleanup of background tasks when session ends
  3. User warning: Alert user about orphaned background processes at session end
  4. Dev server awareness: Special handling for known dev server commands (wrangler dev, npm run dev, etc.)

Impact

  • High CPU/memory consumption from orphaned processes
  • Users may not realize processes are still running
  • Can accumulate multiple orphaned servers over time

View original on GitHub ↗

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