This tutorial explains how to add dejavu — an OpenCode plugin that provides cross-session memory for AI coding agents — so recurring tool-call failures become teachable reminders and, if ignored, session-level blocks. It shows prerequisites, installation, the default workflow, how dejavu decides remind vs block, important edge cases, verification steps, and operational trade-offs.
- dejavu detects recurring failing tool calls across sessions and promotes recurring patterns into gates that remind first and block on same-session repeat.
- Diagnostics (linters, tests, builds) are annotated but never blocked; only non-diagnostic bash commands with preserved identity can become blocking gates.
- Signatures and persisted snippets are scrubbed of secrets and terminal control characters; gates expire after 60 days of inactivity.
What problem dejavu solves
Agents often repeat identical failing commands across sessions because session state and ad-hoc rules don’t persist. dejavu builds a mechanical, conservative memory: it detects repeating tool-call failures, records a normalized signature, and escalates a pattern into a gate that first reminds the agent (so the agent sees a correction) and only becomes a hard block if the agent repeats the exact failing call in the same session after seeing the reminder.
Prerequisites
- OpenCode installed and configured on the machine where the agent runs.
- Bun (runtime for the dejavu TypeScript package) available where you install the plugin.
- Write access to your OpenCode config directories: global (~/.config/opencode/) or project-level opencode.json.
Outcome you’ll achieve
After installation, repeated failing commands (bash, read/edit/write/glob/grep and similar tool calls) will be tracked across sessions. When a pattern reaches the promotion threshold, the next occurrence will show a [dejavu] REMINDER containing a CORRECTION and evidence. If the agent repeats the exact call in the same session after the reminder, dejavu will hard-block further attempts for that session.
Installation — step-by-step
- Create (or update) an OpenCode plugin entry so OpenCode will load dejavu. Example places OpenCode reads: ~/.config/opencode/opencode.json or project opencode.json. Add “opencode-dejavu” to the plugin array.
{ "plugin": ["opencode-dejavu"] }(Do not invent new menu labels; this is the documented plugin-entry mechanism.)
- Clone the dejavu source into OpenCode’s vendor folder and install Bun dependencies:
git clone https://github.com/WhiteBite/opencode-dejavu ~/.config/opencode/vendor/dejavu cd ~/.config/opencode/vendor/dejavu && bun install
- Expose the plugin to OpenCode by exporting Dejavu from your plugin index. Example file: ~/.config/opencode/plugins/dejavu.ts
export { Dejavu } from "../vendor/dejavu/index.ts" - Copy the companion skill and status command into your OpenCode config if you want the agent-facing help commands:
- skills/dejavu/ → ~/.config/opencode/skills/dejavu/
- command/dejavu.md → ~/.config/opencode/command/dejavu.md
- Restart OpenCode so the plugin is loaded and dejavu begins observing tool calls.
How dejavu works (implementation workflow)
High-level flow dejavu uses:
- Observe a tool call that exits with code ≥ 2 (diagnostic tools that exit 1 are explicit exceptions and do not count as failures).
- Normalize the command’s signature: strip paths, numbers, hashes, and remove terminal control characters. For some small payloads that are identity-bearing (python -c, node -e), the code payload is hashed to preserve identity.
- Pass all signatures and snippets through secret scrubbing (common API keys, tokens, PEM blocks, DB strings) before any persistence.
- Count occurrences across sessions and project directories. A pattern that reaches 3 failures across at least 2 distinct sessions gets promoted to a gate.
- Gate behavior: first escalation shows a [dejavu] REMINDER with CORRECTION and EVIDENCE; if the agent repeats the same normalized call in the same session after seeing the reminder, dejavu enforces a hard block for the session.
Scope and storage
dejavu uses two scopes for evidence:
- Repo-level:
<repo>/.opencode/dejavu/stores repository-specific gates and can be committed to VCS for team sharing. - Agent/global: ~/.config/opencode/dejavu/ stores agent-level patterns that were seen across multiple projects.
An index (index.json) tracks how many distinct project directories a pattern has appeared in; patterns seen in 2+ project dirs escalate to the global store.
Remind vs Block policy and notable rules
- Remind first, block on ignored reminder. Pure blocking encourages evasive agent behavior; reminding teaches corrective action before hard enforcement.
- Diagnostics (build/test/lint tools) are treat-as-diagnostics: they never block. Their failing output is annotated with a [dejavu] NOTE (once per session) but the run proceeds.
- File probes (read/edit/write/glob/grep) are watch-only: measured and visible but never interrupting.
- Commands without residual identity (eg. fully parameterized signatures where identity is stripped) cannot become blocking; they degrade to watching/evidence only.
- Foreground long-running dev servers are treated specially: dejavu will interrupt calls that would block and strand processes and instead prompt a detached-run reminder. Detached or explicitly one-shot builds proceed normally.
Gate lifecycle, decay and feedback
- Gates expire after 60 days without recurrence and are dropped automatically.
- Each gate tracks recurredAfterGate: how often the pattern reappeared after a gate fired. This metric is the primary signal of whether gates teach or just add friction.
- If a gate fires but keeps failing (3+ recurrences across 2+ sessions after being promoted) or is repeatedly explicitly bypassed (5+ dejavu:proceed overrides on a blocking gate), dejavu demotes that gate to watching-only (feedbackDemoted), avoiding persistent friction. A human can manually re-enable enforcement by clearing feedbackDemoted and resetting the gate status.
Validation and testing steps
- Trigger a non-diagnostic failing bash command once or twice in a repo and restart OpenCode. Confirm that failures are recorded in the repo-level store.
- Reproduce the failing call across 2 sessions (separate OpenCode runs). After 3 failures across 2 sessions the gate should promote; the next occurrence should display a [dejavu] REMINDER explaining the correction and evidence count.
- After the reminder, deliberately repeat the identical normalized call in the same session. Expect dejavu to hard block further identical attempts that session.
- Verify diagnostic tools (for example tsc/pytest) still run and that failing exit 1 does not increment dejavu failure counters. Also check that test/build runs produce a single [dejavu] NOTE rather than blocking.
- Inspect the persisted gate files in the repo
.opencode/dejavu/or global store to confirm secret scrubbing and that control characters are stripped.
Common mistakes and troubleshooting
- Assuming every failing command will block. Only non-diagnostic bash commands with sufficient identity and recurrence can become blocking. Diagnostics and over-generic signatures remain watching-only.
- Not accounting for normalization: dejavu strips paths/numbers/hashes. If two failing commands differ only by a path or numeric argument they may be conflated or normalized away. Use more deterministic call shapes for reproducible behavior when validating.
- Expecting immediate blocking after first failures. dejavu promotes after patterns meet the threshold (3 failures in 2+ sessions), then reminds once before blocking on same-session repeat.
- Overlooking secret scrubbing: if you inspect persisted signatures, sensitive tokens will be removed or replaced by placeholders. This is expected behavior.
- Misinterpreting exit codes: exit 1 from linters/tests is treated as diagnostic (not a failure). Only exit codes ≥ 2 count as failures.
Edge cases and important trade-offs
- No LLM in the hot path: dejavu chooses mechanical normalization and counting for reliability. That avoids flaky classification but limits semantic understanding of complex errors.
- Conservative blocking policy avoids an arms race where agents simply swap tools to dodge blocks, but it allows repeated human-accepted workarounds to persist until manually reviewed.
- Generic signatures are intentionally non-blocking because they could catch unrelated legitimate commands; stricter enforcement requires preserved identity in the signature.
- Gates can be demoted automatically if they generate too much friction. This preserves developer flow but requires human review for systemic issues.
Practical use cases
- Stop an agent from repeatedly running a destructive rm invocation across projects by surfacing a corrective reminder and then session-level blocking if ignored.
- Surface common mis-invocations (wrong CLI flags, path mistakes) across teammates using committable repo-level gates.
- Collect cross-project agent habits into the global store to reduce repeated mistakes that span repositories.
Short FAQ
- Q: Will dejavu block my test runs? A: No. Diagnostics that exit 1 (tests, linters, builds that signal issues via exit 1) are annotated but never blocked; only non-diagnostic bash with exit ≥ 2 can become blocking.
- Q: Are secrets stored? A: No. dejavu scrubs known secrets and token patterns before persisting anything.
- Q: Can a gate be re-enabled after demotion? A: Yes — a human can clear feedbackDemoted and reset status to re-promote enforcement.
- Q: How long before a gate expires? A: Gates expire after 60 days without recurrence.
Validation checklist before production use
- Confirm Bun and OpenCode plugin path are correct and that “export { Dejavu } from \”../vendor/dejavu/index.ts\”” is reachable by OpenCode.
- Run a set of controlled failing commands and confirm the gate lifecycle: record → promote → remind → block-on-repeat.
- Check persisted gate files for secret scrubbing and absence of ANSI escapes.
- Monitor recurredAfterGate and feedbackDemoted metrics for the first 2–4 weeks to ensure gates teach and don’t add net friction.
dejavu is built to be conservative and mechanical: it trades semantic classification for robust, auditable recurrence detection. For teams running long-lived agents, it provides a teach-first, block-if-ignored mechanism that can be committed at the repo level or escalated to an agent-wide store when patterns repeat across projects.
