Skip to content

Background process termination crashes Claude Code in Docker containers #16135

@viswa-abe

Description

@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)
    
  3. Press to view background tasks, then k to kill the process
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:linuxIssue specifically occurs on Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions