Watch / 值更
WATCH TECHNICAL GUIDE / SESSION HANDOFF

OpenCode, Claude & Codex Bidirectional Session Handoff Guide

OpenCode keeps sessions in ~/.local/share/opencode/opencode.db. WATCH_OPENCODE_DB points Watch at another file. Watch writes sessions, messages, and parts in one SQLite transaction and rolls back if it fails. Unsupported tool fields become text. Later replies depend on the model you configure.

When switching from commercial cloud agents to local open-source models in OpenCode (or handing off back to cloud agents), this guide explains how to use Watch for bidirectional handoff with SQLite transactional data isolation.

Published: 2026-09-21 Modified: 2026-10-14 Applies to: Watch v0.1.1
Key Operational Boundary

OpenCode utilizes a single relational SQLite database (defaulting to ~/.local/share/opencode/opencode.db) for session storage, providing ACID transactional integrity and structured queries. When you wish to transition sensitive tasks to locally hosted open-source models (via Ollama or vLLM in OpenCode) or hand off back to frontier cloud models (Claude/Codex), Watch provides a verified bidirectional bridge.

Unlike tools that rely strictly on append-only JSONL files, OpenCode organizes sessions across normalized relational tables including sessions, messages, and parts. Direct external tampering can corrupt foreign key constraints. Watch maps the UnifiedTurn abstraction cleanly into OpenCode's relational schema while preserving exact directory context (cwd) and timestamps.

  1. Step 1: Identify source session ID and working directory

    Locate your active session ID. Claude Code stores files in ~/.claude/projects/; Codex in ~/.codex/sessions/; OpenCode indexes sessions via globally unique IDs. Verify that the working directory is an absolute path to maintain project boundary alignment.

  2. Step 2: Preflight target database status (Check)

    Run Watch CLI with --check to probe the target OpenCode database. Watch validates write permissions and locks on ~/.local/share/opencode/opencode.db (or the custom path specified by WATCH_OPENCODE_DB) to prevent concurrent write contention.

  3. Step 3: Execute bidirectional handoff (Handoff)

    Select the source session in Watch Desktop and target OpenCode, or run the CLI open command. Watch extracts incremental turns, executes atomic SQLite transactions across sessions, messages, and parts, and issues the destination session ID.

  4. Step 4: Resume session natively in OpenCode (Resume)

    After conversion, execute opencode -s <session-id> in the workspace directory or trigger the launch button in Watch Desktop. OpenCode loads the recorded conversation in that working directory.

# 1. Preflight: Verify target OpenCode database writability npm run watch -- open <claude-session-id> --to opencode --check --json # 2. Handoff: Transfer session into OpenCode SQLite database npm run watch -- open <claude-session-id> --to opencode --json # 3. Reverse handoff: Transfer from OpenCode back to Claude or Codex npm run watch -- open <opencode-session-id> --to claude --json
OpenCode Relational Schema & SQLite Transaction Isolation

OpenCode session storage (~/.local/share/opencode/opencode.db) is structured across three core relational tables: • sessions: tracks session ID, title, absolute workspace directory, and timestamps • messages: maps session_id, role (user / assistant), and creation time • parts: stores text chunks, code blocks, and structured tool call representations Setting WATCH_OPENCODE_DB=/tmp/isolated.db routes writes to a separate SQLite database. Transfers execute inside an atomic SQLite transaction, rolling back completely on any interruption.

Safety Constraints & Disclaimers

1. Database isolation & backups: Watch operates on ~/.local/share/opencode/opencode.db by default and respects WATCH_OPENCODE_DB for testing environments. The write is one SQLite transaction and rolls back if it fails. 2. Tool call representations: Tool records map across schemas; unsupported proprietary parameters degrade into structured text representations. 3. Model continuation: Watch writes the saved session record and working directory. It does not guarantee that every tool event is preserved. Later replies depend on the model you configure.

Frequently Asked Questions

What is the advantage of OpenCode's SQLite storage over JSONL?

SQLite provides ACID transactions and robust indexing, eliminating the risk of line truncation or file corruption during unexpected termination. The WATCH_OPENCODE_DB override also facilitates isolated test environments.

Are custom model reasoning thoughts retained when handing off out of OpenCode?

Watch copies the saved user prompts, assistant text, thinking traces, and tool outputs it can map. Unsupported tool fields become text, so the copy is not a complete replica of the OpenCode row.

How does Watch prevent working directory mismatch?

Watch strictly binds the source session's absolute cwd to the OpenCode session entry. When resuming via opencode -s <session-id>, OpenCode locks to that workspace, preventing accidental edits in the wrong directory.

Official Sources & Acceptance Records