Watch / 值更
WATCH TECHNICAL GUIDE / SESSION HANDOFF

OpenCode, Claude & Codex Bidirectional Session Handoff Guide

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-09-21 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 resumes from the recorded conversation state seamlessly.

# 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
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. Atomic transactions protect against corrupted partial writes. 2. Tool call representations: Tool records map across schemas; unsupported proprietary parameters degrade into structured text representations. 3. Model continuation: Watch ensures lossless history and workspace database ingestion; response generation quality upon resumption depends on your configured model provider.

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?

Yes. Watch extracts the full timeline including user prompts, assistant thoughts, thinking traces, and tool outputs from OpenCode, transcoding them into format-compatible turns for Claude or Codex.

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

Return to Watch Home Download Watch Desktop