Standalone Bash CLI (opencode-relocate) that edits OpenCode's local SQLite
database to move/relink projects and sessions. No LLM, no Bun, no build step.
The entire tool is the single file opencode-relocate (~2300 lines).
- All logic lives in
./opencode-relocate. Edit that file directly; there is no build, compile, package manager, or test suite. - Run it directly:
./opencode-relocate <command> [args]. Commands:relocate,move-sessions,split-project,relink(4 total — the script's own header comment at the top is stale and only lists 3). - Uses
set -euo pipefail. Conventions live at the top of the file: path constants (OPENCODE_DB,OPENCODE_PROJECTS_DIR,OPENCODE_SESSIONS_DIR), color codes, and logging helpersinfo/warn/ok/err. Usesql_query(soft) andsql_query_strict(fails on error) rather than callingsqlite3directly. - Requirements:
sqlite3,git(forsplit-project/relink), optionaljq(falls back tosedfor JSON edits).
- Every command operates on the live DB at
~/.local/share/opencode/opencode.dband~/.local/share/opencode/storage/. Running a command for real edits the developer's own OpenCode state — do not run destructive commands casually. - Each command auto-backs up the DB (+WAL/SHM) to a timestamped
.bakbefore writing. Use--dry-run(where supported, e.g.relink) to preview.
- OpenCode identifies a project by the hash of its first root commit
(
git rev-list --max-parents=0 HEAD). Recreating that commit changes the ID and orphans sessions — this is whatrelinkfixes. - Non-git directories live under the
globalproject; sessions are filtered by directory prefix.globalcan only be a source, never a target.
.opencode/is OpenCode's own agent config (plugin dependency), not part of the CLI's code.README.mdis the authoritative usage doc.