A lightweight local LLM gateway: outbound requests have their Secrets replaced with equal-length realistic Mocks; responses are restored to real values on the way in — the LLM never touches a real Secret, while your Agent tools keep working.
Docs · Download · Quick Start (site) · Protocol Support · 简体中文
The local Agent Harness (claude-code / opencode / hermes-agent and friends) does your work by stuffing material wholesale into the prompt — code, configuration, terminal output, along with the passwords, private keys, tokens, and cookies in them, all delivered to the LLM vendor's servers. Once that data leaves your machine, it is out of your control: it may end up in LLM vendor logs, be used for model training, or leak in a breach.
And "never put Secrets in the context" is simply not viable in Agent workflows — credentials are exactly what an Agent tool needs to act on real systems on your behalf. Secret Guard resolves this tension: your Agent tools keep working with your Secrets, while the LLM never touches a real value.
The only integration cost is one line: point your Agent tool's API base URL at the local gateway:
Outbound: Agent tool ──real Secret──► secret-guard ──realistic Mock──► LLM vendor
Return: local tools ◄──real Secret── secret-guard ◄──Mock reply──── LLM vendor
- Outbound Redact: Secrets in requests are replaced with equal-length, same-charset realistic Mocks — the LLM keeps working with them, none the wiser.
- Return Restore: when responses come back (tool-call arguments included), Mocks are restored to real values — a curl command carrying a Secret lands on your machine with authentication passing as usual.
A real request, before and after leaving the machine (only the token is fictional):
Agent Harness sends: GITHUB_TOKEN=ghp_0123456789abcdefghijklmnopqrstuvwxyz
LLM vendor receives: GITHUB_TOKEN=2_9rr_61dr1lmv2wf15aotyyt262l3t9_2pt4uih
Every forward is inspectable in the WebUI — session timeline, the LLM's-eye request view with the Mock highlighted, the restored real value on the response side, and an on-demand toggle to capture full request/response bodies for troubleshooting:
- Per-secret strategies:
redact(default, as above) /reject(refuse to forward the request at all, 503) /placeholder(swap for an explicit[REDACTED:{id}]token, doubled as a canary that alerts if the real value ever reappears) /monitor(pass the real value through, audited) — see docs/configuration.md. - Built-in protection of the gateway's own credentials: sg API tokens and registered provider keys are auto-mocked with zero configuration — if a prompt injection talks your Agent into pasting its own gateway token, the vendor only ever sees a Mock.
- Suspected-secret alerts (privacy scan): an opt-in side-channel scanner flags token-shaped values that no registered secret accounts for (API keys, JWTs, cloud credentials, ...) in a WebUI panel — one click prefills registration. It never auto-registers or interferes with forwarding.
- Plan-pool failover (Pool): chain multiple coding-plan subscriptions behind one endpoint; traffic fails over on usage-window exhaustion and back on reset — zero manual intervention.
- Multi-provider routing & cross-protocol translation: model-wildcard routing across providers; OpenAI / Anthropic / Responses translate into each other, streaming included — pick the route that matches your harness, not your upstream.
# Binary archives (Linux x86_64 / ARM64, fully static musl, with SHA256SUMS):
# https://github.com/luochen1990/secret-guard/releases
nix run github:luochen1990/secret-guard -- --help # Nix (flake)
cargo install --git https://github.com/luochen1990/secret-guard # from source (rustc >= 1.96)NixOS users: prefer the
services.secret-guard.*structured options (config validated at eval time) → docs/deployment-nixos.md. OIDC login is a cargo feature — default builds ship single-user mode → docs/configuration.md[auth].
secret-guard run # no config file needed — starts empty on 127.0.0.1:8787Open http://127.0.0.1:8787/ — Providers tab: create an entry with the provider URL
and api_key (unsure which protocol it speaks? hit Detect to probe); Secrets tab:
register the value to protect. Entries take effect immediately, no restart, and persist
to secret-guard.state.toml (contains plaintext secrets — keep it out of git). Prefer
declarative, version-managed config? A hand-written secret-guard.toml does the same →
docs/configuration.md.
claude-code — two env vars, zero config:
export ANTHROPIC_BASE_URL=http://127.0.0.1:8787/a/<provider-id>
export ANTHROPIC_AUTH_TOKEN=dummy-key-harness-never-sees-the-real-oneAny OpenAI-compatible client works the same way:
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8787/o/<provider-id>/v1", api_key="ignored")The real API key lives only in your local secret-guard config — the tool itself holds
a dummy value; the gateway injects the real key when forwarding upstream, so even a fully
compromised harness never exposes it. More harness setups (opencode, ...) →
Agent harness integration (site).
On the first protected request, the one-line log summary shows redactions=N — the
replacement count.
URLs take the form /{proto_short}/{provider_id}/*rest, encoding both the ingress
protocol and the target provider:
| proto_short | Protocol | SDK example (base_url) |
|---|---|---|
o |
OpenAI | http://127.0.0.1:8787/o/<provider-id>/v1 |
a |
Anthropic | http://127.0.0.1:8787/a/<provider-id> |
g |
Gemini | http://127.0.0.1:8787/g/<provider-id> |
l |
Ollama | http://127.0.0.1:8787/l/<provider-id> |
r |
Responses (OpenAI Responses API) | http://127.0.0.1:8787/r/<provider-id>/v1 |
The OpenAI SDK needs the
/v1prefix included yourself; the Anthropic SDK appends/v1/messageson its own.
Handing production traffic to an intermediary process requires proof it won't get in the way. The following properties are pinned by property-based tests and end-to-end integration tests, run on every merge to master — and every release is cut from master:
- Transparent relay: without Redact, byte-exact pass-through; with Redact, nothing changes semantically except the real↔mock swap (only serialization noise like field order) — behavior is indistinguishable from a direct connection.
- Strictly reversible: every Mock maps one-to-one to a real value, and Restore is the exact inverse of Redact — tool calls carrying Secrets are never corrupted.
- Deterministic Mocks: a Secret's Mock is stable across turns, preserving the LLM vendor's prefix-cache hits — token cost is unaffected in normal sessions (the mock-escaped-and-replayed exception is documented).
- No collisions in context: a Mock never coincides with other content in the request, so responses are never wrongly replaced.
A source-level comparison with LiteLLM / LLM Guard / PasteGuard — seven secret-protection dimensions, including where the alternatives are stronger: docs/comparison.md.
| Protocol | Forwarding | Secret Redact | Cross-protocol translation |
|---|---|---|---|
| OpenAI (Chat Completions) | ✅ | ✅ | ✅ ⇄ Anthropic (incl. streaming) / ⇄ Responses (incl. streaming) |
| Anthropic (claude) | ✅ | ✅ | ✅ ⇄ OpenAI (incl. streaming) / ⇄ Responses (incl. streaming) |
| OpenAI Responses | ✅ | ✅ (incl. streaming) | ✅ ⇄ Chat Completions / Anthropic (incl. streaming) |
| Gemini / Ollama | ✅ byte pass-through | 🚧 Roadmap | 🚧 Roadmap |
- Gemini / Ollama forward as transparent byte pass-through, but the codec does not cover
them yet — with secrets configured, such requests are rejected by default (503,
[redact] on_unsupported_protocol; the error message carries a hint). - Protocol behavior is pinned by tests against simulated upstreams; real-Provider field validation for Anthropic / Gemini / Ollama has not happened yet (Roadmap) — when first adopting a protocol, verify one real request in the WebUI Records page before going full speed.
Issues and PRs welcome at github.com/luochen1990/secret-guard; the development guide lives in AGENTS.md:
- Gemini / Ollama codec: bring Redact and cross-protocol support to these families
(a new protocol only needs a Reader + Writer trait, ~200 lines) — see
src/codec/AGENTS.md. - Responses streaming fidelity: close the residual known losses (hosted tools / refusal parts dropped, reasoning event normalization) — see docs/known-limitations.md.
- Smarter unknown-secret detection (NER / entropy scoring): accuracy upgrade for the suspect scanner — see #257.
- Real-Provider field validation: integration-test profiles against real upstreams.
- Quick Start walkthrough (first request, curl, logs & troubleshooting) → Quick Start (site)
- Full configuration field reference → docs/configuration.md
- WebUI page-by-page guide → WebUI Guide (site)
- NixOS deployment and credential injection → docs/deployment-nixos.md
- Architecture and dataflow contracts → docs/design/ (contracts.md)
- Source-level comparison with alternatives → docs/comparison.md
- Development workflow / test strategy / module contracts → AGENTS.md
MIT — see LICENSE.

