Continue or fork a session from the command line
headless & scripting
// what it does
opencode run -c continues the most recent session so a chain of run calls builds on each other; -s targets a specific session by ID (find it with opencode session list). Add --fork to branch a session's history into a new one, leaving the original thread untouched.
// shell
$ opencode run -c "now add tests for that change"$ opencode run -s my-session-id "continue that task"$ opencode run -s my-session-id --fork "try a different approach"// gotcha
Without -c or -s, every opencode run starts fresh with no memory of the last one — a common surprise when scripting multi-step tasks. Fork when you want an alternate approach without polluting the original session.