[BUG] Bash tool sends SIGTERM instead of SIGINT when cancelling commands, corrupting build state
Summary
When Claude Code cancels a running Bash command (timeout or user interruption), it sends SIGTERM directly. Build tools like ninja and make are designed to handle SIGINT gracefully — they finish the current write, flush state files, and exit cleanly. SIGTERM bypasses this, corrupting binary state files like .ninja_deps and .ninja_log.
Problem
Ninja writes dependency information to .ninja_deps via fwrite(). When SIGTERM kills the process mid-write, the file ends up with a truncated record. On the next build, ninja reports:
ninja: warning: premature end of file; recovering
This loses dependency tracking information, causing unnecessary full rebuilds that can take significant time on large C++ projects. The only recovery is ninja -t recompact (if the file isn't too corrupted) or deleting the deps files and doing a full rebuild.
This affects any build system that relies on graceful shutdown to flush state: ninja, make, cargo, etc.
Expected behavior
Claude Code should use the standard signal escalation that terminals use:
- SIGINT first — equivalent to Ctrl+C. Build tools catch this, finish current I/O, and exit cleanly.
- Wait briefly (1–2 seconds) for the process to exit.
- SIGTERM if the process is still running.
- SIGKILL as a last resort.
This is what happens when a user presses Ctrl+C in a terminal, and it's what build tools are designed for.
Current behavior
Claude Code sends SIGTERM immediately (and there's a known issue #45717 where it hits the entire process group). There is no hook or setting to change the signal or the escalation sequence.
Workaround
After an interrupted build, run ninja -t recompact to repair the deps log without a full rebuild. There is no way to prevent the corruption proactively.
Environment
- Claude Code on Linux (Fedora 43)
- Ninja build system via CMake
- Large C++ project where full rebuilds are expensive
Related issues
- #45717 — SIGTERM propagation kills Claude Code itself, not just the child
- #7841 — Feature request for a
signalparameter on the Bash tool - #29096 — Graceful shutdown signal for headless sessions
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗