← Vetro Attest · Free Art. 12/14 checker · Free EU AI Act tools

Audit log for Claude Code sessions

Claude Code runs a separate process invocation per hook event — there is no long-lived process holding a session open the way an in-memory agent loop would. That shapes how an audit log for it has to work: buffer what each event reports, and only assemble the real ledger once, when the session ends.

The hook events that matter

The Vetro pattern

Vetro's Claude Code example buffers PreToolUse/PostToolUse events as plain NDJSON per session, then replays the buffer through one real Run at Stop, keeping ledger creation the single-process operation LedgerWriter already assumes:

{
  "hooks": {
    "PreToolUse":  [{ "hooks": [{ "type": "command", "command": "node /path/to/examples/claude-code-hook.mjs" }] }],
    "PostToolUse": [{ "hooks": [{ "type": "command", "command": "node /path/to/examples/claude-code-hook.mjs" }] }],
    "Stop":        [{ "hooks": [{ "type": "command", "command": "node /path/to/examples/claude-code-hook.mjs" }] }]
  }
}

At Stop, the script opens a Vetro instance from @vetro/core, starts a run, and replays every buffered event through run.toolCall() / run.toolResult() in order, hash-chained and ed25519-signed.

Blocking vs. recording, and why it differs by rule

Policy is checked twice, for different reasons. At PreToolUse, the script loads the policy directly and evaluates it against the pending call; on a block-level match it exits with code 2 — Claude Code's documented mechanism for a hook to stop the tool call and feed the reason back to the model. Only rules that don't need a running total (tool.deny, content.regex) are meaningful at this point. budget.* rules need the accumulated stats a live Run carries, which only exists once the buffer is replayed at Stop — too late to block, but the decision is still recorded as evidence, matching the general trade-off in audit trail for AI agents.

Try it without Claude Code

node claude-code-hook.mjs --demo drives the same three events with synthetic payloads, blocks a destructive shell command at PreToolUse, and prints the ledger path plus the exact verify/report commands to run against it.

Check your own logs

Paste the resulting ledger into the free checker: it verifies the hash chain and signature and shows which record-keeping obligations it covers. For a report to hand to a client or an auditor, Vetro Attest issues a 49 USD counter-signed mapping to EU AI Act articles.

See a sample ledger verified in one click, check your own logs free or get the countersigned EU AI Act report.

Pricing