Sessions

Sessions are the durable execution log for your project.

Every agent action, decision, and discovery is logged in sessions. They persist across agent restarts, OpenCode compaction events, and system reboots.

What is a session?

A session represents a unit of agent work — typically a single coding or analysis session. Sessions have a title, open/closed status, and an append-only log of entries.

Each entry has a type, a summary, optional linked entities (tasks, ADRs, dispatches), and metadata (model, toolstack, machine ID).

Sessions are the execution history, not the source of truth for decisions. Durable knowledge belongs in ADRs, tasks, or the knowledge base. Sessions record what happened and provide context for resuming work.

Session lifecycle

  1. Open — agent starts work, creates a session via session_create or resumes an existing one found via session_list
  2. In progress — agent appends entries throughout the session via session_append
  3. Closed — agent closes the session via session_close with a structured summary and next_entry_point

Resuming sessions

When an agent starts, it calls session_list to find open sessions. If one exists, it loads the session detail (summary, next_entry_point, last entries) and appends a note entry marking the resumption. The next_entry_point from the previous close provides the starting context.

Entry types

Entry typeWhen to use
noteGeneral progress, discoveries, decisions, blockers
task_createdA task was created — link the task ID
task_updatedA task status changed — link the task ID
adr_draftedAn ADR was drafted — link the ADR ID
adr_acceptedAn ADR was accepted — link the ADR ID
decision_referencedAn existing ADR was referenced during work
letter_sentA Dispatch was created — link the dispatch ID
letter_repliedA Dispatch was replied to — link the dispatch ID
research_addedResearch was ingested into the knowledge base
conflict_detectedA conflict between entities was found
handoff_recordedWork was handed off to another agent
correctionA previous entry was corrected
security_scanA security scan was completed (auto-ingested as scan report)
performance_scanA performance scan was completed (auto-ingested as scan report)

Session metadata

Every session_append and session_create call should include metadata for traceability:

{
  "agent_id": "opencode",
  "metadata": "{\"model\": \"claude-opus-4.6\", \"toolstack\": \"opencode\", \"machine_id\": \"...\"}"
}

This ensures full traceability of which agent, model, and toolstack produced each session entry. Entries without metadata show as N/A in the dashboard.

Compaction survival

Sessions survive OpenCode context window compaction via the nexus-compaction-plus plugin. Before compaction, the plugin injects session and project IDs into the compaction prompt. After compaction, it records the event in the session timeline.

To maximize resilience against interruptions, agents should append entries during work, not only at close time. If a session is interrupted (crash, timeout, compaction), the resuming agent should have enough context from the session entries alone to continue without asking the user what happened.

MCP tools

ToolDescription
session_createCreate a new work session
session_listList open sessions for a project
session_appendAppend an entry to the active session
session_closeClose the session with summary and next entry point

Was this page helpful?