CONTEXT.md
OpenCode sessions preserve durable conversational history while assembling the runtime context an agent needs to act correctly in its current environment.
System Context: The structured collection of contextual facts presented to the model as initial instructions and chronological updates. Avoid: System prompt
Session History: The projected chronological conversation selected for a provider turn after applying the active compaction and Context Epoch cutoffs. Avoid: Session Context
Context Source: One independently observed typed value within the System Context, represented by a stable key, JSON codec, infallible loader, pure baseline/update renderers, and an optional removal renderer for dynamic sources. Avoid: Prompt fragment
System Context Registry: The Location-scoped registry of ordered, scoped producers that contribute to the current System Context.
Mid-Conversation System Message: A durable chronological instruction that tells the model the newly effective state of a changed Context Source. Avoid: System update, system notification, raw text diff
Context Epoch: The span during which one initially rendered System Context remains the immutable provider-cache baseline, ending at completed compaction, Session movement, or an incompatible context transition that requires a fresh baseline.
Baseline System Context: The full System Context rendered at the start of a Context Epoch. Avoid: Live system prompt
Context Snapshot: The overwriteable model-hidden JSON state used to compare each Context Source with the value last admitted to a provider turn.
Unavailable Context: An expected temporary inability to observe a Context Source value; the runtime retains its prior effective state and emits no update, or omits it until first successfully loaded.
Safe Provider-Turn Boundary: The point immediately before a provider call, after durable input promotion and any required tool settlement, where context changes may be admitted chronologically.
Admitted Prompt: A durable user input accepted into the Session inbox but not yet included in Session History.
Prompt Promotion: The durable transition that removes an Admitted Prompt from pending input and appends its user message to Session History.
Provider Turn: One request to a model provider and the response projected from that request.
Session Drain: One process-local execution span that promotes eligible input and runs required Provider Turns until no immediate continuation remains. A Session Drain has no durable identity or transcript boundary.
Model Tool Output: The bounded projection of a Core-executed tool result persisted in Session history and replayed to the model. A tool may shape this projection semantically, but the Tool Registry enforces the final size limit.
Managed Tool Output File: A temporary file created under OpenCode's shared tool-output directory to retain complete output that was too large for Session history.
PTY Environment: The host-supplied environment overlay applied by the server when creating a PTY, observed for the request Location and resolved PTY working directory.
SystemContext.combine(...) preserves caller order; the System Context Registry evaluates producers concurrently and combines them in stable contribution-key order so rendered context remains deterministic.SystemContext.make(...) hides that value type so differently typed sources compose uniformly. Its codec compares and stores that value; its pure renderers produce model-visible baseline, update, and removal text only when needed.SystemContext.initialize(...) observes a composed System Context once and produces a fresh Baseline System Context with its Context Snapshot.SystemContext.reconcile(...) observes a composed System Context once and returns exactly one next action: unchanged, updated, replacement ready, or replacement blocked.SystemContext.replace(...) renders a fresh generation after completed compaction or another baseline-replacing transition; it reports replacement blocked while previously admitted context is unavailable.AGENTS.md files as one ordered aggregate Context Source at each Safe Provider-Turn Boundary.skill tool.TERM and OPENCODE_TERMINAL.OPENCODE_DISABLE_PROJECT_CONFIG; global instructions remain eligible.Dev: "The date changed while the session was active. Should the Mid-Conversation System Message say what the old date was?" Domain expert: "No. Emit the newly effective date so the agent can act on the current System Context."
experimental.chat.system.transform can mutate the assembled baseline system prompt arbitrarily, but V2 plugins do not yet expose an equivalent hook. Decide separately whether to port it, replace dynamic uses with plugin-defined Context Sources, or narrow its semantics.