Skip to content
Back to skills

Process Hygiene

ASecurity

Clean up after a killed build, a hung test, an OOMed job or a crashed session without touching anyone else's work — find and stop only your own processes and containers, run the session reaper's dry run, sweep stale `gh run` watch loops and orphaned `tail -f` watchers. Use after any abnormal termination, before re-running a crashed job, when a machine has leftover processes, or when a work block ends with background watchers still running.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 23, 2026
ai-agentsgobashnodedockergitapi

Works with

  • api

Security analysis

A100/100

Scanned November 23, 2026

npx -y skills add chipi/agentic-ai-homelab --skill process-hygiene --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Process Hygiene?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Process Hygiene
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/chipi-process-hygiene/badge)](https://www.skillsdirectory.com/skills/chipi-process-hygiene)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: process-hygiene
description: Clean up after a killed build, a hung test, an OOMed job or a crashed session without touching anyone else's work — find and stop only your own processes and containers, run the session reaper's dry run, sweep stale `gh run` watch loops and orphaned `tail -f` watchers. Use after any abnormal termination, before re-running a crashed job, when a machine has leftover processes, or when a work block ends with background watchers still running.
---

# process-hygiene

Killed builds, hung tests and OOMed ML jobs leave orphan processes behind (on macOS especially). Clean them
up before re-running, and clean up only what is yours: on a shared workstation other checkouts, projects
and agents run the same `node`, `vite` and `playwright` binaries.

## What is yours

- A PID or process group you captured when you started it.
- A checkout-scoped mechanism: `docker compose` in that checkout, the repo's own cleaner.
- Never `pkill`, `killall` or `pkill -f <pattern>`.
- `pgrep -f <pattern>` also matches your own checking command (its command line contains the pattern).
  Confirm a PID with `ps -o pid,args -p <pid>` before calling it a leftover, or use a pattern that cannot
  match itself (`pgrep -f '[e]vh run'`).
- Docker: compose-project scoped only; never `docker system/volume/image prune`.

Full rules: `workstation/DEVELOPER-SETUP.md`, "Multi-agent safety rules".

## The session reaper

A global `SessionEnd` hook, `~/.claude/hooks/session-reap.sh`, runs when any session ends:

- It reaps that session's tool processes.
- It sweeps runaway `gh run` poll loops (`while true; do gh run …; done` CI watchers that leak when a
  session dies and poll the GitHub API for days).
- It sweeps orphaned `tail -f <file> | grep …` watchers whose session and file are gone.
- It is family-scoped by project-name prefix (on the Linux workstation, `/work/<project>/`): an `orrery`
  session never touches a `podcast` process.

Run it by hand, dry run first:

```bash
SESSION_REAP_DRY_RUN=1 bash ~/.claude/hooks/session-reap.sh <dir>   # what it would stop
bash ~/.claude/hooks/session-reap.sh <dir>                          # stop them
```

In a repo, `bash scripts/cleanup-worktree.sh [--stale-loops] [--dry-run]` is the per-repo cleaner.

## Habits that keep it clean

- Stop a background `tail -f` watcher by PID when you are done with it.
- Never background a `gh run` watch loop without a bound: `for i in $(seq …)`, not `while true`.
- At the end of a work block, check for your own leftovers.

Safety gates, env knobs (`SESSION_REAP_MAX_LOOP_AGE`, `SESSION_REAP_NO_LOOP_SWEEP`), the family rule and
known gotchas: `~/.claude/hooks/README.md`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.