keyfence
A local proxy that stops secrets from reaching LLM APIs. It checks every request to an AI provider before it leaves your machine and blocks, redacts or placeholder-swaps API keys, passwords and other secrets. Works with Claude Code, Cursor, Codex, Aider, curl and anything else that speaks HTTP.
Install
pip install keyfence
Python 3.12 or newer. mitmproxy comes as a dependency.
Use
keyfence import # register your secrets from .env and credential files (hashes only)
keyfence exec -- claude # run a tool through the proxy
keyfence canary .env # plant a fake secret; if a tool ever sends it, you will know
keyfence install-hooks claude-code # stop Claude Code from reading secret files at all
On first run mitmproxy creates a CA certificate in ~/.mitmproxy/. Trust it
once so HTTPS can be inspected (macOS shown, other systems in the
setup guide):
sudo security add-trusted-cert -d -p ssl \
-k /Library/Keychains/System.keychain ~/.mitmproxy/mitmproxy-ca-cert.pem
Modes
| mode | behaviour |
|---|---|
block |
request gets a 403 and is not sent |
redact (default) |
secret becomes [REDACTED:<kind>] |
placeholder |
secret becomes <<SECRET_id>> and the real value is restored in the response, streaming included |
Documentation
- Setup: CA certificate, manual proxy setup, Docker, all commands.
- Detection: the vault, pattern rules, entropy check, what is excluded, the audit log.
- Configuration: every option, environment variables, the system prompt notice.
- Benchmark:
recall by secret format and false positive rate by content type, against
gitleaks, reproducible with
python bench/run.py. - Limitations: what keyfence does not cover and what to combine it with.
- Development: tests, coverage gate, integration script, releasing.
- Changelog
License
MIT. Bundled detection rules come from gitleaks, also MIT.
Release files for keyfence 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keyfence-0.3.4.tar.gz | 72.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keyfence-0.3.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 125.3 kB
Release files / keyfence-0.3.4.tar.gz
| Download URL | keyfence-0.3.4.tar.gz |
|---|---|
| Size | 72.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
adc2594c9422b1470c9ccf5d41faaa18a70f6e23a1e5437bbb52eba21047d768
|
|
BLAKE2b-256 checksum How to use checksums |
2d06682c0c9d90d08f77bb5948f94395c245cd3bc27401e4f0ba2667cc57247e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 11, 2026.
Transparency logRelease files / keyfence-0.3.4-py3-none-any.whl
| Download URL | keyfence-0.3.4-py3-none-any.whl |
|---|---|
| Size | 53.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94020be618c1838738cdac3e1fdd849286efb19aa219256d2b4ed2c27826cd5c
|
|
BLAKE2b-256 checksum How to use checksums |
b533e3430da0af125ef07e4e04f7395d01876a589151f0f15c46a1c408a18154
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 11, 2026.
Transparency log