SuperAPIAI Directory

claude-bulkhead

github.com · AI agents

claude-bulkhead is a set of hooks for Claude Code and other coding agents, designed to prevent multiple sessions from interfering with each other when working in parallel on the same machine. It checks every Bash or PowerShell command and blocks operations that could harm other sessions, such as: running rm -rf when a variable is empty, using pkill to kill other development servers, seizing ports, committing other sessions' changes with git add -A, and so on. The tool supports Windows, macOS, and Linux, has zero dependencies, and requires no tmux, sudo, background daemon, or network calls. It also protects more than a dozen agents, including Codex, Gemini CLI, Copilot CLI, and Cursor. After installation, the hooks run before every command execution; if a command would harm other sessions, it is blocked and a safer alternative command is suggested. In addition, it provides features such as scanning history, diagnostics, real-time monitoring, worktree management, and remote execution of heavy tasks.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS · Linux

About this tool

claude-bulkhead is an open-source project aimed at solving the conflicts that arise when multiple Claude Code sessions (or other coding agents) work in parallel on the same machine. Through a set of lightweight hooks, it checks before every shell command execution, blocks operations that could affect other sessions, and suggests safer alternative commands.

Purpose

When you run multiple Claude Code sessions on the same machine (for example, each session using a separate git worktree), they share ports, the process table, and memory. This can lead to: port conflicts, mistakenly killing processes of other sessions, memory exhaustion, committing other sessions' unfinished changes, and so on. claude-bulkhead identifies the processes, ports, and git trees owned by each session, and blocks only those commands that would harm other sessions.

Main capabilities

  • kill-guard: Blocks bulk termination commands targeting shared programs (such as node, python, java, etc.) (e.g., pkill, killall, taskkill /IM, etc.), unless specified by PID or project path.
  • port-guard: Blocks starting a development server on a port that another session is listening on, and suggests using a free port; it also blocks killing another session's process by port.
  • memory-guard: When available memory falls below a threshold (default 3GB or 15%), blocks heavy commands (such as test runners, build tools, etc.). It can be combined with bulkhead-slot for queued execution.
  • checkout-guard: When another active session is working in the same git tree, blocks operations such as git checkout, reset --hard, clean -f, as well as commands such as git add -A and git commit -a that could mix in other sessions' changes.
  • disk-guard: Blocks disk scan commands targeting entire drives, the home directory, or all users' home directories (such as du -sh ~, find /, etc.), as well as parallel disk scans.
  • wait-guard: Blocks foreground commands whose cumulative sleep time exceeds 180 seconds, and suggests running them in the background.
  • basics: Blocks dangerous basic commands, such as rm -rf ~, rm -rf $D/ (when D is emptybecomes rm -rf /), rm -rf .git, force pushing to main, etc.
  • bulkhead scan: reads session records in ~/.claude/projects, replays historical commands, and counts how many sessions were running simultaneously and how many times they would have been blocked, without sending any data.
  • bulkhead doctor: diagnoses whether the hooks are working properly and runs harmless commands to verify the blocking effect.
  • bulkhead top: monitors sessions, memory, ports, and heavy tasks in real time.
  • bulkhead worktree add: creates a worktree in one step, copies .env files, installs dependencies, and assigns a fixed port.
  • bulkhead remote: sends heavy tasks (tests, builds, etc.) to another machine over SSH for execution, with support for resource locking and cleanup.

Usage

  1. Install the plugin in Claude Code (see the official documentation for the specific commands).
  2. Start a new Claude Code session; the hooks take effect automatically.
  3. Run /bulkhead:scan 30d to see which commands would have been blocked over the past month.
  4. Run /bulkhead:doctor to check the configuration.
  5. Use bulkhead log to view block records and bulkhead status to view status.
  6. You can disable an individual guard via the BULKHEAD_DISABLE environment variable, or adjust thresholds via the configuration file.

Other agents (such as Codex, Gemini CLI, etc.) can load the same guards as a plugin.

Use cases

  • Running multiple Claude Code sessions on the same machine, especially when using git worktree for parallel development.
  • Needing to prevent agents from accidentally killing other processes or occupying ports.
  • Having limited memory and needing to avoid running multiple heavy tasks at the same time.
  • Wanting to audit dangerous operations in an agent's command history.

Limitations

  • Requires Node.js 18 or later (the native Claude Code installer does not include Node; you need to install it yourself).
  • The hooks only take effect for commands executed via Bash or PowerShell and do not cover other execution methods.
  • Some guards (such as port-guard and the low-memory check) cannotbe replayed in scan because the history does not contain port and memory information.
  • The remote execution feature requires another machine configured with an SSH server, bash, git, and tar.
  • The project is an open-source tool; please refer to the official documentation for specific feature details and configuration.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools