Let AI read your code, not your secrets.
LeakShield scans intercepted model requests for API keys, tokens, private keys and personal data. It masks detected values before sending the request.
Node 20+ · OpenCode v2, Pi coding agent and Claude Code
What the model sees
maskedpsql postgres://app:s3cr3t-Pa55@db.internal/prod
psql postgres://app:[SGP2:SECRET-••••]@db.internal/prod
psql postgres://app:s3cr3t-Pa55@db.internal/prod
Illustrative output with synthetic values. The reverse mapping never leaves the machine.
Block if masking fails
Intercepted requests are blocked if masking fails.
Mapping stays home
Placeholders travel to the model; the mapping that turns them back stays here. Persistence is opt-in and encrypted.
Gaps are written down
Every known blind spot is documented and measured, not quietly ignored.
One scanner, five entry points
OpenCode plugin, Pi extension, Claude Code proxy, CLI and Web UI share the same scanner.
How it works
Scan, mask, restore — inside the loop
LeakShield replaces detected sensitive values with placeholders in intercepted model requests. The reverse mapping stays local.
Scan intercepted requests
The same rules scan supported content in intercepted requests, including prompts, replayed history and tool results.
Mask with pseudonyms
Each finding becomes an SGP2 placeholder. The model reasons about a stable token without ever seeing the value.
Restore on your side
Restoration varies by integration. The Claude Code proxy restores assistant text, not tool arguments.
Unintercepted traffic, tool network traffic, and on-disk transcripts and logs are outside this boundary.
LeakShield masks detected sensitive values before forwarding intercepted requests to a model. The reverse mapping stays local.
View full architecture diagram View full architecture diagram
Detection coverage
What it catches
Built-in rules run in every mode — block, redact and transparent — and are extended by your own guard.config.yaml.
| Type | Detects | Severity |
|---|---|---|
| API keys | OpenAI, Anthropic, Google, AWS, Stripe live keys | HIGH |
| Secrets & passwords | Generic password assignments, AWS secret keys | HIGH |
| Tokens | GitHub, Slack, Hugging Face, JWT, Bearer tokens | HIGH |
| Private keys | PEM private key blocks | HIGH |
| DB connection strings | MongoDB, PostgreSQL, MySQL, Redis, ADO | HIGH |
| URL credentials | Only the userinfo span of a URL is masked | HIGH |
| Taiwan national ID | Format validation | HIGH |
| Credit cards | 13–19 digits, Luhn checksum required | HIGH |
| IBAN | Compact or 4-char groups, mod-97 checksum | HIGH |
| NDA keywords | Built-in defaults plus your own list | HIGH |
| Public IPv4 | Private, loopback, CGNAT and reserved ranges excluded | MEDIUM |
| Email addresses | All email formats | MEDIUM |
| Private domains | Your own domain list from the config file | MEDIUM |
| Private IPv4 / VPN | RFC 1918, CGNAT and link-local, or your own private_cidrsopt-in | MEDIUM |
| Taiwan mobile numbers | Digit runs are a measured false-positive sourceopt-in | MEDIUM |
| International phones | Same trade-off as Taiwan numbersopt-in | LOW |
| HTTP(S) URLs | Off by default: always-on masking would flag provider endpointsopt-in | LOW |
Every rule has a stable id and can be toggled in settings.rule_overrides. Not covered: street addresses, dates, IPv6, and generic assignments outside the keyword list or under 8 characters.
Quickstart
Protect a project in three steps
Needs Node.js 20 or later. Pick your host: OpenCode v2, pi or Claude Code. Mapping persistence needs Node 22.13+.
Install the package
The CLI, the OpenCode plugin, the pi extension and the Claude Code proxy ship in one npm package.
npm install -g leakshield
Register the plugin
Add it to your project's opencode.json. With no options, mode defaults to transparent.
{
"$schema": "https://opencode.ai/config.json",
"plugins": [{ "package": "leakshield" }]
}
Check the install
Exit code 0 means PROTECTED or PARTIAL. A missing dist entry point makes OpenCode skip the plugin silently; the doctor catches that. Then run the synthetic-token smoke test from the README.
leakshield --doctor opencode
Install the pi package
Registers the extension in pi's settings.packages. Needs pi 1.6 and Node.js 22.19 or later.
pi install npm:leakshield
Check the install
A package install reports PARTIAL because pi's load order is not verified. List the extension first in settings.extensions to get PROTECTED.
leakshield --doctor pi
Start the proxy
Leave it running; it listens on 127.0.0.1:8787. Experimental: tool-call arguments are not restored yet.
leakshield --claude-code-proxy
Point Claude Code at it
Or set it in the env block of ~/.claude/settings.json. The doctor checks where the base URL comes from and that the proxy answers.
export ANTHROPIC_BASE_URL=http://127.0.0.1:8787
leakshield --doctor claude-code
Or scan from the terminal
# a file, a tree, or stdin
leakshield --file ./src/config.ts
leakshield --dir ./src --format json
cat .env | leakshield --format json
# write a redacted copy
leakshield --redact --file ./notes.md --out ./notes.safe.md
The CLI never sends content to a model. Exit code 1 means findings blocked the scan, which suits CI.
--doctor checks the install from outside the host, not a live session. Before real data, send a synthetic value and confirm the provider sees a placeholder.
Hosts
Works where you already work
The same scanner and decision model sit behind each host. Verification is recorded per host, with the exact versions and stubs used.
OpenCode v2
primaryEnforced ingress gate. Scans prompts, history, tool output and tool definitions; transparent mode also inspects the final provider body. Verified on v2.0.28 and v2.2.5.
Pi
verifiedIn-process extension that wraps fetch, masks the three wire APIs it supports, and restores read/write/edit/bash arguments. Verified on pi 1.6.0.
Claude Code
experimentalPoint ANTHROPIC_BASE_URL at the local proxy. Masks Messages requests and restores assistant text; tool calls are not restored yet.
CLI & Web UI
manualExplicit scans of text, files, directories and CI pipelines, plus a local browser UI and REST endpoint. Not a model boundary.
Limits
What it does not do
LeakShield protects the model boundary, not your machine. Read this before relying on it.
Not an egress firewall
A permitted tool can still send originals through curl, a remote MCP server or any other channel. Destination control belongs to a separate permission layer.
Local copies remain
History, logs, backups and generated files keep whatever you wrote. forget cannot recall copies a backup already took.
Detection has gaps
Addresses, dates, IPv6 and short generic assignments pass through. Checksum rules only fire on valid checksums; IP detection covers public IPv4.
Coverage is versioned
Each host reports PROTECTED, PARTIAL or BROKEN. A plugin registered but not loaded looks normal — run --doctor and the smoke test.
FAQ
Questions people ask first
Does it send my data anywhere?
LeakShield itself sends nothing. Scanning, masking and restoring happen on your machine, and only the masked request your host already makes reaches the provider. Host telemetry, traffic that bypasses the interception point (Claude Code's WebFetch hostname check, for one), and tools you allow to run are outside that boundary.
What happens when masking is impossible?
The request is refused. LeakShield is fail-closed: an unrecognised shape, an invalid config or a missing mapping stops the call instead of forwarding the original.
Where do the placeholders and keys live?
Placeholders are per-session pseudonyms. Their reverse mapping stays on your machine: in memory by default, or, for OpenCode and pi, in an opt-in encrypted database (SGP.db) whose key the OS keychain holds, with a keyfile fallback for headless machines.
How do I add my own keywords and domains?
Copy config/guard.config.example.yaml to ~/.leakshield/guard.config.yaml (or ./config/ for one project) and add NDA keywords, private domains, allowlists or settings.rule_overrides. An unknown rule id fails the config load rather than being ignored.
Is it production ready?
It is a 0.x release and defaults can still change. Verified hosts and versions are listed above and in the repository; treat unverified combinations as unproven.
How do I report a vulnerability?
Privately, through the security policy in the repository. Please do not open a public issue for a bypass.