Skip to content

fix: prevent SIGINT/SIGTERM propagation to Claude subprocess#617

Open
Br1an67 wants to merge 1 commit intoanthropics:mainfrom
Br1an67:fix/issue-610-sigint-propagation
Open

fix: prevent SIGINT/SIGTERM propagation to Claude subprocess#617
Br1an67 wants to merge 1 commit intoanthropics:mainfrom
Br1an67:fix/issue-610-sigint-propagation

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

When the parent process receives SIGINT or SIGTERM, the signal propagates to the Claude CLI subprocess, causing it to exit immediately (exit code -2). This breaks graceful shutdown patterns where the parent stops accepting new work while allowing in-flight agent tasks to complete.

Fixes #610

Changes

Add start_new_session=True to the anyio.open_process() call in SubprocessCLITransport._start_process(). This puts the Claude CLI subprocess in its own process group so it does not receive signals sent to the parent's process group.

The SDK already terminates the subprocess explicitly via Process.terminate() in the close() method, so normal cleanup is unaffected.

Testing

  • All 160 existing tests pass
  • ruff check passes with no issues
  • Backward-compatible — only affects signal handling, no behavior change for normal operation

Add start_new_session=True to the open_process call so the Claude CLI
subprocess runs in its own process group. This prevents signals like
SIGINT and SIGTERM from propagating from the parent process to the
subprocess, allowing graceful shutdown patterns where the parent stops
accepting new work while the current agent task completes.

The SDK already terminates the subprocess explicitly in its close()
method, so this change does not affect normal cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant