agent-ram-guard
Keeps parallel coding agents from running a Mac out of memory. Works with Claude Code, Codex, Cursor, Antigravity, pi and Gemini CLI.
When several agents share one machine, each one starts its own dev server, test run or container, and nobody stops them. RAM fills up, swap grows, and everything slows down. ram-guard hooks into each agent's shell commands so the agents notice:
- Session start: the agent gets three RAM rules. It must stop every process it starts, never kill a process it did not start, and check RAM before starting anything heavy.
- Before a memory-heavy shell command (
pytest, next dev, docker compose up, tsc, uvicorn, ...): if RAM is critical (95% used by default), it waits up to 2 minutes for it to drop, then denies the command. The denial tells the agent to stop the processes it started itself.
- After a shell command (at most once every 5 minutes per session): it logs a sample and, if RAM is at or above 90% or swap is high, warns the agent with the top processes by memory, tagged with the git worktree each belongs to.
One shell script does the work for every tool. Each tool gets a small hook config that tells the script which output format to use. Requires macOS (it reads vm_stat, sysctl and ps) and jq (brew install jq).
Install
| Tool | Install with | Blocks heavy commands | Warns | RAM rules |
|---|
| Claude Code | plugin | yes | after the command | session start |
| Codex | plugin | yes | after the command | session start |
| Cursor | install.sh | yes | after the command | session start |
| Antigravity (app, IDE, CLI) | install.sh | yes | before the next model call | session start |
| pi | pi install | yes | appended to the bash result | system prompt |
| Gemini CLI | extension | yes | after the command | session start |
Claude Code and Codex: plugin
claude plugin marketplace add sahasrarjn/agent-ram-guard
claude plugin install ram-guard@agent-ram-guard
codex plugin marketplace add sahasrarjn/agent-ram-guard
codex plugin add ram-guard@agent-ram-guard
- Restart open sessions; new ones pick the plugin up.
- Codex skips plugin hooks until you trust them. Start
codex and pick "Trust all and continue" when it says the hooks need review (or run /hooks). Nobody can do this step for you.
- Update later with
claude plugin marketplace update agent-ram-guard or codex plugin marketplace upgrade agent-ram-guard. Codex asks you to trust the hooks again when they change.
Cursor and Antigravity: installer
Neither can install hooks from a repo yet, so the installer writes them into your global config:
curl -fsSL https://raw.githubusercontent.com/sahasrarjn/agent-ram-guard/main/install.sh | bash -s -- cursor antigravity
Name the tools you want, or leave the list empty (| bash) to set up every tool it finds (Claude Code, Codex, Cursor, Antigravity). If you already use the Claude Code or Codex plugin, name only cursor antigravity, or every command is checked twice.
The installer copies the script to ~/.local/bin/ram-guard.sh and registers the hooks in:
| Tool | File |
|---|
| Claude Code | ~/.claude/settings.json |
| Codex | ~/.codex/config.toml (then trust them with /hooks) |
| Cursor | ~/.cursor/hooks.json (restart Cursor) |
| Antigravity | ~/.gemini/config/hooks.json, shared by the app, IDE and CLI |
It backs up each file it changes (*.bak-ram-guard) and skips a tool that already references ram-guard.sh, so you can re-run it safely. Re-run it to update the script.
If Cursor is set to load third-party (Claude Code) hooks, it also runs your Claude Code entries, so keep only one of the two.
pi
pi install git:github.com/sahasrarjn/agent-ram-guard
The extension runs the same script: it blocks heavy bash calls, appends the warning to the bash result and adds the RAM rules to the system prompt.
Gemini CLI
gemini extensions install https://github.com/sahasrarjn/agent-ram-guard
Google moved free-tier Gemini CLI users to Antigravity in June 2026; this is for accounts that still run it.
The RAM rules
Every install method gives the agent these rules at the start of a session (with the real script path), so there is nothing to add to CLAUDE.md, AGENTS.md or GEMINI.md:
- Every process you start (dev servers, test runs, containers, browsers) is yours to stop. Note its PID and stop it when you are done.
- Never kill a process you did not start.
- Before starting something heavy, run `ram-guard.sh status`. If RAM is at or above 90%, close your own idle processes first.
Manual setup
To edit config files yourself, print the exact hooks for a tool and merge them in: