Guides
Package guard
Check packages before an agent installs them — hallucinated names, malicious packages, known vulnerabilities and typosquats — via MCP, REST or a Claude Code, Cursor, Codex or Kimi Code hook.
Coding agents sometimes invent package names. Attackers watch for those names and register them ("slopsquatting"), so the next agent that hallucinates the same name installs malware. The package guard checks every package before it is installed.
What is checked
| Check | Source | Verdict |
|---|---|---|
| The package exists in the registry | deps.dev, then the registry itself for brand-new packages | missing → block |
| The requested version was published | deps.dev / registry | missing → block (and if it was pulled after a malicious-package report, the block says so) |
Malicious-package report (MAL-…) | OSV | block |
| Known vulnerabilities in that version, with the fixed version | OSV (GHSA, PyPA, Go, RustSec…) | warn |
| Deprecated or yanked | deps.dev / crates.io | warn |
| First published less than 30 days ago | deps.dev / registry | warn |
| The version (of an established package) was published less than 72 hours ago — names the previous stable release to pin | deps.dev / registry | warn |
| Fewer than 500 downloads last week (npm) | api.npmjs.org | warn |
An unversioned npm install whose latest tag is a pre-release (prisma → 8.0.0-rc.26) — names the stable release to pin | deps.dev / registry | warn |
Name one or two edits away from a popular package (expres, reqeusts) | CodexGuild list | warn |
A range (prisma@^7, prisma@7, anthropic>=2.1,<3) is checked as the newest stable release it allows; a range nothing matches is block.
block means do not install. warn means tell the user why before installing. ok means nothing was found.
unknown means a lookup failed. The guard never blocks because of an outage.
Ecosystems: npm, pypi, go, cargo. Only names and versions are sent.
MCP
codexguild_check_packages { packages: [{ name: "zod", ecosystem: "npm", version: "^3.25.0" }] }REST
curl -s -X POST https://api.codexguild.com/v1/packages/check \
-H "Authorization: Bearer $CODEXGUILD_API_KEY" -H "content-type: application/json" \
-d '{"packages":[{"name":"reqeusts","ecosystem":"pypi"},{"name":"lodash","ecosystem":"npm","version":"4.17.15"}]}'Claude Code hook (automatic)
The local MCP package also contains a PreToolUse hook. It reads each Bash command before it runs and finds
installs:
npm install <pkg>/pnpm add/yarn add/bun addnpx,bunx,pnpm dlx,yarn dlxpip install(alsopython -m pip),uv add,uv pip install,uv tool install,uvx,pipx install/run,poetry addcargo add,cargo installgo get,go install
If a package is blocked, the hook denies the command and tells the agent why. If a package gets a warning,
Claude Code asks you before the command runs. Lockfile installs (npm ci, npm install with no
arguments) and local paths are never checked.
Add it to ~/.claude/settings.json (or the project's .claude/settings.local.json, which is not committed). The hook reads CODEXGUILD_API_KEY from the environment Claude Code starts in — export it in your shell profile; never put the key in a settings file:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash|Write|Edit|MultiEdit", "hooks": [{ "type": "command", "command": "npx -y @codexguild/mcp@latest guard", "timeout": 20 }] }
]
}
}If the key is missing or CodexGuild can't be reached, the hook lets the command run and prints a note.
Cursor hook
The same command works as a Cursor beforeShellExecution hook. The guard sees Cursor's payload and answers in
Cursor's format: deny for a blocked package, ask for a warning, nothing otherwise. Put it in ~/.cursor/hooks.json
(all projects) or .cursor/hooks.json (one project); the matcher keeps it to install commands:
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{ "command": "npx -y @codexguild/mcp@latest guard", "timeout": 20, "matcher": "\\b(npm|pnpm|yarn|bun|npx|bunx|pip3?|uv|uvx|pipx|poetry|cargo|go)\\b" }
]
}
}Tested with Cursor Agent 2026.10.01: a blocked package is stopped even in Run Everything (--force) mode.
The hook finds the key in CODEXGUILD_API_KEY, or in the codexguild server's env in ~/.cursor/mcp.json (a
Cursor started from the Dock doesn't see your shell profile).
Codex hook
Codex reads Claude Code's PreToolUse format. Add it to ~/.codex/hooks.json (or .codex/hooks.json in a trusted
project) and approve it once when Codex asks you to review new hooks:
{
"hooks": {
"PreToolUse": [
{ "matcher": "^(Bash|apply_patch)$", "hooks": [{ "type": "command", "command": "npx -y @codexguild/mcp@latest guard", "timeout": 20 }] }
]
}
}Codex doesn't support "ask" from a hook yet, so a warning (vulnerable version, brand-new package…) reaches the
agent as context with the instruction to tell you, and the command runs. A block stops the command as in Claude
Code. The key comes from CODEXGUILD_API_KEY or [mcp_servers.codexguild.env] in ~/.codex/config.toml.
Kimi Code hook
Kimi Code 2.1 takes Claude Code-style PreToolUse hooks in ~/.kimi-code/config.toml. A [[hooks]] entry allows
only these four fields — anything else stops the config from loading:
[[hooks]] event = "PreToolUse" matcher = "^(Bash|Read|Write|Edit)$" command = "npx -y @codexguild/mcp@latest guard" timeout = 20
Kimi acts only on "deny" — a hook's "ask" lets the tool run without showing anything, and a hook that allows can't
send the agent a note. So in Kimi Code every objection is a deny: a blocked package, a warning (the agent is told
to pass it on to you, and you install the package yourself if you still want it), a guardrail change, a read of a
credential file. Requires @codexguild/mcp 1.17.0. The key comes from CODEXGUILD_API_KEY in the shell that starts
kimi — the same variable its MCP config names with bearerTokenEnvVar.
The same hook also stops destructive commands (rm -rf ~, database resets, force pushes, secrets sent over the
network) — locally, without the key. See Command guard.