0.4.0 · experimental Apache-2.0 local only

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

masked
You write psql postgres://app:s3cr3t-Pa55@db.internal/prod
Sent to the model psql postgres://app:[SGP2:SECRET-••••]@db.internal/prod
Restored locally for supported tool calls psql postgres://app:s3cr3t-Pa55@db.internal/prod

Illustrative output with synthetic values. The reverse mapping never leaves the machine.

Fail-closed

Block if masking fails

Intercepted requests are blocked if masking fails.

Local

Mapping stays home

Placeholders travel to the model; the mapping that turns them back stays here. Persistence is opt-in and encrypted.

Honest

Gaps are written down

Every known blind spot is documented and measured, not quietly ignored.

Portable

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.

1

Scan intercepted requests

The same rules scan supported content in intercepted requests, including prompts, replayed history and tool results.

2

Mask with pseudonyms

Each finding becomes an SGP2 placeholder. The model reasons about a stable token without ever seeing the value.

3

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 keysOpenAI, Anthropic, Google, AWS, Stripe live keysHIGH
Secrets & passwordsGeneric password assignments, AWS secret keysHIGH
TokensGitHub, Slack, Hugging Face, JWT, Bearer tokensHIGH
Private keysPEM private key blocksHIGH
DB connection stringsMongoDB, PostgreSQL, MySQL, Redis, ADOHIGH
URL credentialsOnly the userinfo span of a URL is maskedHIGH
Taiwan national IDFormat validationHIGH
Credit cards13–19 digits, Luhn checksum requiredHIGH
IBANCompact or 4-char groups, mod-97 checksumHIGH
NDA keywordsBuilt-in defaults plus your own listHIGH
Public IPv4Private, loopback, CGNAT and reserved ranges excludedMEDIUM
Email addressesAll email formatsMEDIUM
Private domainsYour own domain list from the config fileMEDIUM
Private IPv4 / VPNRFC 1918, CGNAT and link-local, or your own private_cidrsopt-inMEDIUM
Taiwan mobile numbersDigit runs are a measured false-positive sourceopt-inMEDIUM
International phonesSame trade-off as Taiwan numbersopt-inLOW
HTTP(S) URLsOff by default: always-on masking would flag provider endpointsopt-inLOW

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.

ALLOWNo findings. Safe to send.
WARNLow-severity findings. A reminder is shown; sending is allowed.
CONFIRMMedium or high findings. Explicit confirmation, or the request is blocked.

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+.

1

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
2

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" }]
}
3

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

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

primary

Enforced 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

verified

In-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

experimental

Point ANTHROPIC_BASE_URL at the local proxy. Masks Messages requests and restores assistant text; tool calls are not restored yet.

CLI & Web UI

manual

Explicit 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.