Repository navigation
Description
Summary
Sessions created before their directory's project row exists are stored under the global
project (worktree /) and never appear in project-scoped session listings (opencode session list, TUI session list), even when the session's directory matches the current directory
exactly. An entire 120-session history was invisible; only sessions created after the project
row appeared were listed.
Environment
- opencode version: 2.1.1
- OS: Linux 6.18.40.1-microsoft-standard-WSL2+ (linux x64)
- Terminal: TERM=xterm-256color (TERM_PROGRAM/COLORTERM unset)
- Shell: /usr/bin/zsh
- Install/channel: latest
- Active plugins: none found (global/project config declare no
plugins; no.opencode/plugin(s)/)
Reproduction
- From
/home/redacted, create sessions whileprojecthas no row for that directory
(sessions are stored withproject_id='global'). - Later start opencode in
/home/redactedagain so aprojectrow for it is created
(observed: created when a new session started). - Run
opencode session list --format jsonfrom/home/redacted. - Only sessions created after the row existed are returned; all older sessions — including
ones whosedirectoryis exactly/home/redacted— are absent even with-n 500.
Expected Behavior
Directory-scoped session listings should include sessions whose directory matches the
current directory regardless of which project bucket stored them, or older sessions should be
re-scoped to the directory's project row when it is first created.
Actual Behavior
opencode session list from /home/redacted returned exactly 1 session while session_v2
contained 141: 120 in project_id='global' (53 with directory=/home/redacted, 67 with
directory=/home/redacted/redacted) and 21 in the /home/redacted project. Listing from
/home/redacted/redacted returned 0 despite 67 sessions with that exact directory, because
that directory has no project row of its own. GET /api/session returns all sessions
regardless of project, so the data exists but is unreachable from directory-scoped views.
Additional Context
- Frequency: user hit this previously and assumed the history was lost; reproducible whenever
sessions predate their directory'sprojectrow. - Evidence:
project_directorywas empty; re-pointing the 120 rows with
UPDATE session_v2 SET project_id = '<directory project>' WHERE project_id='global'
(after an online backup) madesession list -n 500return all 118 top-level sessions — the
rows were intact; only the bucket was wrong. - Workaround requires direct DB editing;
session export/importre-creates sessions instead
of fixing the association. - Related quirk: starting opencode in a subdirectory creates a new
projectrow there,
stranding those sessions from the opposite direction.
Activity
opencode-agent commentedon Oct 21, 2026
Thanks for the detailed report and the database analysis. I think this is a duplicate of #49827.
In v2, a directory that isn't in a git or hg repo always gets its own project when you open it. New sessions are not stored under
global. Sessions end up underglobalwhen they were imported from V1: V1 kept sessions from non-git directories in that shared project. v2 then creates a separate project for/home/redacted(and for/home/redacted/redacted), and the session list only shows sessions from the current project, so the older sessions are hidden. Your data is intact, as you found.Possible duplicates and closely related issues, ordered by likelihood:
globalafter upgrading and are hidden from the project-scoped list (main issue)opencode session listand the TUI; describes the runtime gap where opening a non-git directory does not take over itsglobalsessionsproject_id='global'for non-git directoriesOpen PRs that try to fix this: #51935, #54048 and #56322.
If you fix the rows by hand, note from #54815 and #50551 that
pathshould also be set to''(notNULL). Otherwise the TUI list can still hide the sessions even whenopencode session listshows them.The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different. For example, if these sessions were created by v2 itself and never imported from V1, please say so.
opencode-agent commentedon Oct 22, 2026
We haven't heard back, so I'm closing this as a duplicate of #49827. In v2, a directory that isn't in a git or hg repo gets its own project when you open it. Sessions under
globalin such a directory almost always came from V1. That's why your older sessions in/home/redactedand/home/redacted/redacteddon't show up in the project-scoped list, even though the data is intact.Please follow #49827 for updates. Open PRs #51935, #54048 and #56322 are attempts to fix it. If you repair the rows by hand in the meantime, set
pathto''as well asproject_id.If these sessions were created by v2 itself and never imported from V1, please reply here with that detail and we can reopen.