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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keyfence-0.3.3.tar.gz.
File metadata
- Download URL: keyfence-0.3.3.tar.gz
- Upload date:
- Size: 70.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b44d7e56a4299000a8b410d42f327d00785cb6033ae6314b10a5dba2e2e4882
|
|
| MD5 |
2d5473a9813c0f5d0b53539029215f21
|
|
| BLAKE2b-256 |
278892b44ec3f86c1814ec10e989b45d99a36035566adbd72d91be76f3b17173
|
Provenance
The following attestation bundles were made for keyfence-0.3.3.tar.gz:
Publisher:
release.yml on aminueza/Keyfence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyfence-0.3.3.tar.gz -
Subject digest:
4b44d7e56a4299000a8b410d42f327d00785cb6033ae6314b10a5dba2e2e4882 - Sigstore transparency entry: 2770857533
- Sigstore integration time:
-
Permalink:
aminueza/Keyfence@209a48605f13b6d3643dfa737753c8d129859579 -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/aminueza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@209a48605f13b6d3643dfa737753c8d129859579 -
Trigger Event:
push
-
Statement type:
File details
Details for the file keyfence-0.3.3-py3-none-any.whl.
File metadata
- Download URL: keyfence-0.3.3-py3-none-any.whl
- Upload date:
- Size: 52.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6ab4d249eb5e5da72dfc9f313d8f78805604019470e01b1d587cd26d3c1a140
|
|
| MD5 |
4cc98e671d4b6ee7dbfae73688bbf98c
|
|
| BLAKE2b-256 |
6007a3e349c8e63f59895c2d41040d86da2d638411e6cacbb3a09a2c71a838a1
|
Provenance
The following attestation bundles were made for keyfence-0.3.3-py3-none-any.whl:
Publisher:
release.yml on aminueza/Keyfence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyfence-0.3.3-py3-none-any.whl -
Subject digest:
e6ab4d249eb5e5da72dfc9f313d8f78805604019470e01b1d587cd26d3c1a140 - Sigstore transparency entry: 2770857579
- Sigstore integration time:
-
Permalink:
aminueza/Keyfence@209a48605f13b6d3643dfa737753c8d129859579 -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/aminueza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@209a48605f13b6d3643dfa737753c8d129859579 -
Trigger Event:
push
-
Statement type: