Skip to content

Claude subprocess exits immediately on SIGINT/SIGTERM (exit code -2) – prevents graceful shutdown #610

@cx-ben-alvo

Description

@cx-ben-alvo

Description

When my service receives SIGINT or SIGTERM, it stop consuming new messages and wait for the running flows to complete (graceful shutdown pattern).
However, the signal propagates to the Claude Code subprocess spawned by the Claude Agents SDK, causing it to exit immediately with exit code -2 (SIGINT). This interrupts the in-flight agent task.

Expected Behavior
When the parent process receives a shutdown signal:
Stop accepting new work
Allow the current agent task to complete
Exit cleanly

The Claude subprocess should not terminate immediately.

Is there:
A way to prevent signal propagation to the Claude subprocess?
A graceful shutdown mode?
A recommended pattern for long-running agent workers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions