Skip to main content

keyfence

CI PyPI License: MIT

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. Coding agents read .env files and credential stores and send what they find to the model; keyfence makes sure the values never arrive.

How keyfence sits between your tools and the provider

Try it in one minute

uv tool install keyfence     # or: pipx install keyfence, or pip install keyfence
keyfence demo                # shows what each mode does to a fake request, no network

keyfence demo: the same request in audit, redact, placeholder and block mode

Use it

keyfence import              # register your own secrets: .env files and credential stores, hashes only
keyfence exec -- claude      # run Claude Code through the proxy

That is the whole setup for Claude Code, pi, Codex, Aider, curl and anything built on the Python or Node SDKs: keyfence exec starts the proxy, points the command at it and hands it the CA certificate, then stops the proxy when the command exits. No sudo, nothing changes on your system.

Not sure it is working? keyfence doctor checks every piece and says what to fix; keyfence selftest sends a throwaway secret through a fresh proxy and checks what comes out the other side. keyfence status shows what has been caught.

Two more layers, both optional:

keyfence install-hooks claude-code   # Claude Code refuses to read secret files at all
keyfence install-hooks pi            # same for pi, as a pi extension
keyfence canary .env                 # plant a fake secret; if a tool ever sends it, you will know

Modes

Set mode in ~/.keyfence/config.yaml.

mode behaviour
audit log what would have been caught, change nothing; start here to see what your tools send
redact (default) secret becomes [REDACTED:<kind>]
placeholder secret becomes <<SECRET_id>> and the real value is restored in the response, streaming included
block request gets a 403 and is not sent

What it catches

Your own secrets, whatever their format, once registered with keyfence import (from .env files, ~/.aws/credentials, ~/.netrc, ~/.npmrc, ~/.docker/config.json, or --from op|vault|doppler|aws); 240 known formats through built-in rules and the bundled gitleaks ruleset; and high-entropy strings that look like secrets. Only salted hashes are stored. Details and numbers in the benchmark.

Verified with

Claude Code (through exec, --local and the hook), pi (through exec and the extension), the Anthropic and OpenAI HTTP APIs, curl, Python and Node clients. GitHub Copilot, Vertex AI and Azure AI hosts are on the default list but have not been tested end to end. Cursor and Windsurf route through their own backends and are not on the list; add their hosts with extra_hosts if you want to try, and an issue with the result helps either way.

Documentation

  • Setup: install options, GUI apps and system-wide trust, capturing tools that ignore proxies, 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.
  • Claude Code plugin: the hook and two skills, installable with /plugin marketplace add aminueza/keyfence.
  • Agents: what install-hooks does for Claude Code and for pi.
  • Agent hook contract: the wire format of keyfence hook, the tool names and fields per agent, and how to wire up another agent.
  • Security: what the proxy sees, what it stores, how releases are built.
  • Development and Changelog.

License

MIT. Bundled detection rules come from gitleaks, also MIT.

Release files for keyfence 0.6.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 keyfence 0.6.0
File Size Uploaded
keyfence-0.6.0.tar.gz 114.5 kB Details

Built distribution (wheel)

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

Total release size: 188.6 kB

Release files / keyfence-0.6.0.tar.gz

Download URL keyfence-0.6.0.tar.gz
Size 114.5 kB
Tags Source
SHA-256 checksum
How to use checksums
da85ad2f7407ef433dca6f6a709af1d552527826d4506e7645afb4b0f61f53d1
BLAKE2b-256 checksum
How to use checksums
2dcef562be43859ce1587409c6ee1b489d4037b4507e2def41d0d80886014b4f
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 24, 2026.

Transparency log

Release files / keyfence-0.6.0-py3-none-any.whl

Download URL keyfence-0.6.0-py3-none-any.whl
Size 74.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b7ec5c235ee4893350d19e9daf5d9e7006cbc284b88df8d34b08ef5aa147744
BLAKE2b-256 checksum
How to use checksums
500247848d2ed99945433fac99501d7bdedee99598579960f78d23828921563d
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 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

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