Fail-closed PHI guardrails for AI coding agents (Claude Code hooks, CLI, git pre-commit)
AI coding agents read whatever is in the working tree and send it to a model. On a healthcare codebase that working tree often holds an eligibility export someone dropped in data/, an 835 remittance file used to debug a parser, an HL7 feed sample, or seed data that started life as a production query. One cat and the agent has sent patient records to a vendor that may not be covered by your BAA.
phi-gate puts a checkpoint on every path that data can take through an agent session, and when it cannot run, it blocks instead of letting things through.
Every block, warning and override is written to a hash-chained log at .phi-gate/audit.jsonl with the event, tool, target and the categories found. Never values, never hashes of values, and file names are recorded as keyed hashes by default. See data handling.
/plugin marketplace add obutuz/phi-gate /plugin install phi-gate@phi-gate Needs python3 (3.11 or newer), bash and git on the machine. No packages to install.
pipx install git+https://github.com/obutuz/phi-gate phi-gate install-git-hook # blocks commits that introduce PHI phi-gate scan . # exit 1 if anything would be blocked With the pre-commit framework (this blocks on any PHI in the files being committed, including PHI committed earlier, where install-git-hook judges only what the commit introduces):
repos: - repo: https://github.com/obutuz/phi-gate rev: v0.2.0 hooks: - id: phi-gate Other agents can be pointed at the CLI with a rule in their instructions file; see examples/AGENTS.md.
git clone https://github.com/obutuz/phi-gate && cd phi-gate ./demo/run-demo.sh The script replays the hook calls Claude Code makes against a throwaway project with synthetic data and prints each decision, then the audit log:
phi-gate scan src/ data/ # human output: path:line:col severity category phi-gate scan --staged --json # machine output for CI phi-gate redact export.csv # placeholder copy on stdout phi-gate redact export.csv --map m.json && phi-gate restore --map m.json < answer.txt phi-gate status # config and recent audit events phi-gate audit verify # exit 1 if the audit log was altered phi-gate explain # every detector and the decision rules Scan a project. Output names the file, line, severity and category, never the value:
Redact a file or a stream. Placeholders are typed and consistent within a file, tables keep their columns, and clinical and financial columns are left alone so the copy is still useful for analysis:
Commit checks run in the git pre-commit hook, for any editor or agent:
Audit: every block, warning and override is logged with event, tool, target and category:
Pure Python standard library, no network calls, no model. Detectors are patterns with validation (check digits, issued ranges, labelled context), plus parsers for the formats healthcare data actually arrives in. Text files are read as UTF-8, UTF-16 or UTF-32, and matched on a normalised view, so invisible characters, Unicode dashes and spaces, fullwidth letters and look-alike letters do not hide an identifier. Every pattern runs in linear time. Containers are opened and their contents scanned: .xlsx, .docx, .pptx, OpenDocument files, zip and gzip archives, and SQLite databases (header plus the first 500 rows of each table), because exports are how patient lists actually travel. The scanner, phi-gate redact and the commit gate all read them the same way. A container that cannot be parsed is blocked, not skipped, and so is a DICOM image, whose header holds the patient's name.
Decision rules. Any HIGH finding blocks. A clinical fact (diagnosis code, date of service) within 400 characters of a name, phone, email or address blocks, because identity plus health information is what PHI is. Other MEDIUM findings only warn: a name next to an email is usually a package.json author field or a staff directory. LOW findings never block.
Synthetic values pass by design. These cannot belong to a real person, so they are never flagged and fixtures written with them just work:
Generated records are different: a Synthea CSV or FHIR bundle still has the shape of a patient record (name and birth-date columns, Patient resources), and phi-gate cannot tell it from a real export. Keep generator output under a folder listed in allow_paths.
Blocking ordinary code would get the plugin uninstalled in a day, so this is measured, not hoped for. Across 4,725 files (69.3 MB: the CPython 3.13 standard library with NumPy and other installed packages), phi-gate blocked 1 file, or 0.02%: a 19-digit integer in NumPy test data that passes the payment card check. Average cost: about 7 ms per file. Reproduce it on your own code:
python3 bench/false_positive_sweep.py path/to/your/repo Configuration Optional .phi-gate.toml at the project root. Everything has a safe default. The annotated version is examples/.phi-gate.toml.
[phi-gate] mode = "block" # block | warn | audit allow_paths = ["tests/fixtures/**"] # synthetic data lives here (gitignore-style globs) allow_values = ["1EG4-TE5-MK73"] # known test values (exact; prefix "re:" for a regex) disable = [] # categories to switch off opaque = "allow" # or "block": refuse formats phi-gate cannot read The configuration reference covers every key, how patterns match, and how layers combine.
Start with mode = "audit" on an existing repo to see what would be blocked, then switch to block.
Prompt override. A prompt that starts with #phi-ok is sent even if it contains identifiers, and the override is logged. Only a person can type a prompt, so the agent cannot use it. Use it only where your organisation has a BAA covering the model provider, or switch it off with prompt_override_token = "".
Managed policy. A security team can install a policy that every repository on a machine must meet and none can loosen; a .phi-gate.toml in a subfolder can only tighten the rules. See the deployment guide.
Be clear-eyed about what a pattern scanner on a developer machine can and cannot do.
The threat model sets out what phi-gate defends against and where that stops. The deployment guide covers rolling it out across a team, and data handling what phi-gate stores and where.
python3 -m unittest discover -s tests # unit, hook, git, property and stress tests ./demo/run-demo.sh # exits 1 if any decision changes claude plugin validate . --strict See CONTRIBUTING.md for the full checks.
.claude-plugin/ plugin.json and marketplace.json (this repo is its own marketplace) hooks/ hooks.json and the fail-closed run.sh wrapper bin/phi-gate CLI, put on the agent's PATH by Claude Code src/phi_gate/ detectors, policy, scanner, shell analysis, redaction, audit, hooks, CLI skills/ hipaa-aware-dev skill and references commands/ /phi-gate:scan, /phi-gate:redact, /phi-gate:status tests/ unit, hook, git, property and stress tests (synthetic data only) bench/ false-positive sweep docs/ threat model, deployment, configuration, data handling, screenshots (synthetic data only) License MIT
Both files in this release have provenance metadata.
hipaa phi pii redaction claude-code healthcare dlp
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Both files in this release have been uploaded with provenance metadata.
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.




