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:
| Method | Command | Use when |
|---|---|---|
| Latest | opencode --continue / -c | Pick up the last session immediately |
| By ID | opencode --session <id> / -s | You have an ID from a share link, log, or list |
| List | opencode session list (-n, --format json) | You need to discover IDs |
| In TUI | /sessions | Switch 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:
- Automatic —
auto: trueby default; keeps aboutkeep.tokens(default 15000) of recent context beside a checkpoint summary. - Manual — TUI
/compact, orPOST /api/session/{sessionID}/compactagainst a running server. - Compaction is lossy. Raise
keep.tokenswhen recent detail matters. - Disable auto with
"compaction": { "auto": false }orOPENCODE_DISABLE_AUTOCOMPACT. Manual/compactstill works when auto is off.
{
"$schema": "https://opencode.ai/config.json",
"compaction": {
"auto": true,
"keep": { "tokens": 15000 },
"buffer": 20000
}
}
Practical tips:
/compactbefore a long refactor if you want a checkpoint early.- If a log or patch detail vanished, raise
keep.tokensor re-@the file. - 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
/undoand/redorevert 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.