Resume an OpenCode Session After You Stop

Resuming an OpenCode session means continuing the latest chat (--continue / -c), attaching a known ID (--session / -s), or picking one in the TUI with /sessions. When context is tight, request /compact; to split the same history into a new line of work, add --fork.

This howto sticks to flags and slash commands documented in the official CLI, TUI, and Compaction pages. Product menu click-paths vary by version, so they are omitted. No pricing.

Where is the session ID?

One-line answer: List with opencode session list; in the TUI use /sessions (aliases /resume, /continue; keybind ctrl+x l). Resume flags are --continue and --session <id>.

Documented entry points:

MethodCommandUse when
Latestopencode --continue / -cPick up the last session immediately
By IDopencode --session <id> / -sYou have an ID from a share link, log, or list
Listopencode session list (-n, --format json)You need to discover IDs
In TUI/sessionsSwitch sessions without leaving the TUI

The same --continue / --session / --fork flags appear on opencode run and opencode attach.

opencode --continue
opencode -s ses_example
opencode session list -n 10
opencode run --session ses_example "Continue fixing the tests"

Export with opencode export [sessionID], import with opencode import <file-or-share-url>, delete with opencode session delete <id>.

Start fresh work with /new (alias /clear). Older sessions remain selectable via /sessions.

What if context is truncated?

One-line answer: Autocompaction is on by default; request /compact (alias /summarize, keybind ctrl+x c) early. Tune thresholds in the compaction block of your OpenCode config.

From the Compaction docs:

  • Automaticauto: true by default; keeps about keep.tokens (default 15000) of recent context beside a checkpoint summary.
  • Manual — TUI /compact, or POST /api/session/{sessionID}/compact against a running server.
  • Compaction is lossy. Raise keep.tokens when recent detail matters.
  • Disable auto with "compaction": { "auto": false } or OPENCODE_DISABLE_AUTOCOMPACT. Manual /compact still works when auto is off.
{
  "$schema": "https://opencode.ai/config.json",
  "compaction": {
    "auto": true,
    "keep": { "tokens": 15000 },
    "buffer": 20000
  }
}

Practical tips:

  1. /compact before a long refactor if you want a checkpoint early.
  2. If a log or patch detail vanished, raise keep.tokens or re-@ the file.
  3. If fixed instructions and tool schemas dominate the window, compaction cannot free much—reduce tools or start /new.

Inspect usage with opencode stats.

Sessions per branch?

One-line answer: Conversation branches use --fork. Sessions are not auto-split by git branch name; lists are scoped to the working directory / project.

opencode --continue --fork
opencode --session ses_example --fork

--fork must be paired with --continue or --session. It creates a child session from the projected history—useful to keep an experimental line separate from the main thread.

Relative to git feature branches (no invented UI):

  • Sessions bind to a working directory/project. You can start with opencode /path/to/project.
  • To isolate chats per branch, separate directories (extra clone, git worktree) keep session lists apart. Switching git branches inside one directory does not rename or auto-fork the OpenCode session.
  • In-TUI /undo and /redo revert file changes via Git, so the project needs to be a git repo (per TUI docs).

Treat “per-branch sessions” as (1) conversation forks (--fork) and (2) directory/worktree separation—that matches the published CLI/TUI surface.

Wrap-up

Resume OpenCode with session list / /sessions, attach via -c / -s, manage context with /compact and compaction settings, and split work with --fork or separate directories. Verify flags against the official CLI and TUI docs.

Sources