◉CLAUDE LABJP
●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…
Articles/Claude Code
⟐ Claude Code/2026-07-18Advanced

I Stopped the Headless Claude Code Job, but the Build Kept Running — Designing Teardown Around exit 143

In headless mode, a SIGTERM received while Claude Code was mid-Bash used to orphan the command's process tree. The 2.1.212 fix changes that to a clean exit 143. Here is how to redesign your supervisor and cleanup around that contract.

Claude Code264headless14SIGTERMautomation109process management

✦ Premium Article

As an indie developer, I was running a nightly maintenance job for one of my apps and stopped it by hand one morning. I typed systemctl stop, the prompt returned immediately, and I moved on. A few hours later a disk-usage alert fired on the VM. When I looked, a single next build process that the job had spawned was still alive, holding onto the CPU. Its parent was gone, but the child kept running. It was still holding a port, too, so the next scheduled session failed to bind and quietly did nothing.

The stop command had succeeded. What had failed was the stop reaching the child. This article walks through what actually happened when a headless (-p / SDK) Claude Code process was stopped mid-Bash, how Claude Code 2.1.212 changed it, and how to rebuild your supervisor and cleanup around the new exit 143 contract — in the order I hit each piece.

The job I stopped kept eating CPU

First, what exactly was orphaned. A headless Claude Code process launches a shell as a child whenever it calls the Bash tool. That shell launches npm run build, and the build launches its own workers. The tree gets deep.

LayerProcessRole
Parentclaude (headless)Runs the turn, calls tools
Childbash -cShell for the tool call
Grandchildnpm / nodeThe actual build or test
Great-grandchildworker threadsWhere the CPU actually goes

What systemctl stop and timeout send by default is a single SIGTERM to the parent. The parent claude receives it and tries to wind the turn down. The problem: if the parent exits before explicitly ending the child tree, the grandchildren lose their parent, get reparented to init (PID 1) as orphans, and keep running. The build does not stop, the port is not released, and the temporary intermediate files keep filling the disk.

That is exactly what I hit, and the nasty part is that the stop command's exit code was 0. From the supervisor's point of view, it had worked.

Why orphaning happens — signals do not reach a process group automatically

This part is not specific to Claude Code; it is plain Unix, but it is the heart of the problem. kill <pid> and a default SIGTERM reach only the single PID you name. They are not automatically propagated to descendants.

There are two ways to propagate. One is to send to the whole process group with kill -TERM -<pgid> (a leading minus makes the number a process group ID). The other is for the parent itself to walk its descendants inside its SIGTERM handler and end them before exiting.

Before the fix, headless Claude Code was missing that "clean up descendants before exiting" step for the case where it was stopped mid-Bash. The parent shut down politely while the grandchildren were left behind. So in any environment where the supervisor was not holding KillMode itself, orphans slipped right through.

How you send itWhat it reachesGrandchildren
kill -TERM <pid>Only that PIDMay be left behind
kill -TERM -<pgid>The whole groupReached together
Parent kills descendants in handlerWhat the parent walksDepends on the parent
✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Why SIGTERM does not reach a process group on its own, and the interrupt / tree-kill / exit 143 contract introduced in 2.1.212
✦Before/After code that rewrites the timeout and systemd supervisor around exit 143
✦A verification step to confirm no orphans remain, and how the work splits with SessionEnd hooks
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Claude Code2026-08-09
One Transient 401 Replaced My Long-Lived Token — Giving Credentials a Provenance Field
A shared credential file can lose its long-lived token to a single transient 401. I injected exactly one 401 into a 24-worker fleet, measured the blast radius, and compared a provenance guard against full isolation.
⟐ Claude Code2026-09-02
Two hooks that record every model switch and stop the ones you never agreed to
Build a PostModelSwitch hook that logs every model change and a PreModelSwitch hook that blocks unapproved switches during unattended runs. Complete scripts, measured timings, and the reason the two jobs must stay separate.
⟐ Claude Code2026-08-31
Half of My Scheduled Runs Vanished Without a Single Error
A batch job set to run twice a day was only firing once. No errors, no failure alerts. Here is how to expand your own schedule, count expected runs, and reconcile them against execution records to catch silent misses.