Stops your AI coding agent from repeating the same mistakes.
opencode-dreams is an OpenCode plugin that reflects on every coding session and consolidates failure modes, learned patterns, and preferences into a persistent knowledge base. That knowledge is automatically injected back into every future session — so your agent stops hitting the same walls, making the same wrong choices, and asking the same questions twice.
Inspired by the OpenDream conceptual model. This repository is the OpenCode-specific implementation: concrete plugin packaging, external memory integrations, and a hardened baseline validated through eight phases of adversarial regression testing. Credit for the underlying Reflect/Dream backbone belongs to the original OpenDream work and its maintainers.
What it does in one sentence: after each session the agent reflects on what went wrong and what worked, consolidates that into durable memory, and injects it into every session that follows.
- Failure mode tracking — mistakes, wrong approaches, and dead ends are explicitly captured and stored as
failure_modememory entries so they are never repeated - Pattern and preference learning — workflows, tool sequences, and preferences compound across sessions into
pattern,workflow, andpreferenceentries - Automatic session capture — live events are recorded as they happen; no manual export needed
- Two-stage pipeline — Stage 1 (Reflect) analyses each session; Stage 2 (Dream) consolidates across all sessions into generalizable knowledge
- Durable
AGENTS.mdexport — consolidated memory is written into a managed block your agent reads at the start of every session - External memory sync — pulls in memories from
opencode-mem,true-mem,simple-memory, andopencode-lcm - 15 composable tools — call any stage individually or chain the full pipeline in one go
- Hardened and tested — 182/182 tests across 8 adversarial hardening phases; structured error boundaries throughout
- MIT licensed — free to use, modify, and distribute
Live session / imported trace
-> Stage 1: Reflect
-> Stage 2: Dream
-> memory/current.md
-> AGENTS.md
- End-to-end pipeline is implemented
- Hardening baseline spans Phases 1–8
- Latest verified baseline: 182/182 tests passing
See also:
docs/ARCHITECTURE.mddocs/INSTALL.mddocs/OPENDREAM-MAPPING.mddocs/adversarial-hardening-status.md
Give this prompt to your AI agent (in any OpenCode session) to have it install and configure opencode-dreams automatically:
Please set up the opencode-dreams plugin in this project by doing the following steps in order:
1. Run: npm install opencode-dreams
2. Open or create opencode.json in the project root. Add opencode-dreams to the plugin array with this config:
{
"$schema": "https://opencode.ai/config.json",
"model": "github-copilot/gpt-5.4",
"provider": { "github-copilot": {} },
"plugin": [
["opencode-dreams", {
"preferredReflectModel": "github-copilot/gpt-5.4",
"preferredDreamModel": "github-copilot/gpt-5.4",
"captureLiveSessions": true,
"logLevel": "info"
}]
]
}
If opencode.json already exists and has a plugin array, append the opencode-dreams entry to it. Do not remove existing plugins.
3. Call opendream_init to create the .opencode-dream/ workspace layout.
4. Call opendream_info to confirm the plugin is running.
5. Tell me the current pipeline status shown by opendream_info.
Adjust
"model"and"preferredReflectModel"/"preferredDreamModel"to whatever model you are using in OpenCode.
- OpenCode installed and configured
- Node.js
>=20 - A model available in your OpenCode setup for reflection and consolidation
Supported models (examples):
| Provider | Model ID | Notes |
|---|---|---|
| GitHub Copilot | github-copilot/gpt-5.4 |
Recommended — fast, strong reasoning |
| GitHub Copilot | github-copilot/gpt-4.5 |
Good alternative |
| GitHub Copilot | github-copilot/claude-sonnet-4-5 |
Strong for nuanced reflection |
| Anthropic | anthropic/claude-sonnet-4-5 |
If using Anthropic provider |
| Anthropic | anthropic/claude-opus-4-5 |
Best quality, slower |
| OpenAI | openai/gpt-4o |
If using OpenAI provider |
| OpenAI | openai/o3 |
Strong reasoning for consolidation |
| AWS Bedrock | aws/claude-sonnet-4-5 |
If using Bedrock provider |
Any model available in your OpenCode provider config works. Use the same format: providerID/modelID.
npm install opencode-dreamsIn your project root, open (or create) opencode.json and add opencode-dreams to the plugin array:
Start an OpenCode session and tell your agent:
Call opendream_init to set up the workspace.
This creates the .opencode-dream/ directory layout and optional AGENTS.md markers. Only needed once per project.
Call opendream_info to confirm the plugin is running and show pipeline status.
| Option | Type | Default | Description |
|---|---|---|---|
preferredReflectModel |
string | — | Model for Stage 1 reflection (e.g. github-copilot/gpt-5.4) |
preferredDreamModel |
string | — | Model for Stage 2 consolidation |
projectRelativeStateDir |
string | .opencode-dream |
Where plugin state is stored relative to project root |
captureLiveSessions |
boolean | true |
Auto-capture live session events |
logLevel |
string | info |
debug | info | warn | error |
opencodeMem.enabled |
boolean | false |
Enable opencode-mem integration |
opencodeMem.url |
string | http://127.0.0.1:4747 |
opencode-mem server URL |
opencodeMem.importMode |
string | append |
append or replace when merging external memories |
If you want to use a local clone instead of the published package:
git clone https://github.com/Ryurexflipper/Opencode-Dreams.git
cd Opencode-Dreams
npm install && npm run buildThen in opencode.json point to the built output directly:
{
"plugin": [
["file:///ABSOLUTE/PATH/TO/Opencode-Dreams/dist/src/index.js", {
"preferredReflectModel": "github-copilot/gpt-5.4",
"preferredDreamModel": "github-copilot/gpt-5.4"
}]
]
}- auto-captures live sessions into
.opencode-dream/sessions/live/ - stores transient capture state in
.opencode-dream/sessions/runtime/ - imports external traces into
.opencode-dream/sessions/imports/
- renders reflection prompts
- runs LLM-backed reflection for one session or in batch
- imports externally generated reflection JSON
- stores validated reflections in
.opencode-dream/reflections/
- renders consolidation prompts
- runs LLM-backed consolidation across stored reflections
- stores validated dream outputs in
.opencode-dream/dreams/
- applies consolidation entries into
.opencode-dream/memory/current.md - exports current memory into one managed
AGENTS.mdblock - injects consolidated memory into session compaction context
- supports:
opencode-memtrue-memsimple-memoryopencode-lcm
- merges each source into tagged blocks inside
memory/current.md
The plugin registers three hooks:
event— live session captureshell.env— exports resolved state/model env varsexperimental.session.compacting— injects current memory into compaction
.opencode-dream/
sessions/
imports/
live/
runtime/
reflections/
dreams/
memory/
current.md
docs/
README.md
The plugin currently exposes 15 tools:
- setup/status
opendream_infoopendream_initopendream_memory_status
- session ingest
opendream_ingest_generic_jsonl
- Stage 1 reflection
opendream_reflect_promptopendream_reflect_import_jsonopendream_reflect_runopendream_reflect_batch
- Stage 2 dream
opendream_dream_promptopendream_dream_run
- memory/export
opendream_memory_applyopendream_export_agents
- external memory
opendream_mem_probeopendream_mem_syncopendream_ext_mem_sync
Run these tools inside an OpenCode session (tell your agent to call them by name):
1. opendream_info — check plugin status and pipeline state
2. opendream_reflect_run — reflect on the most recent session
3. opendream_dream_run — consolidate all reflections into memory
4. opendream_memory_apply — write consolidation into memory/current.md
5. opendream_export_agents — update AGENTS.md with current memory
After a few sessions, memory compounds automatically — each Dream pass builds on prior ones.
| Tool | What it does |
|---|---|
opendream_info |
Shows plugin config, tool inventory, and current pipeline state (session/reflection/dream counts) |
opendream_init |
Initialises the .opencode-dreams/ workspace layout and optional AGENTS.md markers |
opendream_memory_status |
Shows the current memory file path, size, and whether markers are intact |
| Tool | What it does |
|---|---|
opendream_ingest_generic_jsonl |
Validates and stages a JSONL session export into the import queue for reflection |
| Tool | What it does |
|---|---|
opendream_reflect_prompt |
Renders the reflection prompt for a stored session (for manual inspection or external LLM use) |
opendream_reflect_import_json |
Validates and stores a reflection JSON you produced externally |
opendream_reflect_run |
Runs LLM-backed reflection for a single session |
opendream_reflect_batch |
Runs LLM-backed reflection for all un-reflected sessions in one pass |
| Tool | What it does |
|---|---|
opendream_dream_prompt |
Renders the consolidation prompt across all stored reflections (for manual inspection) |
opendream_dream_run |
Runs LLM-backed consolidation and saves the dream output |
| Tool | What it does |
|---|---|
opendream_memory_apply |
Applies the latest dream consolidation into memory/current.md |
opendream_export_agents |
Writes current memory into the managed block in AGENTS.md |
| Tool | What it does |
|---|---|
opendream_mem_probe |
Reads raw items from the opencode-mem server without writing anything |
opendream_mem_sync |
Pulls opencode-mem memories into memory/current.md |
opendream_ext_mem_sync |
Pulls from all configured external memory sources in one command |
opencode-mem is a separate memory server that stores memories independently of sessions. opencode-dreams can pull those memories into its own pipeline so agents always have both kinds of context.
Step 1 — Enable opencode-mem in your opencode.json:
{
"plugin": [
["opencode-dreams", {
"preferredReflectModel": "github-copilot/gpt-5.4",
"preferredDreamModel": "github-copilot/gpt-5.4",
"opencodeMem": {
"enabled": true,
"url": "http://127.0.0.1:4747",
"importMode": "append",
"maxItemLength": 1000
}
}]
]
}| Option | Default | Description |
|---|---|---|
enabled |
false |
Must be true to activate the integration |
url |
http://127.0.0.1:4747 |
Base URL of your running opencode-mem server |
importMode |
"append" |
"append" replaces the existing block or adds it; "replace" rebuilds the whole memory file |
maxItemLength |
1000 |
Truncates long memory items to this character limit |
Step 2 — Sync memories during a session:
Tell your agent:
Call opendream_mem_sync to pull my opencode-mem memories into the pipeline.
Or use the unified command to sync all sources at once:
Call opendream_ext_mem_sync to pull from all external memory sources.
You can also pass arguments:
Call opendream_mem_sync with url="http://127.0.0.1:4747" and dryRun=true
Step 3 — After sync, export to AGENTS.md:
Call opendream_export_agents to write the updated memory into AGENTS.md.
Recommended session start sequence with opencode-mem:
1. opendream_ext_mem_sync — pull latest external memories
2. opendream_reflect_batch — reflect any un-processed sessions
3. opendream_dream_run — consolidate everything
4. opendream_memory_apply — persist to memory/current.md
5. opendream_export_agents — update AGENTS.md
These can be set in .env or your shell — they are optional overrides. The plugin config in opencode.json takes priority.
| Variable | Description |
|---|---|
OPENCODE_DREAM_REFLECT_MODEL |
Model to use for Stage 1 reflection (e.g. github-copilot/gpt-5.4) |
OPENCODE_DREAM_DREAM_MODEL |
Model to use for Stage 2 consolidation |
OPENCODE_DREAM_LOG_LEVEL |
Log verbosity: debug, info, warn, error (default: info) |
The system improves in two ways:
-
Knowledge compounding
- sessions become reflections
- reflections become consolidations
- consolidations become durable memory
- memory is reinjected into future sessions and exports
-
Reliability compounding
- adversarial hardening Phases 1–8 added direct regression coverage for path safety, marker handling, live-capture integrity, reflection/dream validation, and memory/export stability
- recoverable tool-boundary failures now return structured JSON instead of crashing in key paths
- Node.js >= 20
- ESM-only package
npm run typechecknpm run buildnpm test
Current maintained verification baseline: 182/182 tests passing.
docs/INSTALL.md— install and first-run flowdocs/ARCHITECTURE.md— subsystem/data-flow overviewdocs/OPENDREAM-MAPPING.md— OpenDream concept mappingINTEGRATIONS.md— external memory sources and merge modeldocs/adversarial-hardening-status.md— hardening history and current baseline
- Conceptual backbone: the broader OpenDream reflection/consolidation model
- This repository: an OpenCode-specific implementation, hardening pass, and releaseable plugin built on top of that conceptual foundation
MIT
{ "$schema": "https://opencode.ai/config.json", "model": "github-copilot/gpt-5.4", "provider": { "github-copilot": {} }, "plugin": [ ["opencode-dreams", { "preferredReflectModel": "github-copilot/gpt-5.4", "preferredDreamModel": "github-copilot/gpt-5.4" }] ] }