Background process termination crashes Claude Code in Docker containers

Open 💬 15 comments Opened Jan 3, 2026 by viswa-abe

When running Claude Code inside a Docker container, killing background processes (either manually with k or when Claude autonomously decides to kill them) causes Claude Code itself to crash with exit code 137 (SIGKILL).

Environment

  • Claude Code v2.0.76
  • Running inside Docker container (python:3.12-slim base)
  • Container started via docker exec -it <container> /bin/bash

Steps to Reproduce

  1. Run Claude Code inside a Docker container
  2. Start a background process using Claude's built-in background feature:

``
> start the backend server
● Bash(uvicorn api:app --port 8000) timeout: 10m
⎿ Running in the background (↓ to manage)
``

  1. Press to view background tasks, then k to kill the process
  2. Claude Code exits/crashes immediately

Expected Behavior

Claude Code should kill only the background process and continue running.

Actual Behavior

Claude Code crashes with exit code 137 (SIGKILL). The signal sent to kill the background process also kills Claude itself.

Root Cause Analysis

The issue appears to be that Claude Code and its spawned background processes share the same process group. When Claude sends a signal to kill the process group (e.g., kill -PGID), it kills itself too.

Workaround

Manually using setsid to isolate background processes works:

setsid uvicorn api:app --port 8000 > /tmp/server.log 2>&1 &

However, this loses Claude's background process monitoring and notification features.

Suggested Fix

Claude Code should spawn background processes in isolated process groups using setsid or setpgid() internally, while maintaining its monitoring wrapper. This would prevent signal propagation while preserving the background task management UI.

Additional Context

  • Tried docker run --init - doesn't help since Claude runs via docker exec
  • Tried script -q -c "claude ..." /dev/null - still crashes
  • Tried setsid claude ... - Claude loses terminal input
  • Only setsid on the child processes works, but loses monitoring

View original on GitHub ↗

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