You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Project path is not updated after moving project directory (opens old deleted path) #34737
I previously opened a project in OpenCode located at:
C:\first_address
Later, I moved the entire project to:
D:\second\address
The original folder (C:\first_address) was removed/deleted.
After reopening OpenCode and selecting the project from the new location (D:\second\address), OpenCode still tries to open the old path (C:\first_address) instead of using the new one.
It looks like OpenCode may be keeping a cached workspace/project reference and not refreshing the project location.
I encountered the same issue and dug into the local database (~/.local/share/opencode/opencode.db). The problem is that when a project directory is moved, several database fields are not updated to reflect the new path:
What gets updated correctly
project_directory table — a new row is inserted mapping the new directory to the existing project ID ✅
What stays stale (the bug)
Table
Field
Problem
project
worktree
Still points to the old (now non-existent) path
session
directory
All existing sessions keep the old path
session
path
Some sessions also have this field set to the old path
Consequence
When opening opencode in the new directory:
The project is found via project_directory (which correctly has the new path)
But session history is filtered by session.directory, which still has the old path
So the IDE/TUI shows either no sessions or still references the old project path
Reproduction
Open a project at path A, create several sessions
Close opencode
Move the project folder to path B (path A no longer exists)
Open opencode at path B
project_directory gets a new row for path B, but project.worktree and all session.directory values still point to path A
Manual fix that worked for me
-- Update project worktreeUPDATE project SET worktree ='<new_path>'WHERE id ='<project_id>';
-- Update all sessionsUPDATE session SET directory ='<new_path>'WHERE directory ='<old_path>';
UPDATE session SETpath='<new_path>'WHEREpath='<old_path>';
After this, all session history is correctly visible in the new directory.
Suggested fixes
Either of these would resolve the issue:
Auto-update on open: When opencode opens a directory and finds it matches a project_directory entry but the project.worktree is stale (path doesn't exist on disk), automatically update project.worktree and all related session.directory / session.path fields to the new path.
Allow manual rebinding: Provide a command (e.g., opencode project rebind <new_path>) that lets users rebind a project to a new directory, updating all related tables at once.
Option 1 would be ideal since it's transparent to the user — they just open the new folder and everything works.
Also confirmed on OpenCode Desktop 1.18.18 on Linux while replacing an old checkout with another clone at a new path.
The new path was inserted into project_directory, but project.worktree remained the old path. Because both clones had the same Git remote, the new path was also stored in project.sandboxes under the same project ID. Selecting the new path therefore normalized back to the old canonical worktree. This overlaps with the shared-remote collision tracked in #42315.
In our case we wanted to completely purge the old OpenCode project and did not need its session history. The tested workaround was:
Quit Desktop and back up ~/.local/share/opencode/opencode.db plus the relevant files under ~/.config/ai.opencode.desktop/.
Run the deletion with PRAGMA foreign_keys=ON so deleting the stale shared project row also removed its old sessions and directory mappings.
Remove the old path from the nested server, globalSync.project, notification, layout/session, and window-tab state in the Desktop .dat files; remove the old path's hashed workspace .dat file.
Leave the new path as the first/last Desktop project and restart.
Desktop then recreated the project with the new path as project.worktree, an empty sandboxes list, and no old-path references. The database passed integrity_check and foreign_key_check afterward.
This is deliberately more destructive than the SQL rebinding workaround already posted above. If session history must be preserved, updating project.worktree, session.directory, session.path, and project_directory is preferable. The additional detail from our reproduction is that Desktop's persisted .dat state may also need cleanup; changing only the visible project list or only the database can leave the other layer stale.
Same situation on my end after an Explorer rename (Windows 11): sessions invisible under the new folder, and Delete on the leftover empty project fails because the backend still resolves the old worktree. What finally made it recoverable was updating three layers, not just the DB row:
session.directory / session.path
the directory strings embedded inside event.data payloads (they resurrect stale state otherwise)
Desktop's own registry (opencode.global.dat → server.projects.local[], plus base64(path)-keyed maps)
Until all three move together, the UI keeps showing a dead entry that can't be deleted. I've started work on relink + delete-cascade support (see my note on #23248) and will link the PR here — if you'd rather see this fixed purely server-side (auto-relink on startup) instead of adding Desktop UI for it, say so and I'll aim there.
PR is up: #45133 - it covers the relink/migration half of this (rename+move, all stored encodings) plus groundwork docs for the delete-cascade and Desktop registry cleanup. Feedback welcome.
Activity
github-actions commentedon Jul 1, 2026
This issue might be a duplicate of existing issues. Please check:
If your issue matches one of these, consider adding a comment there with any new details rather than opening a separate report.
gnu-lorien commentedon Jul 6, 2026
I have the same problem and can't figure out how to force it to update.
wangminle commentedon Aug 4, 2026
Root Cause Analysis
I encountered the same issue and dug into the local database (
~/.local/share/opencode/opencode.db). The problem is that when a project directory is moved, several database fields are not updated to reflect the new path:What gets updated correctly
project_directorytable — a new row is inserted mapping the new directory to the existing project ID ✅What stays stale (the bug)
projectworktreesessiondirectorysessionpathConsequence
When opening opencode in the new directory:
project_directory(which correctly has the new path)session.directory, which still has the old pathReproduction
project_directorygets a new row for path B, butproject.worktreeand allsession.directoryvalues still point to path AManual fix that worked for me
After this, all session history is correctly visible in the new directory.
Suggested fixes
Either of these would resolve the issue:
Auto-update on open: When opencode opens a directory and finds it matches a
project_directoryentry but theproject.worktreeis stale (path doesn't exist on disk), automatically updateproject.worktreeand all relatedsession.directory/session.pathfields to the new path.Allow manual rebinding: Provide a command (e.g.,
opencode project rebind <new_path>) that lets users rebind a project to a new directory, updating all related tables at once.Option 1 would be ideal since it's transparent to the user — they just open the new folder and everything works.
SamSpiri commentedon Aug 15, 2026
UPDATE project_directory SET directory = '<new_path>' WHERE directory = '<old_path>';also needed
benizzio-opencode commentedon Aug 18, 2026
Also confirmed on OpenCode Desktop 1.18.18 on Linux while replacing an old checkout with another clone at a new path.
The new path was inserted into
project_directory, butproject.worktreeremained the old path. Because both clones had the same Git remote, the new path was also stored inproject.sandboxesunder the same project ID. Selecting the new path therefore normalized back to the old canonical worktree. This overlaps with the shared-remote collision tracked in #42315.In our case we wanted to completely purge the old OpenCode project and did not need its session history. The tested workaround was:
~/.local/share/opencode/opencode.dbplus the relevant files under~/.config/ai.opencode.desktop/.PRAGMA foreign_keys=ONso deleting the stale sharedprojectrow also removed its old sessions and directory mappings.server,globalSync.project, notification, layout/session, and window-tab state in the Desktop.datfiles; remove the old path's hashed workspace.datfile.Desktop then recreated the project with the new path as
project.worktree, an emptysandboxeslist, and no old-path references. The database passedintegrity_checkandforeign_key_checkafterward.This is deliberately more destructive than the SQL rebinding workaround already posted above. If session history must be preserved, updating
project.worktree,session.directory,session.path, andproject_directoryis preferable. The additional detail from our reproduction is that Desktop's persisted.datstate may also need cleanup; changing only the visible project list or only the database can leave the other layer stale.neohiro commentedon Aug 26, 2026
Same situation on my end after an Explorer rename (Windows 11): sessions invisible under the new folder, and Delete on the leftover empty project fails because the backend still resolves the old worktree. What finally made it recoverable was updating three layers, not just the DB row:
session.directory/session.pathevent.datapayloads (they resurrect stale state otherwise)opencode.global.dat→server.projects.local[], plus base64(path)-keyed maps)Until all three move together, the UI keeps showing a dead entry that can't be deleted. I've started work on relink + delete-cascade support (see my note on #23248) and will link the PR here — if you'd rather see this fixed purely server-side (auto-relink on startup) instead of adding Desktop UI for it, say so and I'll aim there.
neohiro commentedon Aug 26, 2026
PR is up: #45133 - it covers the relink/migration half of this (rename+move, all stored encodings) plus groundwork docs for the delete-cascade and Desktop registry cleanup. Feedback welcome.
feat(project): rename-with-relocation and cascade delete for projects
Hona commentedon Sep 2, 2026
Fixed for opencode2 launch via #46713
You can try the desktop beta here: https://github.com/anomalyco/opencode-beta