fix(opencode): inject recalled context via system.transform hook#207
Merged
Conversation
Closes #169. The `session.created` handler only logged a debug line — it never actually delivered recalled memories into the session. OpenCode's `session.created` is observational; the API for context injection is `experimental.chat.system.transform`, which fires before each model call and lets a plugin push extra system-prompt strings. Add a Layer 3 handler that: - Runs once per session (de-dup by sessionID so the wake-up doesn't re-inject on every chat turn). - Captures `icm wake-up --project <p>` (critical/high facts + preferences) and pushes it to `output.system`. - Captures `icm recall-project --limit 5` (top project memories) and pushes it too. Both calls are best-effort — a missing binary or empty memory store returns "" and silently no-ops. Type-checked with `tsc --strict` against @opencode-ai/plugin@1.14.46. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #169.
The previous `session.created` handler only logged a debug line — it never actually delivered recalled memories into the session. OpenCode's `session.created` is observational; the API for context injection is `experimental.chat.system.transform`, which fires before each model call and lets a plugin push extra system-prompt strings.
Fix
New Layer 3 handler in the plugin that:
` (critical/high facts + preferences) → pushes to `output.system`.
Both calls are best-effort — a missing binary or empty memory store returns "" and silently no-ops.
Why `experimental.chat.system.transform`
Verified against `@opencode-ai/plugin@1.14.46`:
```ts
"experimental.chat.system.transform"?: (input: { sessionID?, model }, output: { system: string[] }) => Promise
```
This is the only hook that lets a plugin add to the system prompt. `chat.params` only modifies model parameters (temperature etc.), `chat.message` mutates the user message itself.
Test plan
🤖 Generated with Claude Code