anomalyco / anomalyco/opencode

Session picker hides all sessions after the folder's .git directory is removed (project re-keying); CLI `session list` still shows them

Open
#49,257 3 comments 0 reactions 1 assignee View on GitHub

@simonklee is already working on this.

Since Sep 16, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

OpenCode keys sessions to a per-project id derived from the enclosing git repo.
If that repo is removed (e.g. deleting an unused/accidental .git in a plain folder), the directory re-keys to the global project. The TUI session picker then hides every pre-existing session for that folder, with no UI path to discover them. The data is intact: opencode -s <sessionID> resumes them, and opencode session list in the same directory still lists them. Only the picker's filter excludes them.

Additional observations
  • The CLI and the TUI disagree: opencode session list in the same directory lists the hidden sessions; the picker does not. The picker applies a project/subpath filter the CLI does not.
  • Root cause (from reading the dev branch): the picker query defaults to a subpath filter (sessionListQuery() in packages/tui/src/context/sync.tsx, gated by the session_directory_filter_enabled kv), while sessions persist project_id plus a path subpath computed at creation time (packages/core/src/session.ts: path.relative(project.directory, directory)). After repo removal, old sessions keep project_id = <repo project> and path = "" (project root), new sessions get project = global and path = "home/user/..." - so the filter never matches the old rows again.
  • Recovery that worked for me (opencode closed, ~/.local/share/opencode/opencode.db):
    UPDATE session SET project_id='global', path='<dir without leading slash>'
      WHERE directory='<dir>';
    DELETE FROM project_directory WHERE directory='<dir>';  -- stale mapping to the old project
    
    This restored full picker visibility.
Suggested fixes (any one of)
  • Match sessions by directory as well as project (directory OR project match)
  • Surface a UI toggle for the directory/project filter scope (session_directory_filter_enabled kv exists but I found no UI for it)
  • Offer migration of old sessions when a directory's project re-keys
Plugins

opencode-scheduler

OpenCode version

1.18.31

Steps to reproduce
  1. mkdir /tmp/repro && cd /tmp/repro && git init # empty repo, zero commits is enough
  2. Start opencode, send a few messages so a session exists, then quit opencode
  3. rm -rf .git
  4. Start opencode again in the same folder and open the session picker.

Actual: the session from step 2 is not listed (picker browse and title search both miss it).
Expected: prior sessions for this directory remain visible, or there is some UI affordance to reach them.

Screenshot and/or share link

No response

Operating System

Arch Linux

Terminal

Terminator

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.