VibeGuard for OpenCode V2. Ported from the V1 plugin
opencode-vibeguard@0.1.0 (MIT, by inkdust2021).
Replaces configured sensitive strings with __VG_<CATEGORY>_<hash12>__ placeholders before requests
reach the LLM provider, and restores them before local tools execute so tools always run with
real values.
# from GitHub
opencode plugin add github:AxeForce/opencode-vibeguard-v2
# from a local checkout
opencode plugin add /absolute/path/to/opencode-vibeguard-v2
# or via config
# "plugins": ["github:AxeForce/opencode-vibeguard-v2"]OpenCode V2 also auto-discovers global plugins from ~/.config/opencode/plugins/; dropping this
directory there works too.
| V1 hook | V2 equivalent |
|---|---|
experimental.chat.messages.transform |
ctx.session.hook("context" | "compaction" | "generate" | "title") |
tool.execute.before |
ctx.tool.hook("execute.before") |
experimental.text.complete |
❌ not available in OpenCode 2.0.1 (see below) |
The port redacts text / reasoning / compaction parts, tool-call inputs, tool-result
outputs, and system parts (event.system[].text, which V1 could not see).
Both transforms are copy-on-write: they never write into the objects they receive, and hand a
transformed copy back through the hook event (event.input, event.messages, event.system).
That is load-bearing, not stylistic:
- OpenCode freezes some tool inputs. The
questiontool's input is frozen, so an in-placeargs[key] = restoredthrowsAttempted to assign to readonly property.and the call dies before the prompt renders. Onlyquestionwas affected, which made it look like a core bug. - Writing into message parts also leaks placeholders into the stored session, because the parts are
the same objects OpenCode persists. The model then sees
__VG_...__in its own history forever, and anything it writes to disk inherits the placeholder.
Redaction turns a value into an opaque token. Fine for a secret the model never has to reason about.
Wrong for a value it has to act on — a host to scan, a service to reach. Handed
__VG_IPV4_1a2b3c4d5e6f__ instead of the target address, the model did not ask: it invented
10.18.200.101, wrote it into scope.md, coverage.md and findings.json, and the restore path
converted the invention back into a real-looking address on disk. No error was raised anywhere.
Two guards:
patterns.keep_private_ipv4(defaulttrue): RFC1918 / loopback / link-local IPv4 is left alone, because those are the addresses an agent is normally told to operate on. Public addresses are still tokenized. Setfalseto tokenize everything.- Token contract note: when a request carries a token, a system part is appended saying a token is a handle, not a value — pass it through verbatim, never substitute an invented value, say "redacted" rather than guessing. Added once, only when a token is present.
V2 has no working response-side restore hook on OpenCode 2.0.1. If the model echoes a placeholder in assistant text, the local transcript shows the placeholder. Tested and rejected:
| Approach | Result |
|---|---|
ctx.aisdk.hook("language", ...) wrapping LanguageModelV3 |
Hooks register (ctx.aisdk exists) but are never triggered by the runtime |
ctx.session.hook("http.response", ...) replacing the response body |
Hook fires, but the replaced event.response is discarded: the trigger wraps object fields in immer drafts and resets the field with finishDraft(draft) after hooks |
session.text.ended event |
Read-only, cannot write back |
What still works: the provider never sees plaintext, and tools always receive restored values
(including write / edit / bash). Only the rendered/stored assistant text keeps placeholders.
Practical asymmetry:
- Tool results and files contain real values (they are stored as produced, e.g. a
readorbrowser.tabs.listresult shows real IDs). - Model-authored text and tool-call arguments keep placeholders in the transcript, because
OpenCode persists the model output before the
execute.beforerestore runs and offers no API to rewrite stored messages. The execution itself still uses the restored values.
Wanted? File an upstream feature request for a text-mutation hook (the V1
experimental.text.complete equivalent).
Config lookup order (first match wins):
OPENCODE_VIBEGUARD_CONFIGenv var<location>/vibeguard.config.json<location>/.opencode/vibeguard.config.json~/.config/opencode/vibeguard.config.json
Plugin instances are location-scoped, so project configs are found before the global one. The plugin
is a no-op when no config is found or enabled=false. See vibeguard.config.json.example.
Invalid regex rules are skipped at setup with an error log instead of breaking every model request.
Builtin patterns: email, china_phone, china_id, uuid, ipv4, mac. Add your own secrets as
keywords and regex entries.
Debug: set "debug": true in the config or OPENCODE_VIBEGUARD_DEBUG=1. Debug writes load
diagnostics to <tmpdir>/opencode-vibeguard-trace.log.
npm testRequires Node 20+. Zero runtime dependencies; the plugin only uses Node builtins.
MIT. Original plugin and VibeGuard placeholder format by inkdust2021.