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.

pip install keyfence
Python 3.12 or newer. mitmproxy comes as a dependency.
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
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
| 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 |
python bench/run.py.MIT. Bundled detection rules come from gitleaks, also MIT.
4 commits
Python
95.0%
Shell
4.6%
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.

pip install keyfence
Python 3.12 or newer. mitmproxy comes as a dependency.
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
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
| 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 |
python bench/run.py.MIT. Bundled detection rules come from gitleaks, also MIT.
4 commits
Python
95.0%
Shell
4.6%