Repair stale directory paths in the local OpenCode session database after a repository move or rename.
opencode-repath is a small Bash command with a Python standard-library SQLite helper. It reads OpenCode's database path through opencode db path; it does not need direct database configuration or third-party Python packages.
git clone https://github.com/AlbertoOS/opencode-repath.git
cd opencode-repath
mkdir -p ~/.local/bin
ln -sfn "$(pwd)/bin/opencode-repath" ~/.local/bin/opencode-repathThe executable resolves its own symlink before locating its bundled helper, so this installation layout is supported. Ensure ~/.local/bin is on your PATH.
- Bash
- Python 3.9 or later, with SQLite support
- The
opencodeCLI onPATHand a local OpenCode database
# List active sessions whose saved directories no longer exist.
opencode-repath --broken
# Preview one active session selected by ID or exact title.
opencode-repath ses_abc123 ~/Developer/new-location
opencode-repath "Fix authentication flow" ~/Developer/new-location
# Apply the one-session change after reviewing the preview.
opencode-repath ses_abc123 ~/Developer/new-location --apply
# Preview all active sessions at or below an old directory prefix.
opencode-repath ~/Developer/old-project ~/Developer/new-project
# Apply the explicitly named bulk mode.
opencode-repath --prefix ~/Developer/old-project ~/Developer/new-project --apply- Every mutation is a dry run unless
--applyis supplied. - A non-path selector first matches an exact active session ID. If no ID matches, it matches an exact active title.
- Duplicate titles are rejected and their candidate IDs are printed; use the ID to continue.
- A path-prefix operation affects every active session at the exact old path or beneath it. Archived sessions are never changed.
- The helper uses parameterized SQLite statements, escapes
LIKEmetacharacters, and performs writes in an immediate transaction. If the preview count and update count differ, it rolls the transaction back. - New paths must be absolute (or start with
~). The command does not create directories or require the replacement directory to exist, which supports repathing data before the working tree is restored.
make test
make checkThe offline fixture creates a temporary SQLite database and a fake opencode command. It covers targeted ID/title selection, title ambiguity, dry-run behavior, path validation, ID/title collision precedence, bulk-prefix boundaries, and archived-session preservation.
MIT. See LICENSE.