Two-way secret redaction for OpenCode v2.
opencode-redact replaces API keys, tokens, passwords and other secrets in your
OpenCode conversation with stable placeholders before they are sent to the
model, then swaps them back just before a tool runs. The model never sees the
secret; the tool still gets the real value.
OpenCode v2 changed the plugin API, so V1 privacy plugins such as
opencode-vibeguard no longer load — and v2 ships no built-in redaction.
opencode-redact fills that gap with a small, dependency-free plugin written for
the v2 hook API.
redact rehydrate
prompt ──▶ [REDACTED:aws-access-key:…] ──▶ model ──▶ tool input ──▶ real secret
(prompt + context hooks) (execute.before hook)
prompt— redacts the text you type, before it is persisted.context— redacts the system prompt, message history (including earlier tool output) and tool definitions right before the request is sent.execute.before— swaps placeholders back to the real secret in the tool input, so the command that needs it still works.
Every secret becomes a stable token [REDACTED:<rule>:<fingerprint>]. The same
secret always yields the same token, so the model can still refer to it.
This fork is not published to npm (unlike the upstream project), so it can only be installed as a local plugin.
Global drop-in — copy src/index.ts to
~/.config/opencode/plugins/redact/index.ts. Global plugins are auto-loaded
and need no config entry.
Project-level drop-in — copy src/index.ts to .opencode/plugins/redact.ts
in the project.
Alternatively, point your config at a checkout of this repo:
// ~/.config/opencode/opencode.json { "$schema": "https://opencode.ai/config.json", "plugins": ["/absolute/path/to/opencode-redact/src/index.ts"] }
Restart OpenCode (or run opencode service restart) after copying or changing
the file.
| Rule | Matches |
|---|---|
aws-access-key |
AKIA…, ASIA…, AGPA…, … |
gcp-api-key |
AIza… |
github-pat |
ghp_, gho_, ghu_, ghs_, ghr_ |
github-fine-grained |
github_pat_… |
gitlab-pat |
glpat-… |
openai-key |
sk-…, sk-proj-… |
anthropic-key |
sk-ant-… |
slack-token |
xoxb-, xoxa-, xoxp-, xoxr-, xoxs- |
stripe-key |
sk_live_, sk_test_, rk_live_, rk_test_ |
npm-token |
npm_… |
pypi-token |
pypi-… |
jwt |
three dot-separated base64url segments starting eyJ |
private-key |
PEM -----BEGIN … PRIVATE KEY----- blocks |
credential |
password: …, api_key=…, secret=…, token: … |
At startup the plugin registers the values of every environment variable whose
name ends in KEY (minimum 8 characters). Any occurrence of those exact values
— pasted into the prompt, echoed by a tool (printenv) or shown in a file — is
replaced before it reaches the model, and rehydrated just before a tool runs:
printenv STRIPE_KEY → the model sees [REDACTED:env-stripe-key:0000c281e114]
Tokens for seeded variables are deterministic fingerprints of the value and are
re-registered on every plugin load, so placeholders from earlier history keep
rehydrating across opencode service restart for as long as the variable
remains in the environment.
Protected — your prompt, system prompt, message history (incl. tool output) and tool definitions on the way out; tool input on the way in.
Not protected
- Secret formats not listed above.
- Base64-encoded, encrypted or split secrets, and passwords with no
key = valueshape. - Large/binary strings (
data:URIs, oversized base64) are skipped on purpose so images and files are never corrupted. - The vault is in-process: after a service restart, placeholders in old history can no longer be rehydrated.
- Rehydration depends on the model echoing a placeholder verbatim.
Redaction guards what leaves your machine. It is one layer of defence, not a reason to paste real credentials into a conversation.
OpenCode v2.0.18+ (v2 prompt, context, tool.execute.before hooks) · Node 20+.
npm install npm run build # tsc -> dist/ npm test # build + node --test
This is a fork of opencode-redact
by kk Cheng (@kkchengg), MIT-licensed. The
two-way redaction design, the [REDACTED:<rule>:<fingerprint>] placeholder
format, the detection rules, hooks, rehydration, and the deep-walking redactor
are all the original author's work.
This fork's only addition so far is the *KEY environment-variable seeding
(described above) and its tests. Everything else is upstream, unchanged.
MIT — © kk Cheng, the original opencode-redact author. The fork's additions inherit the same MIT licence.