DOCS
Guard
Guard is a local hook. Claude Code or Cursor calls balerx before a tool runs. The decision comes from ~/.balerx/policy.yaml. The call is recorded in the OS data directory: ~/.local/share/balerx/logs/activity.jsonl on Linux, ~/Library/Application Support/balerx/logs/activity.jsonl on macOS, and %LOCALAPPDATA%\balerx\logs\activity.jsonl on Windows.
Nothing is uploaded until you run upload yourself.
balerx setup writes the policy you choose to ~/.balerx/policy.yaml. It prints a Balerx Gate banner first. Until that file exists, Guard uses a built-in policy. A present empty or unreadable file fails closed: the hook returns ask and does not use that built-in fail-open default. balerx doctor parses the file and exits 1 when it is empty or invalid. The installer prints the same banner when it finishes and does not open the checklist. balerx scan does not open the checklist either. After a scan, a missing file prints No policy set yet. Run: balerx setup on stderr. balerx guard install prints that hint first on stdout, then installs.
balerx setup
balerx setup --yes
balerx setup --preset strict
balerx policy show
balerx policy edit
balerx guard install claude-code
balerx guard install cursor
balerx guard uninstall claude-code
balerx guard uninstall cursor
balerx guard statusThe agent names are claude-code and cursor. Guard hooks exist for Claude Code and Cursor. A scan of another agent, such as VS Code with GitHub Copilot or Codex CLI, still reads that agent's config. The agents section then includes a Guard coverage line: Guard hooks are not available for VS Code with GitHub Copilot yet, so its tool calls aren't intercepted. The scan still checks its config. That line is separate from findings. The finding count and the risk score stay the same, and --fail-on ignores it. HOOK-GAP-002 stays planned. Current scans do not raise it.
Claude Code hooks are merged into ~/.claude/settings.json. Each event is an array of {matcher, hooks:[{type:"command", command}]}. An existing project .claude/settings.json is updated the same way. The installer lists each settings file once. A Windows \\?\ prefix is the same path, so it is not written a second time. A second install does not add another hook. The hook binary path is quoted: POSIX shells use single quotes ('\'' for an embedded quote). PowerShell always uses & "path", including a plain drive-letter path, and escapes $ and backtick. guard status and doctor unescape those PowerShell escapes only on the & "..." form. A POSIX hook command whose binary directory contains a backtick is checked as stored. Cursor hooks are merged into ~/.cursor/hooks.json, keeping "version": 1 and any hooks you already had. Events are beforeShellExecution, beforeMCPExecution, and beforeReadFile.
balerx uninstall removes commands that run the balerx binary, or balerx.exe, with a hook argument. my-balerx-webhook.sh stays. It prints the paths and asks before it writes. --yes skips the question. Without --purge, policy and logs stay. --purge also deletes known files only: policy.yaml, policy.yaml.bak copies, planted canary files in ~/.balerx/canaries, canaries.json, and logs/activity.jsonl. Unknown files stay. A directory is removed only when it is empty afterward and its name is .balerx or balerx. A custom BALERX_DATA_DIR is never removed wholesale. balerx guard uninstall claude-code and balerx guard uninstall cursor still remove one agent and do not ask. Neither command puts an old file back.
balerx guard status prints whether those hooks are installed, the policy timeout, and the log path. User Claude Code hooks are ~/.claude/settings.json. Project hooks are a separate .claude/settings.json in the working folder. When the working folder is HOME, status does not treat the user file as a project hook. On a fresh install it exits 0 and prints Not installed — run: balerx guard install claude-code and Not installed — run: balerx guard install cursor. --strict and --check exit 1 when no hook is installed. Use that flag in a CI script that should fail until Guard is installed. A machine that already has a Claude Code or Cursor hook exits 0, unless the recorded hook binary is missing or not executable: then guard status and doctor exit non-zero and say so.
Decisions match the agent. Claude Code PreToolUse gets permissionDecision of allow, deny, or ask, and deny exits 2. PostToolUse records the call, exits 0, and does not emit permissionDecision. Cursor gets {"permission":"allow"|"deny"|"ask"} and always exits 0.
If the hook is slow or the input is broken
The timeout wait starts when the evaluation thread is spawned after stdin is read, not at process start. The hook waits only that budget (minimum 25ms). A timeout asks. A stdin that never closes can still hang. The deserialized default is 50 milliseconds. New balanced and strict files write 250 milliseconds. A completed deny or ask is kept even after that budget. An evaluation that does not finish asks, regardless of fail_open. When stdin is not JSON, fail_open chooses the decision. The default is true, so invalid JSON allows the tool. --preset strict writes fail_open: false and timeout_ms: 250. An allow from fail_open is written to the activity log and stderr. Omitting global or writing global: {} uses the built-in defaults. Existing files are not rewritten. The command normalize pass is one linear scan (capped at 256 KiB); if that scan cannot finish, Guard asks. npx <bin> is allowed when the effective cwd has node_modules/.bin/<bin> and no parent is world-writable; scoped names must match the full package; npx --package/--call and versioned specs ask; npm exec <bin> uses the same local-bin rule as npx. Setup writes command_pattern so an older binary still loads the file. A rule that contains an unknown condition type asks when its known conditions match.
Paths are matched after ~ / $HOME expansion, .. collapse, and symlink resolve when the path exists. Guard policy, Claude Code and Cursor hook files, and the activity log cannot be read or written by an agent. Guard is a guardrail, not a sandbox.
An empty or unreadable policy file is not a fail_open case. The hook returns ask and writes a warning to stderr. Stdin larger than 1 MB also returns ask and is not parsed.
