Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
By alleneubankv0.3.1MITIn 1 marketplace
Wrap the Bash tool with janitor so processes a Claude Code session starts are drained when the session ends.
Run automatically on Claude Code events. Claude doesn't decide.
1 caution to review before installing
A hook runs when Claude uses the Bash tool
Static checks of hooks, mods, MCP servers and commands. Not a security audit.
1 marketplace, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Wraps the Claude Code Bash tool so that any process a session starts is
supervised by janitor and drained
when the session goes away — including a normal exit, /clear, a crash, or the
terminal window being closed. No per-command effort, no orphaned dev servers,
watchers, or daemons holding ports and files after the session is gone.
A PreToolUse hook on the Bash tool transparently rewrites each command to:
janitor --watch-path '<session-lock>' --watch-pid '<claude-pid>' --grace-ms <ms> -- bash -c '<your command>'
--watch-path is a per-session lock file; a SessionEnd hook removes it on a
clean exit, which tells janitor to drain.--watch-pid is the Claude session process id. If the session dies hard
(crash / SIGKILL / closed terminal) so no SessionEnd runs, janitor still
sees that pid exit and drains the process group anyway. This matters because a
Bash command runs under a per-command shell that survives the session, so
watching the session pid directly is the only reliable crash trigger.On teardown, janitor sends SIGTERM to the original command process group,
then drains live descendants whose identity it can prove. Processes already
reparented before capture and targets that fail identity verification are
skipped with a diagnostic, so they are outside that guarantee.
Your command's stdout/stderr, exit code, and run_in_background behavior are
unchanged; janitor is transparent.
Worktree-isolated sessions (EnterWorktree or claude --worktree) are not
wrapped: Claude Code's isolation guard refuses any wrapper that hands a shell a
-c string, so the hook passes commands through unmodified there instead of
blocking them. Processes started inside such a session are not drained.
Install janitor and make sure it is on your PATH:
curl -fsSL https://raw.githubusercontent.com/alleneubank/janitor/main/install.sh | sh
(Default install location is ~/.local/bin/janitor.)
Install this plugin from the Claude Code plugin marketplace:
/plugin marketplace add alleneubank/janitor
/plugin install janitor-bash-drain@janitor
The hooks fail open: if janitor is not installed or not on PATH, the
hook is a no-op and your command runs unmodified. Nothing this plugin does can
block or corrupt a Bash command.
Configure via environment variables (read by janitor cc-hook). Set them in
your shell profile or project environment.
| Variable | Default | Meaning |
|---|---|---|
JANITOR_CC_ENABLED | 1 | Set 0/false to disable wrapping entirely. |
JANITOR_CC_GRACE_MS | 1500 | SIGTERM→SIGKILL grace window (ms). |
JANITOR_CC_WRAP_MODE | all | all wraps every command; background-only wraps only run_in_background commands. |
JANITOR_CC_SHELL | bash | Shell used for -c to re-run your command. |
JANITOR_CC_SKIP_PATTERNS | read-only/trivial set | Comma-separated command prefixes to skip. Default skips ls, cat, pwd, echo, which, cd, git status, git log, git diff, git show. |
JANITOR_CC_DENY_PATTERNS | (empty) | Comma-separated command prefixes to never wrap. |
Read-only/trivial commands and commands that already start with janitor are
never wrapped (no double-wrapping, no overhead where it isn't needed).
macOS and Linux only. On Windows — and whenever janitor is absent — the hook
is a no-op and commands run unmodified.
Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
npx claudepluginhub alleneubank/janitor --plugin janitor-bash-drainPlugins from other owners that cover similar ground