claude-bulkhead 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -0
- package/LICENSE +21 -0
- package/README.es.md +590 -0
- package/README.ja.md +590 -0
- package/README.ko.md +590 -0
- package/README.md +589 -2
- package/README.pt-BR.md +590 -0
- package/README.zh-CN.md +590 -0
- package/bin/bulkhead +3 -0
- package/bin/bulkhead-slot +3 -0
- package/bin/bulkhead-statusline +3 -0
- package/hooks/hooks.json +99 -0
- package/package.json +55 -4
- package/src/agent-hook.js +162 -0
- package/src/agent-setup.js +256 -0
- package/src/agents.js +89 -0
- package/src/allow-cli.js +65 -0
- package/src/allow-hint.js +62 -0
- package/src/allow-once.js +152 -0
- package/src/auto-queue.js +93 -0
- package/src/bash-guards.js +36 -0
- package/src/basics.js +255 -0
- package/src/checkout-guard.js +564 -0
- package/src/cli-util.js +91 -0
- package/src/cli.js +77 -0
- package/src/config-check.js +46 -0
- package/src/config-cli.js +116 -0
- package/src/config.js +333 -0
- package/src/dev-servers.js +523 -0
- package/src/disk-guard.js +200 -0
- package/src/doctor-enforcement.js +273 -0
- package/src/doctor.js +265 -0
- package/src/edit-guard.js +196 -0
- package/src/events.js +133 -0
- package/src/explain.js +251 -0
- package/src/git-info.js +55 -0
- package/src/gitargs.js +82 -0
- package/src/hook.js +126 -0
- package/src/kill-extras.js +219 -0
- package/src/kill-guard.js +586 -0
- package/src/kill-owners.js +116 -0
- package/src/log-cli.js +151 -0
- package/src/mcp.js +131 -0
- package/src/memory-guard.js +247 -0
- package/src/memory.js +95 -0
- package/src/notices.js +95 -0
- package/src/orphan-reaper.js +574 -0
- package/src/paths.js +31 -0
- package/src/port-cli.js +134 -0
- package/src/port-guard.js +154 -0
- package/src/port-kills.js +198 -0
- package/src/pressure.js +75 -0
- package/src/processes.js +213 -0
- package/src/reap-cli.js +56 -0
- package/src/remote-sh.js +478 -0
- package/src/remote.js +1034 -0
- package/src/remotes.js +126 -0
- package/src/scan-report.js +166 -0
- package/src/scan.js +673 -0
- package/src/secrets-guard.js +301 -0
- package/src/self-allow.js +73 -0
- package/src/session-info.js +121 -0
- package/src/session-state.js +176 -0
- package/src/sessions.js +236 -0
- package/src/shell.js +857 -0
- package/src/slot-cli.js +221 -0
- package/src/slots.js +216 -0
- package/src/stable-port.js +61 -0
- package/src/status.js +149 -0
- package/src/statusline.js +98 -0
- package/src/subagent-guard.js +24 -0
- package/src/top-worker.js +14 -0
- package/src/top.js +330 -0
- package/src/wait-guard.js +327 -0
- package/src/worktree-cli.js +454 -0
- package/src/worktree-copy.js +82 -0
package/README.md
CHANGED
|
@@ -1,3 +1,590 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">claude-bulkhead</h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Stop Claude Code from running <code>pkill node</code> on your other dev servers, taking their ports, and committing another session's edits with <code>git add -A</code>.</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">Hooks that know which processes, ports and git trees belong to which Claude Code session and subagent, so they block only what would hurt something else, and tell Claude the safe command to run instead.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">Windows, macOS and Linux. No tmux, no sudo, no background daemon, no network calls, no dependencies. Also guards Codex, Gemini CLI, Copilot CLI, Cursor and six more agents.</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/dooly6276/claude-bulkhead/actions/workflows/test.yml"><img src="https://github.com/dooly6276/claude-bulkhead/actions/workflows/test.yml/badge.svg" alt="tests"></a>
|
|
13
|
+
<img src="https://img.shields.io/badge/node-18%2B-34d6b4?style=flat-square" alt="Node 18+">
|
|
14
|
+
<img src="https://img.shields.io/badge/dependencies-0-34d6b4?style=flat-square" alt="zero dependencies">
|
|
15
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-34d6b4?style=flat-square" alt="MIT license"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<img src="docs/demo.gif" alt="Two Claude Code sessions work on two worktrees of one app. Session A serves checkout on port 3000. Session B is told to kill all node processes and restart its search server; bulkhead's kill-guard blocks the command, Claude restarts only its own server, and checkout keeps running with the same PID." width="100%">
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p align="center"><sub><a href="README.ko.md">한국어</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a> | <a href="README.es.md">Español</a> | <a href="README.pt-BR.md">Português (Brasil)</a></sub></p>
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
Inside Claude Code:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
/plugin marketplace add dooly6276/claude-bulkhead
|
|
30
|
+
/plugin install bulkhead@bulkhead
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then see what it would have stopped in your own last month, without changing anything:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
/bulkhead:scan 30d
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Node 18 or later must be on `PATH` (the native Claude Code installer does not install it; check with `node --version`).
|
|
40
|
+
|
|
41
|
+
| Install | What you get |
|
|
42
|
+
|---|---|
|
|
43
|
+
| The plugin (above) | The guards, which run on every Bash, PowerShell, Read and Edit call; the slash commands `/bulkhead:scan`, `status`, `log`, `doctor`, `reap`, `remote`; the skill that teaches Claude the safe habits. This is the part that protects you. |
|
|
44
|
+
| `npm install -g claude-bulkhead` (optional) | The `bulkhead` command in your own terminal (`status`, `top`, `explain`, `allow`, `worktree`, `scan`, `doctor`), the status line, `bulkhead-slot`, and `bulkhead setup <agent>` for Codex, Gemini and the others. `npx claude-bulkhead status` works without installing. |
|
|
45
|
+
|
|
46
|
+
Unsure whether it is working? `bulkhead doctor` runs a harmless command through each guard and shows that it was blocked, and how long it took.
|
|
47
|
+
|
|
48
|
+
## What it stops
|
|
49
|
+
|
|
50
|
+
| Without bulkhead | With bulkhead |
|
|
51
|
+
|---|---|
|
|
52
|
+
| An agent restarts its dev server with `pkill node`, and every other worktree's server dies with it. | kill-guard blocks the command and tells the agent how to find and stop its own PID. |
|
|
53
|
+
| Two sessions share a checkout. One runs `git add -A && git commit`, and the other one's half-finished edits ship in that commit. | checkout-guard blocks it and asks for the file names. |
|
|
54
|
+
| Two worktrees run `npm run dev`. The second moves to 3001, but its agent keeps testing `localhost:3000` and sees the other branch. | port-guard blocks the second start and names a free port. |
|
|
55
|
+
| Three sessions start `next build`, `npm test` and Playwright in the same minute, and the machine freezes. | memory-guard blocks heavy commands when RAM is low. Through `bulkhead-slot`, the third job waits in a queue until there is room. |
|
|
56
|
+
|
|
57
|
+
<details>
|
|
58
|
+
<summary>Five more</summary>
|
|
59
|
+
|
|
60
|
+
| Without bulkhead | With bulkhead |
|
|
61
|
+
|---|---|
|
|
62
|
+
| A session checks out another branch in a tree that a second session is editing. | checkout-guard blocks it and suggests `git worktree add`. |
|
|
63
|
+
| A session exits, and its dev servers, test workers and watchers keep running and holding RAM and ports. | orphan-reaper stops them within seconds of the session exiting. |
|
|
64
|
+
| A subagent polls in the foreground for ten minutes. The session cannot answer you, and the prompt cache expires. | wait-guard blocks the loop and asks for `run_in_background: true`. |
|
|
65
|
+
| An agent wants to know what is using disk space and runs ten `du` at once over your home folder. Every session's builds and `git status` crawl for minutes. | disk-guard blocks it and asks for one folder at a time. |
|
|
66
|
+
| A "clean up the worktrees" task runs `git worktree remove` on a worktree a second session is still working in. | checkout-guard blocks it and names the session that is still there. |
|
|
67
|
+
|
|
68
|
+
</details>
|
|
69
|
+
|
|
70
|
+
With a single session, kill-guard, memory-guard, wait-guard, disk-guard and basics (no `rm -rf ~`, no force-push to `main`, no `reset --hard` over uncommitted work) still apply. port-guard and checkout-guard act once a second session or subagent is alive.
|
|
71
|
+
|
|
72
|
+
## What is it?
|
|
73
|
+
|
|
74
|
+
<p align="center">
|
|
75
|
+
<picture>
|
|
76
|
+
<source media="(prefers-color-scheme: light)" srcset="docs/hero-light.svg">
|
|
77
|
+
<img src="docs/hero.svg" alt="Several Claude Code sessions in separate git worktrees on one machine. kill-guard blocks pkill node, port-guard moves a second dev server to a free port, disk-guard stops ten parallel du scans, checkout-guard stops git add -A from sweeping another session's edits into a commit, and bulkhead-slot queues a third heavy job so free RAM stays above the floor. bulkhead scan then counts what it would have stopped in past sessions." width="100%">
|
|
78
|
+
</picture>
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
Claude Code hooks are small programs that Claude Code runs before every shell command, and that can stop the command and tell Claude why. bulkhead is a set of them. Before each Bash or PowerShell call it checks the command against what the other sessions on the machine are doing: which processes and ports belong to which session, how much RAM is left, and which git tree each session works in. When the command would hurt another session, it is blocked, and Claude gets a message with the safer command to run instead. Claude reads it and carries on, usually without asking you.
|
|
82
|
+
|
|
83
|
+
## Do you need it? Ask your transcripts
|
|
84
|
+
|
|
85
|
+
You do not have to guess. Claude Code keeps every session's transcript in `~/.claude/projects`, and `bulkhead scan` replays the shell commands in them against the guards: how many sessions you really run at once, and how often they already did the things bulkhead blocks.
|
|
86
|
+
|
|
87
|
+
<p align="center">
|
|
88
|
+
<picture>
|
|
89
|
+
<source media="(prefers-color-scheme: light)" srcset="docs/scan-light.svg">
|
|
90
|
+
<img src="docs/scan.svg" alt="bulkhead scan reads a month of transcripts, reports the most sessions that ran at once, and lists per guard and rule how many commands would have been stopped, in how many sessions, and how many a hook or the user already stopped." width="100%">
|
|
91
|
+
</picture>
|
|
92
|
+
</p>
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
/plugin install bulkhead@bulkhead # then, inside Claude Code:
|
|
96
|
+
/bulkhead:scan 30d
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
It only reads, masks anything that looks like a secret before printing, and sends nothing anywhere. port-guard and the low-RAM check are not replayed, because transcripts do not record which ports and how much RAM were in use; checkout-guard is rebuilt from which sessions were active in the same git tree at that minute. `bulkhead scan --share` prints a 5 to 8 line summary with counts only (no paths, no commands) that you can paste into a post or a chat, and `--explain 1` shows one example in full with the part that matched. Details: [docs/commands.md](docs/commands.md#bulkhead-scan).
|
|
100
|
+
|
|
101
|
+
## Why this exists
|
|
102
|
+
|
|
103
|
+
A common way to speed up work with Claude Code is to run several sessions on one repository, each in its own git worktree, each with its own subagents. git keeps the branches apart. The machine does not: every session shares the same ports, the same process table and the same RAM. That is where they collide.
|
|
104
|
+
|
|
105
|
+
- Two worktrees of the same app both run `npm run dev`. The second one fails on port 3000, or quietly moves to 3001 while its agent keeps testing `localhost:3000` and sees the other branch.
|
|
106
|
+
- An agent restarts its own server with `pkill node` or `taskkill /IM node.exe` and takes down the dev servers and test runs of every other worktree, and sometimes its own session.
|
|
107
|
+
- Three sessions start `npm test`, `next build` and a Playwright run in the same minute, and the machine stops responding.
|
|
108
|
+
- A session ends and the dev servers it started keep running.
|
|
109
|
+
|
|
110
|
+
The Claude Code tracker has many reports of exactly this:
|
|
111
|
+
|
|
112
|
+
- [#13941](https://github.com/anthropics/claude-code/issues/13941): asked to restart a dev server, Claude ran `taskkill //IM node.exe` or `pkill node` and killed its own session.
|
|
113
|
+
- [#34754](https://github.com/anthropics/claude-code/issues/34754): `taskkill //F //IM python.exe` killed two long-running simulations, after the user had marked their PIDs as off limits.
|
|
114
|
+
- [#43225](https://github.com/anthropics/claude-code/issues/43225): asked to restart one bot, Claude force-killed every Python process on the machine, about 20 services.
|
|
115
|
+
- [#53229](https://github.com/anthropics/claude-code/issues/53229): told to stop only unused dev servers, an agent also killed a gateway and a Postgres process it had not identified.
|
|
116
|
+
- [#15487](https://github.com/anthropics/claude-code/issues/15487): 24 subagent processes saturated a 4 GB VPS until it had to be rebooted; a commenter froze a 24 GB Mac the same way.
|
|
117
|
+
- [#11502](https://github.com/anthropics/claude-code/issues/11502) and [#25180](https://github.com/anthropics/claude-code/issues/25180): processes started by agents outlive them, 60 Node processes in one report and 550 pytest workers in the other.
|
|
118
|
+
|
|
119
|
+
claude-bulkhead is a set of small hooks that block or clean up each of these. Each one can be turned off on its own. The name is from the bulkhead pattern: one compartment taking on water should not sink the ship.
|
|
120
|
+
|
|
121
|
+
## What it does
|
|
122
|
+
|
|
123
|
+
| | |
|
|
124
|
+
|---|---|
|
|
125
|
+
| **[kill-guard](docs/guards/kill-guard.md)**<br>Blocks `pkill node`, `taskkill /IM`, `Stop-Process -Name` and other kills by program name, and mass kills (`docker system prune`, `pkill -u`, `adb kill-server`) while another session is alive. Kills of your own processes by PID pass; `kill <pid>` of another session's process does not. | **[port-guard](docs/guards/port-guard.md)**<br>Blocks starting a dev server on a port another session already serves, and killing that session's server by port. |
|
|
126
|
+
| **[memory-guard and bulkhead-slot](docs/guards/memory-guard.md)**<br>Blocks heavy commands when RAM is low, and queues heavy jobs against one RAM budget shared by every session. | **[checkout-guard](docs/guards/checkout-guard.md)**<br>Blocks `git checkout`, `stash`, `reset --hard`, `git add -A` and similar when another live session works in the same tree, and deleting a folder another session works in. |
|
|
127
|
+
| **[wait-guard](docs/guards/wait-guard.md)**<br>Blocks foreground sleep loops longer than 3 minutes, which make the next request rewrite the whole prompt cache. | **[orphan-reaper](docs/guards/orphan-reaper.md)**<br>When a session exits, stops the dev servers, test workers, watchers and headless browsers it left running. Keep one on purpose with `BULKHEAD_KEEP=1`; tunnels and databases are kept already. |
|
|
128
|
+
| **[disk-guard](docs/guards/disk-guard.md)**<br>Blocks `du -sh ~`, `find /` without `-maxdepth`, and disk scans run in parallel, which stall the disk every session shares. | **[`bulkhead scan`](#do-you-need-it-ask-your-transcripts)**<br>Replays your past Claude Code transcripts against the guards: what they would have stopped, and how many sessions ran at once. |
|
|
129
|
+
| **[basics](docs/guards/basics.md)**<br>Blocks `rm -rf` at a root, home or a folder directly in it, force-pushes to `main`, resets that would lose uncommitted work, and commits authored as Claude. | **[`bulkhead status`, `top`, `log`, `doctor`](#see-what-is-running)**<br>Shows every session, its RAM, its ports, queued jobs, and what the guards have blocked. |
|
|
130
|
+
| **[edit-guard](docs/guards/edit-guard.md)** <sup>new</sup><br>Tells the agent when another live session edited the same file in the last 30 minutes, in this tree or another worktree of the repository. Advisory by default, no server. | **[secrets-guard](docs/guards/secrets-guard.md)** <sup>new, off by default</sup><br>Blocks reading or printing `.env`, private keys, cloud credentials and the whole environment, by the Read tool or a shell command, while `.env.example`, `ls ~/.ssh` and `.pub` files pass. |
|
|
131
|
+
| **[`bulkhead explain` and `bulkhead allow`](#when-it-blocks-something-you-meant)** <sup>new</sup><br>See what every guard would say about a command before it runs, and let one blocked command through once with the code in the block message. Claude cannot approve its own blocks. | **[`bulkhead worktree`](#worktrees-in-one-step)** <sup>new</sup><br>A new worktree in one step, with your `.env` files copied, dependencies installed and its own stable port; `prune` removes merged ones, squash merges included, and never one a session works in. |
|
|
132
|
+
| **[Auto-queue](docs/commands.md#auto-queue)** <sup>new</sup><br>With `memoryGuard.autoQueue`, heavy commands are not refused but put in line: the hook wraps them in `bulkhead-slot`, and they start when there is room. | **[Codex, Gemini and other agents](#codex-gemini-and-other-agents)** <sup>new</sup><br>The same guards for Codex, Gemini CLI, Copilot CLI, Cursor, Windsurf, Droid, Devin, Cline, opencode and Amp, set up with `bulkhead setup <agent>`. |
|
|
133
|
+
| **[Status line](#status-line)**<br>`3 sessions 2 heavy 9.1 GB free` in the Claude Code status line, in about 100 ms. | **[Config and slash commands](#configuration)**<br>Per-machine and per-project config with allow lists, plus `/bulkhead:scan`, `/bulkhead:status`, `/bulkhead:log`, `/bulkhead:doctor` and `/bulkhead:reap`. |
|
|
134
|
+
|
|
135
|
+
Optional: **[`bulkhead remote`](#run-heavy-jobs-on-another-machine-optional)** runs a test suite, a build or a browser run on another machine over SSH, when this one has no RAM to spare.
|
|
136
|
+
|
|
137
|
+
## More demos
|
|
138
|
+
|
|
139
|
+

|
|
140
|
+
|
|
141
|
+
A scripted run of `bulkhead status`, port-guard, kill-guard and wait-guard, recorded with [docs/demo.sh](docs/demo.sh). The two sessions are stand-in processes named `claude`; everything printed comes from the hook scripts and `bulkhead status`. The recording at the top of this page is a real Claude Code session; how it was made is in [docs/demo.tape](docs/demo.tape).
|
|
142
|
+
|
|
143
|
+
## Quick start
|
|
144
|
+
|
|
145
|
+
1. Install the plugin as above and start a new Claude Code session.
|
|
146
|
+
2. See what it would have caught: run `/bulkhead:scan 30d`, or `bulkhead scan` in the Bash tool. It reads your last month of transcripts and changes nothing.
|
|
147
|
+
3. Check the setup. Inside Claude Code run `/bulkhead:doctor`, or run `bulkhead doctor` in the Bash tool. Every line should say `OK`. A `WARN` or `FAIL` line names the guard and the reason. The Enforcement section at the end proves the hooks block: it runs the installed hook with a canary command and checks the exit code, the message and the latency, and it flags `disableAllHooks`, a disabled plugin or a missing `node`.
|
|
148
|
+
4. Open a terminal next to your sessions and run `npx claude-bulkhead top` (or `bulkhead top` after `npm install -g claude-bulkhead`) to watch sessions, RAM, ports and heavy jobs live. Press `q` to quit.
|
|
149
|
+
|
|
150
|
+
After that there is nothing to do. The guards run on every Bash and PowerShell call. To see what they stopped, run `bulkhead log` or `/bulkhead:log`; `bulkhead log --summary` counts blocks per guard on your machine. To change a threshold or allow a command, see [docs/configuration.md](docs/configuration.md). All commands are listed in [docs/commands.md](docs/commands.md).
|
|
151
|
+
|
|
152
|
+
## Worktrees in one step
|
|
153
|
+
|
|
154
|
+
When another session works in your tree, checkout-guard sends the agent to a worktree. A plain worktree has no `.env`, no `node_modules` and the same dev server port as the main checkout. `bulkhead worktree add` fixes those three:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
$ bulkhead worktree add fix-login
|
|
158
|
+
created ~/dev/shop-fix-login on new branch fix-login from HEAD
|
|
159
|
+
copied .env (default set)
|
|
160
|
+
pnpm install --frozen-lockfile: done in 14.2s
|
|
161
|
+
wrote PORT=3800 to .env.local
|
|
162
|
+
next: cd ~/dev/shop-fix-login && claude
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
It copies the files named in `.worktreeinclude` (the file Claude Code reads too) or a safe default set of `.env` files, never `node_modules`, build output or anything over 5 MB; installs with the project's lockfile; and gives the worktree a port that stays the same every time. `bulkhead worktree list` shows each worktree with its branch, state, live session and port. `bulkhead worktree prune` lists the ones that are merged, clean and unused, and removes them with `--yes` using `git worktree remove` and `git branch -d`, never `--force`, never a live session's folder. Details in [docs/commands.md](docs/commands.md#bulkhead-worktree).
|
|
166
|
+
|
|
167
|
+
## Run heavy jobs on another machine (optional)
|
|
168
|
+
|
|
169
|
+
When several sessions run test suites and builds at once, one machine runs out of RAM: memory-guard blocks the commands, or bulkhead-slot makes them queue (automatically, with `memoryGuard.autoQueue`). If you have a second machine that is mostly idle, `bulkhead remote` runs the heavy command there instead.
|
|
170
|
+
|
|
171
|
+
<p align="center">
|
|
172
|
+
<img src="docs/remote.svg" alt="This machine has 1.8 GB free, so memory-guard holds npm test. bulkhead remote sends only the new commit and the changed files over SSH to buildbox, the tests run there in copy a on port 7172, and the last 20 lines come back. Free RAM on this machine does not change." width="100%">
|
|
173
|
+
</p>
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
bulkhead remote add buildbox dev@192.168.1.20 --ssh-option=IdentityFile=~/.ssh/buildbox
|
|
177
|
+
bulkhead remote run -- npm test
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
[bulkhead remote] buildbox: 3f2a1c9 already there, 3 changed files (24 KB), 1 deleted
|
|
182
|
+
[bulkhead remote] buildbox copy a /home/dev/bulkhead-remote/acme-web-3f9a1c port 7172
|
|
183
|
+
...test output...
|
|
184
|
+
[bulkhead remote] exit 0 after 1m 12s (copy a)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- **What is sent.** The current commit as a git bundle (only the commits the remote does not have yet) and your uncommitted changes, deletions included. Ignored files stay here unless you name them with `--files`. Nothing outside the repository is sent.
|
|
188
|
+
- **Where it runs.** In one of up to 8 copies of the repository on the remote, so parallel runs do not share a working tree. `node_modules` is kept between runs. Each run gets its own port in `$BULKHEAD_PORT`.
|
|
189
|
+
- **Room.** Locks on the remote hold a copy and a job slot, and `--gb=N` waits until N GB is free there. When there is no room within `--wait` minutes, it exits 3.
|
|
190
|
+
- **Cleanup.** When the command ends, or the SSH connection drops (Ctrl-C, a tool timeout), everything it started on the remote is stopped, including a server left on its port.
|
|
191
|
+
- **The remote** needs only an SSH server, `bash`, `git` and `tar`. Linux, macOS and Windows with Git for Windows all work.
|
|
192
|
+
|
|
193
|
+
`bulkhead remote fetch PATH` brings files back from the copy the last run used, and `bulkhead remote status` shows each remote's free RAM and running jobs. In Claude Code, `/bulkhead:remote <command>` runs a command there in the background. Setup, options and exit codes: [docs/remote.md](docs/remote.md).
|
|
194
|
+
|
|
195
|
+
## How it works
|
|
196
|
+
|
|
197
|
+
```mermaid
|
|
198
|
+
flowchart LR
|
|
199
|
+
CC["Claude Code session"] -->|"PreToolUse: Bash, PowerShell"| G["kill-guard, wait-guard, memory-guard,<br>port-guard, checkout-guard, disk-guard, basics"]
|
|
200
|
+
CC -->|"SessionEnd, SessionStart"| R["orphan-reaper (background)"]
|
|
201
|
+
G -->|"read"| P["process table, listening ports,<br>~/.claude/sessions"]
|
|
202
|
+
G <-->|"read, append"| S[("state dir ~/.claude/bulkhead<br>slots, guards.log, events.jsonl")]
|
|
203
|
+
B["bulkhead-slot"] <--> S
|
|
204
|
+
G -->|"exit 2 + message: blocked"| CC
|
|
205
|
+
G -->|"exit 0: allowed"| CC
|
|
206
|
+
G -.->|"any error: exit 0"| CC
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Each guard is a separate Node script with no dependencies. Claude Code pipes the tool call to it as JSON. The guard reads the command text, and only when the command matches does it look further: at the process table, the listening ports, the session files Claude Code keeps in `~/.claude/sessions`, free RAM, or `git status`. A block is exit code 2 with a message that tells Claude what to do instead. Any error inside a guard lets the call through, so a broken guard never stops your work.
|
|
210
|
+
|
|
211
|
+
Every session on the machine shares one state directory. bulkhead-slot keeps its RAM reservations there, and every block is recorded there. More detail, including the state directory layout and how sessions are found on each OS, is in [docs/architecture.md](docs/architecture.md).
|
|
212
|
+
|
|
213
|
+
## Guards
|
|
214
|
+
|
|
215
|
+
Each guard has a page with the exact commands it blocks, what passes, the message Claude sees, and its limits. The short version:
|
|
216
|
+
|
|
217
|
+
<details>
|
|
218
|
+
<summary><strong>kill-guard</strong>: kills by program name</summary>
|
|
219
|
+
|
|
220
|
+
Blocks `taskkill /IM`, `taskkill /FI` without a PID, `Stop-Process -Name`, `Get-Process node | Stop-Process`, `pkill`, `killall`, `kill $(pgrep node)`, `wmic ... delete` and similar when they target a program other sessions share, such as `node`, `python`, `java`, `chrome`, `git` or `vite`. Kills by PID and by project path pass. Kills by port pass too, unless another session owns the port; port-guard checks those. Claude is told how to find its own PIDs.
|
|
221
|
+
|
|
222
|
+
Turn off: `BULKHEAD_DISABLE=kill-guard`. Details: [docs/guards/kill-guard.md](docs/guards/kill-guard.md).
|
|
223
|
+
</details>
|
|
224
|
+
|
|
225
|
+
<details>
|
|
226
|
+
<summary><strong>port-guard</strong>: ports owned by another session</summary>
|
|
227
|
+
|
|
228
|
+
Blocks starting a dev server (`npm run dev`, `next dev`, `vite`, `uvicorn`, `rails s` and more) on a port that another Claude session's process tree is listening on, and suggests a free port. It also blocks kill-by-port commands such as `npx kill-port 3000`, `fuser -k 3000/tcp` and `lsof -ti :3000 | xargs kill` when another session owns that port.
|
|
229
|
+
|
|
230
|
+
Turn off: `BULKHEAD_DISABLE=port-guard`. Details: [docs/guards/port-guard.md](docs/guards/port-guard.md).
|
|
231
|
+
</details>
|
|
232
|
+
|
|
233
|
+
<details>
|
|
234
|
+
<summary><strong>memory-guard and bulkhead-slot</strong>: RAM</summary>
|
|
235
|
+
|
|
236
|
+
memory-guard blocks heavy commands (test runners, `next build`, `tsc`, Gradle, the Android emulator, Playwright, `cargo test`, `docker build` and similar) when free RAM is under 3 GB, or under 15% of RAM on machines with less than 20 GB. `bulkhead-slot run --gb=4 -- <command>` waits until the shared RAM budget has room, runs the command, and frees the slot when it exits.
|
|
237
|
+
|
|
238
|
+
Turn off: `BULKHEAD_DISABLE=memory-guard`. Details: [docs/guards/memory-guard.md](docs/guards/memory-guard.md).
|
|
239
|
+
|
|
240
|
+
With `"memoryGuard": { "autoQueue": true }`, nobody has to remember the slot: memory-guard rewrites every heavy command (tests, builds, browser runs, container builds) to run through `bulkhead-slot`, so all sessions wait in one fair queue instead of being blocked. A waiting job prints its position every 30 seconds, and `bulkhead status` shows which session and project each queued job belongs to. With `"memoryGuard": { "subagents": true }`, a new subagent is not started while memory pressure is critical. See [docs/commands.md](docs/commands.md#auto-queue).
|
|
241
|
+
</details>
|
|
242
|
+
|
|
243
|
+
<details>
|
|
244
|
+
<summary><strong>checkout-guard</strong>: two sessions in one git tree</summary>
|
|
245
|
+
|
|
246
|
+
Blocks `git checkout <branch>`, `switch`, `stash`, `reset --hard`, `clean -f`, `rebase`, `merge`, `restore .` and a dirty `pull` when another live session works in the same tree, and suggests `git worktree add`. Also blocks `git add -A`, `git add .` and `git commit -a` there (`stage-all`; `git add -A src/` and `git add -n` pass), which would sweep the other session's half-finished edits into your commit, and `rm -rf` or `git worktree remove` of a folder another live session works in (`remove-session-dir`). On Windows it blocks `git worktree remove --force` on a worktree that holds junctions, which git has followed into the main checkout.
|
|
247
|
+
|
|
248
|
+
Turn off: `BULKHEAD_DISABLE=checkout-guard`, or one rule with `BULKHEAD_DISABLE=stage-all` or `remove-session-dir`. Details: [docs/guards/checkout-guard.md](docs/guards/checkout-guard.md).
|
|
249
|
+
</details>
|
|
250
|
+
|
|
251
|
+
<details>
|
|
252
|
+
<summary><strong>disk-guard</strong>: whole-disk and parallel scans</summary>
|
|
253
|
+
|
|
254
|
+
Blocks `du`, `ncdu`, `dust`, `ls -R`, `Get-ChildItem -Recurse` and `dir /s` over the whole drive, the home folder or every user's home (`du -sh ~`, `du -sh ~/*`, `ncdu /`), `find /` and `find ~` without `-maxdepth`, and disk scans run in parallel wherever they point: `xargs -P 10 du`, GNU `parallel`, `du ... &` in a loop, `ForEach-Object -Parallel`. One folder at a time passes (`du -sh node_modules`, `du -sh ~/Library/Caches`).
|
|
255
|
+
|
|
256
|
+
Turn off: `BULKHEAD_DISABLE=disk-guard`. Details: [docs/guards/disk-guard.md](docs/guards/disk-guard.md).
|
|
257
|
+
</details>
|
|
258
|
+
|
|
259
|
+
<details>
|
|
260
|
+
<summary><strong>wait-guard</strong>: long foreground waits</summary>
|
|
261
|
+
|
|
262
|
+
Blocks a foreground command whose sleeps can add up to more than 180 seconds. The prompt cache expires after about five minutes without a request, so a subagent polling in the foreground rewrites the whole context every time it wakes. Claude is told to run the loop with `run_in_background: true`. Sleeps in a background job (`sleep 600 &`) pass. With the default 120 second tool timeout a wait cannot pass the default limit, so it blocks only when the call raises the timeout.
|
|
263
|
+
|
|
264
|
+
Turn off: `BULKHEAD_DISABLE=wait-guard`, or raise the limit with `BULKHEAD_WAIT_MAX_SEC`. Details: [docs/guards/wait-guard.md](docs/guards/wait-guard.md).
|
|
265
|
+
</details>
|
|
266
|
+
|
|
267
|
+
<details>
|
|
268
|
+
<summary><strong>orphan-reaper</strong>: processes left by sessions that exited</summary>
|
|
269
|
+
|
|
270
|
+
When a session exits, a hidden background waiter stops what it started from its tool shells and left running: dev servers and anything else listening on a port, test runners and their workers (Vitest, Jest, Playwright, pytest and xdist, `cargo test`, `go test` and more), watchers such as `tsc --watch` and nodemon, builds such as `next build`, and headless browsers. A pass at session start catches what a crash left behind. Editors, terminals, shared daemons such as Gradle or adb, and anything you started yourself are never touched. `bulkhead reap --dry-run` shows what it would stop and why. Something you started on purpose to stay up is kept with `BULKHEAD_KEEP=1 <command>` (ssh tunnels, cloudflared, ngrok, Jupyter, Redis, Postgres, MySQL, MongoDB and Docker are kept without it), and the next session tells you in one line what was stopped. Windows, Linux and macOS (macOS tested on a real Mac).
|
|
271
|
+
|
|
272
|
+
Turn off: `BULKHEAD_DISABLE=orphan-reaper`. Details: [docs/guards/orphan-reaper.md](docs/guards/orphan-reaper.md).
|
|
273
|
+
</details>
|
|
274
|
+
|
|
275
|
+
<details>
|
|
276
|
+
<summary><strong>basics</strong>: five mistakes that cannot be undone</summary>
|
|
277
|
+
|
|
278
|
+
`rm-root` (`rm -rf` at a root, a top-level folder such as `/srv`, home, a folder directly in home such as `~/Documents`, or above the repository), `force-push-main` (`git push --force` to `main` or `master`; `--force-with-lease` passes), `protected-delete` (`git push origin :main`, `git push --delete origin main`, `git branch -D main`), `discard-changes` (`git reset --hard` or `git clean -fd` that would lose uncommitted work) and `agent-author` (`--author="Claude <noreply@anthropic.com>"`, `git config user.name Claude` and the like, so your commits keep counting as yours).
|
|
279
|
+
|
|
280
|
+
Turn off: `BULKHEAD_DISABLE=basics`, or one rule by name. Details: [docs/guards/basics.md](docs/guards/basics.md).
|
|
281
|
+
</details>
|
|
282
|
+
|
|
283
|
+
## Codex, Gemini and other agents
|
|
284
|
+
|
|
285
|
+
If you run Codex CLI, Gemini CLI, Copilot CLI, Cursor, opencode, Amp, Cline, Factory Droid, Windsurf or Devin on the same machine as Claude Code, bulkhead guards their shell commands with the same guards and counts their sessions: an agent's dev server is protected from the others, and `bulkhead status` gets an `AGENT` column.
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
bulkhead setup codex # prints the config for ~/.codex/hooks.json
|
|
289
|
+
bulkhead setup codex --write # merges it (original saved as hooks.json.bulkhead-backup)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
`bulkhead setup <agent>` works for `codex`, `gemini`, `copilot`, `cursor`, `windsurf`, `droid`, `devin`, `cline`, `opencode` and `amp`. Each agent calls `bulkhead hook --agent <name>` before a shell command and gets its own block format back. The agents, config files, what is guarded and the documentation each row was checked against are in [docs/other-agents.md](docs/other-agents.md).
|
|
293
|
+
|
|
294
|
+
## How bulkhead relates to other hook packs
|
|
295
|
+
|
|
296
|
+
General safety packs protect a session from dangerous commands. For example, [claude-forge](https://github.com/sangrokjung/claude-forge) includes hooks that filter leaked secrets from output, block piped remote scripts and stop destructive SQL, and [dcg](https://github.com/Dicklesworthstone/destructive_command_guard) and [cc-safety-net](https://github.com/kenryu42/claude-code-safety-net) cover destructive shell and git commands broadly. They are worth using.
|
|
297
|
+
|
|
298
|
+
bulkhead covers a different problem: sessions on one machine getting in each other's way through process ownership, ports, shared RAM and a shared git tree. Only its `basics` rules overlap with those packs, and you can turn them off with `BULKHEAD_DISABLE=basics` if another pack already covers them. bulkhead runs alongside other hooks: Claude Code runs every hook that matches a tool call, and the call is stopped if any of them blocks it.
|
|
299
|
+
|
|
300
|
+
## Configuration
|
|
301
|
+
|
|
302
|
+
The defaults need no setup. To change them, use a config file: `~/.claude/bulkhead/config.json` for the machine, and `<repo>/.claude/bulkhead.json` for one project (found by walking up to the folder with `.git`). Project settings win over the global file.
|
|
303
|
+
|
|
304
|
+
A project file can take names off kill-guard's block list, ignore ports or turn a guard off for that repository. Read `.claude/bulkhead.json` in a repository you clone before you work in it, as you would its other config; `bulkhead config` shows every setting and the file it came from. Remote hosts and ssh options are read from the global file only.
|
|
305
|
+
|
|
306
|
+
For example, a project that runs `ffmpeg` on purpose and has a slow integration suite:
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"killGuard": { "allowNames": ["ffmpeg"] },
|
|
311
|
+
"waitGuard": { "limitSeconds": 300 },
|
|
312
|
+
"portGuard": { "ignorePorts": [9229] },
|
|
313
|
+
"basics": { "protectedBranches": ["main", "release"] }
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Every guard can be turned off with `"<guard>": { "enabled": false }`. `bulkhead config` prints every setting, its value and where it came from. A broken file is ignored, the guards keep their defaults, and the session shows one notice at startup. All keys are in [docs/configuration.md](docs/configuration.md), and [config.example.json](config.example.json) sets each of them.
|
|
318
|
+
|
|
319
|
+
Environment variables still work and win over both files. The simplest place for them is the `env` block of `~/.claude/settings.json`.
|
|
320
|
+
|
|
321
|
+
<details>
|
|
322
|
+
<summary>All environment variables</summary>
|
|
323
|
+
|
|
324
|
+
| Variable | Default | Same as |
|
|
325
|
+
|---|---|---|
|
|
326
|
+
| `BULKHEAD_DISABLE` | empty | Comma-separated guards to turn off: `kill-guard`, `wait-guard`, `memory-guard`, `port-guard`, `checkout-guard`, `disk-guard`, `orphan-reaper`, `basics`, or `all`. Single rules can be turned off too: `rm-root`, `force-push-main`, `protected-delete`, `discard-changes`, `agent-author`, `stage-all`, `remove-session-dir`. A name here is off whatever the files say |
|
|
327
|
+
| `BULKHEAD_PRESET` | `normal` | The preset: `quiet`, `normal` or `strict` |
|
|
328
|
+
| `BULKHEAD_WAIT_MAX_SEC` | 180 | `waitGuard.limitSeconds` |
|
|
329
|
+
| `BULKHEAD_MIN_FREE_GB` | 3, or 15% of RAM if less | `memory.minFreeGb` |
|
|
330
|
+
| `BULKHEAD_SLOT_FLOOR_GB` | 5, or 25% of RAM if less | `memory.slotFloorGb` |
|
|
331
|
+
| `BULKHEAD_MAX_COMMIT_PCT` | 75 | `memory.maxCommitPct` (Windows only) |
|
|
332
|
+
| `BULKHEAD_NO_LOG` | empty | `log.enabled: false` when set to `1` |
|
|
333
|
+
| `BULKHEAD_STATE_DIR` | `~/.claude/bulkhead` | Where slots, the event log, `guards.log` and the global config file live |
|
|
334
|
+
| `BULKHEAD_SSH` | `ssh` on `PATH` | The ssh client `bulkhead remote` runs |
|
|
335
|
+
|
|
336
|
+
</details>
|
|
337
|
+
|
|
338
|
+
## When it blocks something you meant
|
|
339
|
+
|
|
340
|
+
A block is a question, not a verdict. Three ways out, from the smallest:
|
|
341
|
+
|
|
342
|
+
1. Allow it once. Every block message ends with a short code. In your own terminal, run `bulkhead allow 7F3K`. The agent's next identical call (same command, same folder) goes through, once, within 10 minutes. The agent cannot do this for you: bulkhead blocks any attempt to run `bulkhead allow` or to write its state files.
|
|
343
|
+
2. See why first. `bulkhead explain -- <command>` runs the command through every guard against the live sessions, ports and git tree, without running it, and prints who owns what is in the way, the exact message the agent sees, and how to allow it.
|
|
344
|
+
3. Allow it for good, or change how much it blocks. Put the rule in `.claude/bulkhead.json` (the table below), or pick a preset: `bulkhead config --preset quiet` keeps only the cross-session guards and the two rules that cannot be undone, `strict` turns everything on with tighter limits, `normal` is the default. Your own keys and environment variables win over a preset.
|
|
345
|
+
|
|
346
|
+
### Blocked something you meant? cheat sheet
|
|
347
|
+
|
|
348
|
+
The one-time way is always `bulkhead allow <code>`, run by you. The permanent way, for the rule that fired:
|
|
349
|
+
|
|
350
|
+
| Guard | Rule | Permanent, in `.claude/bulkhead.json` |
|
|
351
|
+
|---|---|---|
|
|
352
|
+
| kill-guard | `pkill`, `taskkill-im`, `stop-process-name` and the other kills by name | `{"killGuard":{"allowNames":["ffmpeg"]}}` |
|
|
353
|
+
| kill-guard | `other-session-pid`: a PID in another session's tree | `{"killGuard":{"ownerCheck":false}}` |
|
|
354
|
+
| kill-guard | `mass-kill`, `docker-mass`, `device-kill`, `app-quit`, `service-stop`: the other rules (only while another session runs) | `{"killGuard":{"massKill":false}}`, and likewise (`dockerMass`, `deviceKill`, `appQuit`, `serviceStop`) |
|
|
355
|
+
| wait-guard | `long-sleep`, `poll-loop`, `follow` | `{"waitGuard":{"limitSeconds":600}}` |
|
|
356
|
+
| memory-guard | `low-memory` | `{"memory":{"minFreeGb":1}}` |
|
|
357
|
+
| memory-guard | `slot-files` | `{"memoryGuard":{"enabled":false}}` |
|
|
358
|
+
| port-guard | `port-in-use`, `kill-by-port` | `{"portGuard":{"ignorePorts":[3000]}}` |
|
|
359
|
+
| checkout-guard | `stage-all` | `{"checkoutGuard":{"stageAll":false}}` |
|
|
360
|
+
| checkout-guard | `remove-session-dir` | `{"checkoutGuard":{"removeSessionDir":false}}` |
|
|
361
|
+
| checkout-guard | `git-checkout`, `git-pull` and the other tree changes | `{"checkoutGuard":{"enabled":false}}` |
|
|
362
|
+
| disk-guard | `disk-wide-find`, `parallel-disk-scan`, `disk-wide-scan` | `{"diskGuard":{"enabled":false}}` |
|
|
363
|
+
| basics | `rm-root` | `{"basics":{"rmRoot":false}}` |
|
|
364
|
+
| basics | `force-push-main` | `{"basics":{"forcePushMain":false}}` |
|
|
365
|
+
| basics | `discard-changes` | `{"basics":{"discardChanges":false}}` |
|
|
366
|
+
| basics | `agent-author` | `{"basics":{"agentAuthor":false}}` |
|
|
367
|
+
| basics | `self-allow` | cannot be allowed once; only you can approve |
|
|
368
|
+
|
|
369
|
+
The same switch as an environment variable is `BULKHEAD_DISABLE=<guard or rule name>`. Everything is in [docs/configuration.md](docs/configuration.md) and [docs/commands.md](docs/commands.md).
|
|
370
|
+
|
|
371
|
+
## See what is running
|
|
372
|
+
|
|
373
|
+
`bulkhead` is on the Bash tool's `PATH` next to `bulkhead-slot`. Inside Claude Code, `/bulkhead:scan [30d]`, `/bulkhead:status`, `/bulkhead:log [24h|7d]`, `/bulkhead:doctor` and `/bulkhead:reap` run the matching command and summarize it. In your own terminal, run `npx claude-bulkhead top`, or install it once with `npm install -g claude-bulkhead` and run `bulkhead top`. The npm package is the same code as the plugin. Every command that prints a table takes `--json`. The full reference is [docs/commands.md](docs/commands.md).
|
|
374
|
+
|
|
375
|
+
### bulkhead status
|
|
376
|
+
|
|
377
|
+
Every Claude Code session on the machine: what it is doing (working, waiting for you, needs permission), its git branch and whether that is a worktree, the memory its process tree uses, what it has listening on a port, the jobs held in bulkhead-slot and the ones waiting, free RAM, and MCP servers that run as several copies across sessions:
|
|
378
|
+
|
|
379
|
+
```
|
|
380
|
+
$ bulkhead status
|
|
381
|
+
SESSION STATE STARTED RSS BRANCH PROJECT
|
|
382
|
+
18672 working 09:52 1.4 GB main ~/src/acme-web
|
|
383
|
+
:3000 node pid 24632
|
|
384
|
+
21888 needs permission 4m 10:05 353 MB feat/login (wt) ~/src/acme-web-auth
|
|
385
|
+
26448 waiting 3m 11:40 625 MB feat/checkout (wt) ~/src/acme-web-checkout
|
|
386
|
+
:3001 node pid 31020
|
|
387
|
+
duplicate MCP: 3 copies of @playwright/mcp, 1.2 GB (sessions 18672, 21888, 26448)
|
|
388
|
+
|
|
389
|
+
SLOT GB PID AGE SESSION PROJECT COMMAND
|
|
390
|
+
slot-1 4 30112 6 min 18672 ~/src/acme-web npx playwright test
|
|
391
|
+
|
|
392
|
+
WAITING GB PID FOR SESSION PROJECT COMMAND
|
|
393
|
+
#1 3 30200 2 min 26448 ~/src/acme-web-checkout npm run build
|
|
394
|
+
|
|
395
|
+
9.9 GB free of 31.8 GB, commit 68%
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
`bulkhead top` puts the sessions that need you first. `bulkhead port --stable` prints a port that belongs to the current git worktree and is the same every time. To get a desktop notification when a session starts waiting, set `notify.command` ([commands.md](docs/commands.md#session-state-and-notifications)).
|
|
399
|
+
|
|
400
|
+
`bulkhead slot ...` is the same as `bulkhead-slot ...`.
|
|
401
|
+
|
|
402
|
+
### bulkhead top
|
|
403
|
+
|
|
404
|
+
The same view, live and full screen. It refreshes every 2 seconds on Linux and macOS and every 4 seconds on Windows, where one process scan takes 1 to 2 seconds. The scan runs in a worker thread, so keys never wait for it. `q`, `Esc` or `Ctrl-C` quit, `r` refreshes.
|
|
405
|
+
|
|
406
|
+
```
|
|
407
|
+
bulkhead top 14:30:05 scan 1.4s every 4s q quit r refresh
|
|
408
|
+
RAM ████████████████░░░░░░░░░░░░░░ 9.9 GB free of 31.8 GB commit 68%
|
|
409
|
+
|
|
410
|
+
SESSIONS 3
|
|
411
|
+
PID STARTED PROJECT RSS PROCS PORTS
|
|
412
|
+
18672 Oct 12 17:49 ~/src/acme-web 1.4 GB ██████████ 12 :3000 :24678
|
|
413
|
+
21888 Oct 12 17:52 ~/src/acme-web-auth 353 MB ███░░░░░░░ 3 -
|
|
414
|
+
26448 03:43 ~/src/acme-web-checkout 625 MB ████░░░░░░ 5 :3001
|
|
415
|
+
|
|
416
|
+
HEAVY JOBS 1 running, 1 waiting
|
|
417
|
+
slot-1 4 GB 30112 6 min npx playwright test
|
|
418
|
+
wait #1 3 GB 30200 2 min npm run build (this machine has 16 GB; one heavy job at a time)
|
|
419
|
+
|
|
420
|
+
RECENT BLOCKS
|
|
421
|
+
14:29 kill-guard taskkill-im ~/src/acme-web-auth taskkill /F /IM node.exe
|
|
422
|
+
14:12 wait-guard poll-loop ~/src/acme-web-checkout until [ -f out/DONE ]; do sleep 30; done
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
On a narrow terminal it drops columns instead of wrapping. When the output is not a terminal, or with `--once`, it prints one snapshot and exits.
|
|
426
|
+
|
|
427
|
+
### bulkhead log
|
|
428
|
+
|
|
429
|
+
Every block, and every process orphan-reaper stops, is one JSON line in `<state dir>/events.jsonl` with the time, guard, rule, session, project and the command cut to 200 characters. The file stays on your machine, rotates at 1 MB, and keeps one old file. `BULKHEAD_NO_LOG=1` turns it off.
|
|
430
|
+
|
|
431
|
+
```
|
|
432
|
+
$ bulkhead log --summary --since 7d
|
|
433
|
+
10 blocks in the last 7 days, 3 projects, 4 sessions
|
|
434
|
+
|
|
435
|
+
GUARD RULE COUNT LAST
|
|
436
|
+
wait-guard poll-loop 3 06:40 ████████████████████████
|
|
437
|
+
wait-guard long-sleep 2 06:40 ████████████████
|
|
438
|
+
basics force-push-main 1 06:40 ████████
|
|
439
|
+
basics rm-root 1 06:40 ████████
|
|
440
|
+
kill-guard pkill 1 06:40 ████████
|
|
441
|
+
kill-guard taskkill-im 1 06:40 ████████
|
|
442
|
+
memory-guard slot-files 1 06:40 ████████
|
|
443
|
+
|
|
444
|
+
PROJECT COUNT
|
|
445
|
+
~/src/acme-web 4
|
|
446
|
+
~/src/acme-web-auth 3
|
|
447
|
+
~/src/acme-web-checkout 3
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
`bulkhead log -n 20` lists the events themselves, `--since 30m|24h|7d|2w|<date>` limits the time, and `--guard kill-guard` limits the guard.
|
|
451
|
+
|
|
452
|
+
### bulkhead doctor
|
|
453
|
+
|
|
454
|
+
Checks Node, the plugin files, the state directory, the config files, each guard (on or off, and why), the process reader with its timing, the session files, the RAM limits computed for this machine, held slots, the event log and git. Then an Enforcement section proves the installed hooks block: the install and `enabledPlugins`, duplicate installs, settings that turn hooks off, `node` on the hook `PATH`, and a real run of each guard's hook command against a canary, with its latency. The exit code is 1 when any check fails.
|
|
455
|
+
|
|
456
|
+
```
|
|
457
|
+
$ bulkhead doctor
|
|
458
|
+
OK node v24.22.1
|
|
459
|
+
OK package this copy ~/.claude/plugins/cache/bulkhead/bulkhead/0.3.0, hooks: 3 SessionStart, 2 SessionEnd, 1 UserPromptSubmit, 1 Stop, 1 Notification, 2 PostToolUse, 1 PostToolUseFailure, 4 PreToolUse
|
|
460
|
+
OK state dir ~/.claude/bulkhead is writable
|
|
461
|
+
OK config no config files, defaults in use
|
|
462
|
+
OK preset normal (default)
|
|
463
|
+
OK kill-guard on
|
|
464
|
+
OK wait-guard on, limit 180s
|
|
465
|
+
OK memory-guard on
|
|
466
|
+
OK port-guard on
|
|
467
|
+
OK checkout-guard on
|
|
468
|
+
OK disk-guard on
|
|
469
|
+
OK basics on, protected branches: main, master
|
|
470
|
+
OK edit-guard on
|
|
471
|
+
OK secrets-guard off (default)
|
|
472
|
+
OK orphan-reaper on, at session start and after each session ends
|
|
473
|
+
OK session-state on
|
|
474
|
+
OK processes 589 processes, 11 listening ports, 10 Claude sessions (10 with a session file) in 0.2s
|
|
475
|
+
OK sessions ~/.claude/sessions (10 session files; a running session without one is still found from the process list, but checkout-guard cannot tell which folder it works in)
|
|
476
|
+
OK memory 28.3 of 48.0 GB free, memory-guard blocks heavy commands below 3 GB, bulkhead-slot keeps 5 GB free for a second job
|
|
477
|
+
OK slots none held
|
|
478
|
+
OK event log ~/.claude/bulkhead/events.jsonl, 2 events, 254 B (rotates at 1 MB)
|
|
479
|
+
OK git 2.56.0
|
|
480
|
+
|
|
481
|
+
Enforcement
|
|
482
|
+
OK install bulkhead@bulkhead 0.3.0 at ~/.claude/plugins/cache/bulkhead/bulkhead/0.3.0, enabled in user settings
|
|
483
|
+
OK hooks on no disableAllHooks or allowManagedHooksOnly in user, project, local or managed settings
|
|
484
|
+
OK hooks.json installed copy: 4 PreToolUse hooks, all synchronous
|
|
485
|
+
OK hook node /opt/homebrew/bin/node v24.22.1
|
|
486
|
+
OK hook kill-guard blocked "pkill node" (exit 2, message shown to Claude) in 71 ms
|
|
487
|
+
OK hook wait-guard blocked "sleep 100000" (exit 2, message shown to Claude) in 64 ms
|
|
488
|
+
OK hook disk-guard blocked "du -sh /" (exit 2, message shown to Claude) in 70 ms
|
|
489
|
+
OK hook basics blocked "rm -rf /" (exit 2, message shown to Claude) in 63 ms
|
|
490
|
+
|
|
491
|
+
30 OK, 0 WARN, 0 FAIL
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### bulkhead port
|
|
495
|
+
|
|
496
|
+
Prints a port that nothing listens on, checked on IPv4 and IPv6, so a second worktree can start its server without guessing:
|
|
497
|
+
|
|
498
|
+
```
|
|
499
|
+
npm run dev -- --port $(bulkhead port --near 3000)
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### bulkhead reap
|
|
503
|
+
|
|
504
|
+
Runs orphan-reaper now. `--dry-run` lists what it would stop, the rule that matched and why the session counts as exited, without stopping anything:
|
|
505
|
+
|
|
506
|
+
```
|
|
507
|
+
$ bulkhead reap --dry-run
|
|
508
|
+
would stop 30112 test-runner node ~/src/acme-web/node_modules/vitest/dist/workers/forks.js
|
|
509
|
+
Vitest and its worker pool (tinypool); its session has exited and removed snapshot-bash-1791860359256-ezwkie.sh; 6 processes from 30080
|
|
510
|
+
1 tree would be stopped. Run `bulkhead reap` to stop it.
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### Status line
|
|
514
|
+
|
|
515
|
+
`bulkhead-statusline` prints one line for the Claude Code status line:
|
|
516
|
+
|
|
517
|
+
```
|
|
518
|
+
3 sessions 2 heavy 9.1 GB free
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
Sessions are the live entries in `~/.claude/sessions`, heavy is the number of jobs holding a bulkhead-slot, and free is the same measure memory-guard uses. When sessions are waiting for you, the line adds `2 waiting` after the session count. It does not list every process (one `ps` for the session pids only), takes about 100 ms from cold on a Mac with 650 processes, and caches the line for 5 seconds in the state directory, written through a temporary file so concurrent sessions never read half of it.
|
|
522
|
+
|
|
523
|
+
A plugin cannot set the main status line (plugin settings only support `agent` and `subagentStatusLine`), so add it to `~/.claude/settings.json` yourself:
|
|
524
|
+
|
|
525
|
+
```json
|
|
526
|
+
{
|
|
527
|
+
"statusLine": {
|
|
528
|
+
"type": "command",
|
|
529
|
+
"command": "bulkhead-statusline",
|
|
530
|
+
"refreshInterval": 10
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
This needs `npm install -g claude-bulkhead`, which puts `bulkhead-statusline` on `PATH`. If you already have a status line script, call `bulkhead-statusline` from it and append its output.
|
|
536
|
+
|
|
537
|
+
## FAQ
|
|
538
|
+
|
|
539
|
+
**Does it slow Claude Code down?**
|
|
540
|
+
A little. All the Bash guards run in one short Node process with no dependencies, about 76 ms per tool call on a MacBook Pro (Node 24), of which 32 ms is starting Node. When 10 sessions make a tool call at the same moment, each waits about 89 ms (318 ms when every guard was its own process, as in 0.2). Writing a block to the event log adds no measurable time. The guards only do slow work, such as reading the process list (a second or two on Windows), when the command matches: a dev server start on a port that already answers, a kill, a heavy command. The status line takes about 100 ms cold and is cached for 5 seconds.
|
|
541
|
+
|
|
542
|
+
**It blocked something it should not have. What do I do?**
|
|
543
|
+
Run `bulkhead log` to see the exact command and reason. Let it through in the project config, `<repo>/.claude/bulkhead.json`: `killGuard.allowNames` for a program name, `portGuard.ignorePorts` for a shared port, `waitGuard.limitSeconds` for a longer wait, or `"enabled": false` for the whole guard in that project. See [docs/configuration.md](docs/configuration.md). Then please open a [false positive issue](https://github.com/dooly6276/claude-bulkhead/issues/new?template=false-positive.yml) with the line from `bulkhead log`, so the pattern can be fixed for everyone.
|
|
544
|
+
|
|
545
|
+
**Is it useful with a single session?**
|
|
546
|
+
Yes. kill-guard, wait-guard, memory-guard and basics protect one session and its subagents just as well. port-guard and checkout-guard only act when another session is alive, and orphan-reaper cleans up after sessions that have exited.
|
|
547
|
+
|
|
548
|
+
**Which systems does it support?**
|
|
549
|
+
Windows, Linux and macOS, with Node 18 or later. orphan-reaper on macOS is tested with fixtures of `ps` output and on a real Mac (a stand-in session was ended and only its leftovers were stopped), and on Linux it needs a Claude Code version that sets `CLAUDE_PID` for tool shells. On Windows, `bulkhead-slot` runs commands through Git Bash when it is installed and through `cmd.exe` otherwise.
|
|
550
|
+
|
|
551
|
+
**Does it send anything anywhere?**
|
|
552
|
+
No. There is no telemetry and no network call. The only socket it opens is port-guard's connection attempt to `localhost` to see whether a port answers. Logs stay in the state directory. The one exception is `bulkhead remote`, which connects over SSH to a machine you configured, and only when you run it.
|
|
553
|
+
|
|
554
|
+
More questions, including how the guards can be bypassed and how the RAM numbers are measured, are in [docs/faq.md](docs/faq.md).
|
|
555
|
+
|
|
556
|
+
## Limitations
|
|
557
|
+
|
|
558
|
+
- The guards read command text. They split it into commands and open wrappers such as `bash -c`, `cmd /c`, `powershell -EncodedCommand` and `sudo` up to three levels deep, but a kill or a sleep hidden in a script file, a shell function or an alias is not seen. They catch the common shapes, not a determined workaround.
|
|
559
|
+
- memory-guard and bulkhead-slot only see RAM. They do not limit CPU, disk or GPU.
|
|
560
|
+
- bulkhead-slot is only used when called. Nothing forces every session to queue through it.
|
|
561
|
+
- Each guard page lists its own limits.
|
|
562
|
+
|
|
563
|
+
## Uninstall
|
|
564
|
+
|
|
565
|
+
```
|
|
566
|
+
/plugin uninstall bulkhead@bulkhead
|
|
567
|
+
/plugin marketplace remove bulkhead
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
If you installed the npm package instead, run `npm uninstall -g claude-bulkhead`. A SessionEnd waiter that is already running exits by itself within 3 minutes, so nothing keeps running after you uninstall.
|
|
571
|
+
|
|
572
|
+
Then delete the state directory (`~/.claude/bulkhead`, or `BULKHEAD_STATE_DIR` if you set it) and remove the `statusLine` entry from `~/.claude/settings.json` if you added one.
|
|
573
|
+
|
|
574
|
+
## Using bulkhead? Show it
|
|
575
|
+
|
|
576
|
+
Add this badge to your project's README:
|
|
577
|
+
|
|
578
|
+
```markdown
|
|
579
|
+
[](https://github.com/dooly6276/claude-bulkhead)
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
It renders as [](https://github.com/dooly6276/claude-bulkhead)
|
|
583
|
+
|
|
584
|
+
## Contributing
|
|
585
|
+
|
|
586
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Security reports: [SECURITY.md](SECURITY.md). The changelog is in [CHANGELOG.md](CHANGELOG.md), and what bulkhead stores and sends is in [PRIVACY.md](PRIVACY.md).
|
|
587
|
+
|
|
588
|
+
## License
|
|
589
|
+
|
|
590
|
+
[MIT](LICENSE)
|