Skip to content

Chat message capture and injection (chatMessage)

These settings live under the chatMessage key in ~/.config/opencode/opencode-mem.jsonc:

Option Default What it does
enabled true Capture authored user prompts and inject memory context.
injectOn "first" For recall: "recent", inject on the first user message or on "always" every authored turn. With recall: "relevant" / "both", context always refreshes each authored turn (issue #460).
recall "relevant" How injected memories are chosen: "relevant" embeds the user message and runs vector search each turn; "recent" keeps the legacy newest-N listing; "both" prefers relevant then fills remaining slots with recent.
recallScope "default" Scope for auto-recall: "default" follows memory.defaultScope, or force "project" / "all-projects". When searching all projects, hits from the current project get a small similarity boost.
similarityThreshold (top-level) Optional per-inject floor; otherwise uses the top-level similarityThreshold.
maxMemories / excludeCurrentSession / maxAgeDays 3 / true / — How many memories the injected context holds, whether memories captured in the current session are excluded, and an optional age cutoff in days.
filterInjectedPrompts true Skip prompt text injected by the host or by other OpenCode plugins (system reminders, orchestration directives, background-task notifications) so it is never stored as if the user had typed it.
injectionMarkers built-ins Extra markers identifying injected blocks; added to the built-in list, never replacing it.
captureChildSessions false Capture prompts from orchestrator child sessions (sessions with a parentID, e.g. OpenCode task/subagent children). Their “user” messages are written by the parent agent, not by you, so by default they are not stored, auto-captured, used for profile learning, or given injected memory context.

Session and age exclusions are applied before the injected memory limit, so excluded memories do not consume slots that could hold eligible memories. Setting chatMessage.maxMemories to 0 disables project-memory injection while still allowing the user profile to be injected when enabled.

Injected memory tags identify selection="recent" or selection="semantic". Recent selections (including fallback and recent fill in both) have no numeric score. Semantic selections carry a finite retrieval_score when available; this is a ranking signal that can include the current-project boost, not a probability of relevance or factual correctness. Missing or invalid scores are omitted. This replaces the former relevance="...%" prompt attribute without changing memory selection, ordering, content, or provenance. Compaction retains its existing format.

When semantic recall fails (for example, embedding is unavailable), relevant and both fall back to the existing recent listing with the same scope, count, session, and age restrictions. A successful search with no eligible matches stays empty in relevant; both still fills from recent as usual. Partial-shard warnings do not trigger failure fallback. If recent fallback also fails, recall remains empty and nonfatal. Missing-query fallback and per-turn refresh behavior are unchanged.