-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
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
- Run Claude Code inside a Docker container
- 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) - Press
↓to view background tasks, thenkto kill the process - 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 viadocker exec - Tried
script -q -c "claude ..." /dev/null- still crashes - Tried
setsid claude ...- Claude loses terminal input - Only
setsidon the child processes works, but loses monitoring