anomalyco / anomalyco/opencode

New session created via /new gets projectID=global instead of the directory's project, making prior sessions invisible in /sessions

Open
#42,230 1 comment 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Aug 13, 2026.

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

Description

Description

Environment

  • opencode version: 1.18.17
  • OS: macOS (darwin), TUI
  • Working directory: a git repo with a linked worktree (.worktrees/magazine-portfolio)
  • git config --global safe.directory = *

Description

After pressing /new in a directory that already has an associated project, the new session is created with projectID=global instead of the project ID. Since the /sessions picker appears to filter by project, only "global" sessions are shown, and all prior sessions (which belong to the real project) disappear from the list. Data is not lost — the old sessions are intact in the DB — but the user cannot switch back to them from the UI.

Steps to reproduce

  1. Start opencode in /path/to/repo (git repo).
  2. Do some work in a session; the session gets assigned to the directory's project (projectID=).
  3. Press /new to start a new session in the same directory.
  4. Run /sessions — only the current session is listed.

Expected behavior

The new session inherits the directory's existing project ID; /sessions shows all sessions for that directory.

Actual behavior

The new session is created with projectID=global; /sessions only shows global-project sessions.
Log evidence (from ~/.local/share/opencode/log/opencode.log)
02:45:46 level=INFO message="booting location services" directory=/Users/lichao/git/opencode_test workspaceID=undefined
02:45:46 level=INFO message="project copy refresh done" projectID=3c7c11a5... updated=[] removed=[]
02:46:49 level=INFO message=created id=ses_006fc1c3... projectID=global directory=/Users/lichao/git/opencode_test workspaceID=undefined title="New session - ..."
Note that projectID=3c7c11a5... (the correct project) was known to the same instance ~1 minute earlier, and a session created at 02:44:37 got the correct ID.

Additional observations

  • The same instance also reports the directory as "not a git repo" (env detection says Is directory a git repo: no) even though git status works fine.
  • Timeline: the opencode instance started (01:45 UTC) before the git repo was initialized (~01:55 UTC). Sessions created before repo init got global and were later re-associated to the project — but the post-init /new session was not.
  • All sessions in another directory (my-daily-work, also a git repo) are under global as well, same symptom.

Workaround

Manually reassign in the DB (after quitting opencode):
sqlite3 ~/.local/share/opencode/opencode.db
"UPDATE session SET project_id='<project_id>' WHERE id='<session_id>';"
(project_id can be found via SELECT id, worktree FROM project;)

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.