Skip to content

VIGIL with the Claude Agent SDK

Developers · Updated November 29, 2026 · Docs read 29 November 2026

VIGIL's hook script for Claude Code and the Claude Agent SDK reports what the platform saw, not what the agent said, and since 17 November 2026 it asks VIGIL before every tool runs. One script, adapters/claude_agent_sdk/vigil_hooks.py, handles the SessionStart, PreToolUse, PostToolUse and Stop hooks. This page says what each hook does; the install steps, the settings.json block and the policy call are on the VIGIL docs page it is drawn from.

What each hook sends, and what it does with the answer

The same script answers each hook and reads the hook JSON from stdin. The Claude Agent SDK takes the same shape through its hooks option as Claude Code takes through settings.json.

SessionStart. Asks VIGIL which arm this session is in (POST /observation/assign, episode = the session id) and, when observed, hands the disclosure sentence back as hookSpecificOutput.additionalContext, which Claude Code adds to the model's context. Every later event carries episode_id = the session id; VIGIL_OBSERVATION=0 skips it. It never blocks, and VIGIL being down leaves the session unassigned.

VIGIL docs, Claude Agent SDK hooks (https://docs.vigil.supertruth.ai/adapters/claude-agent-sdk), read 29 November 2026.

PreToolUse. Every tool: a tool_call through POST /tools/check with the tool name, the arguments' SHA-256, the paths the call writes and the hosts it reaches, judged against the tools_policy on the agent's blueprint before the tool runs. Then Write, Edit, MultiEdit, NotebookEdit, and Bash commands that run cp, mv, rm, scp or rsync become a file_operation (operation write, copy, move, delete or transfer), with source platform_hook and actor agent:<session_id>. A deny blocks the tool: exit 2 with the rule that decided, the policy digest and the event id on stderr, which Claude sees; the deny is the one record of the attempt and no file_operation follows it. On allow, a hold, alert or collapse on the file_operation blocks the tool as before.

VIGIL docs, Claude Agent SDK hooks (https://docs.vigil.supertruth.ai/adapters/claude-agent-sdk), read 29 November 2026.

PostToolUse. An edit whose path matches VIGIL_PROTECTED_PATHS becomes a config_write with initiated_by: agent and authorized: false. When held, the hook exits 2 so the reason reaches the model.

VIGIL docs, Claude Agent SDK hooks (https://docs.vigil.supertruth.ai/adapters/claude-agent-sdk), read 29 November 2026.

Stop. An output_generated event with content_length = the transcript file size. It never blocks; it prints the reason if held.

VIGIL docs, Claude Agent SDK hooks (https://docs.vigil.supertruth.ai/adapters/claude-agent-sdk), read 29 November 2026.

The hook fails closed

If VIGIL is unreachable, refuses, or the hook is not configured, the tool is blocked (exit 2) and the reason goes to stderr: the hook fails closed, and since every tool now asks first, that includes Read. VIGIL_FAIL_OPEN=1 lets the tool run and warns instead. The older VIGIL_FAIL_CLOSED is still read: 0 opens, 1 closes, and it wins when both are set.

An agent whose blueprint carries no tools_policy is never denied: every check answers allow, the call is recorded, and the fifth family stays unmeasured for it. The hook does not block on the tool_call event's own gate status, so an agent without a policy keeps every tool whatever its BII; the file_operation path blocks on a hold for the tools it always covered. If the agent is not registered the hook registers it and retries once.

Every tool call is one round trip and one metered event against the plan's monthly cap (a Write, Edit, MultiEdit, NotebookEdit or a Bash cp, mv, rm, scp or rsync records a second event, the file_operation); past the cap the check is a 429 and the fail-closed hook blocks. Every check is a scored event: an agent whose own arithmetic holds it keeps its tools, since the hook blocks on a deny and not on the event's gate, but opens a new review action (and a webhook where one is subscribed) on every tool call until a reviewer decides or the violation leaves the window.

What the hook reads from a Bash command

Where the command writes, and whom it reaches. The command is tokenized with shlex (operators as tokens), split into segments at ;, &&, ||, | and &, and each segment read against a table of write-capable commands and where their targets sit: redirects (>, >>, &>, >|, with 2> and 2>&1 told apart), tee, cp, mv, rm, chmod, chown, touch, truncate, dd of=, sed -i, perl -i, find -delete and find -exec, git subcommands that rewrite the tree, curl -o, wget -O, scp and rsync. bash -c, sh -c and eval are read recursively; cd is tracked across segments; sudo, env, nice, nohup, time, timeout and xargs are stepped over; relative paths resolve against the hook's cwd. Hosts come from any URL in the command, from ssh, scp and rsync, and from WebFetch's url.

A recursive operation is reported as root/**/name and is denied when a protected file could sit under the root: rm -rf build/ is denied under a */config/*.yaml rule, find build -name '*.o' -delete is not. A target the hook cannot read (a variable its environment does not hold, a command substitution, paths arriving on stdin through xargs) is reported as /**/* and denied whenever any path is protected. Inline interpreter code (python -c, node -e) is scanned for path-like literals when it contains a write call.

Out of reach: a script file run by an interpreter, and a binary the table does not know. Those are documented limits, not guarantees; for a file-system guarantee, run the agent in a sandbox and use the policy for the record and the tools it names.

Configure it

The Claude Code process needs VIGIL_API_URL, a VIGIL_API_KEY with the events:write scope (an adapter key, not one bound to an agent, since the hook says source and actor), VIGIL_AGENT_ID (one registered agent per install), VIGIL_PROTECTED_PATHS (the hook-local list behind file_operation and config_write; the blueprint's tools_policy is what denies) and VIGIL_FAIL_OPEN, whose default of 0 blocks the tool when VIGIL cannot answer.

In ~/.claude/settings.json or the project's .claude/settings.json, the PreToolUse entry carries no matcher, so it fires on every tool: the old Write|Edit|MultiEdit|NotebookEdit|Bash matcher would leave Read, Grep, WebFetch and every MCP tool unchecked. It carries "onFailure": "block", because Claude Code lets the tool run when a hook times out or exits with any code but 0 and 2, which fail-closed cannot allow; the hook exits 2 on its own faults, and its client makes two attempts of two seconds each, so even a Write (the check, then the file_operation) ends under nine seconds, inside the 15-second timeout.

The policy is declared with the organization's admin key on the agent's blueprint. A policy with no allow list leaves tool names unrestricted and lets the deny list, the protected paths and the protected hosts do the work; an allow list takes the names the hook records in tool (Bash, Read, Edit, WebFetch, Agent, mcp__<server>__<tool>), so read a session's recorded calls from GET /audit/{agent_id} before writing one, since an unlisted name is denied. Without a tools_policy the check answers allow with policy_declared: false; declare one with protected_paths: ["*/config/*.yaml"] and the same call answers deny with the rule in policy_reason and the policy's digest in policy_digest, and the hook exits 2 the moment it does.

The exact environment block, the settings.json block, the blueprint call and the example script are on the VIGIL docs page for the Claude Agent SDK hooks.