Bug Description
opencode import <file> always sets the imported session's project_id to "global" regardless of which project directory the command is run from. The command reports success (Imported session: <id>) but the session is never associated with the current project.
Steps to Reproduce
- Export a session from a project (or have a
session.json file)
cd into a git-backed project directory (e.g. ~/my-project)
- Run
opencode import session.json
- Output says:
Imported session: ses_xxx
- Open
opencode in the project directory — the imported session does not appear
- Check the DB:
project_id is "global", directory is / (or home dir) instead of the project worktree
Expected Behavior
The session should be assigned to the project corresponding to the current working directory (Instance.project.id), and directory should reflect the project's worktree path.
Root Cause Analysis
In packages/opencode/src/cli/cmd/import.ts:
const row = { ...Session.toRow(exportData.info), project_id: Instance.project.id }
Instance.project.id evaluates to "global" at handler execution time, even when the command is run from a valid git-backed project directory. This happens on both fresh inserts and conflict updates (onConflictDoUpdate).
The bootstrap(process.cwd(), ...) call correctly resolves the directory (confirmed via debug logs: service=project directory=/path/to/project fromDirectory), but the project context does not appear to propagate into the handler's Instance.project getter.
Additionally, on conflict (re-import), only project_id is updated — directory is not included in onConflictDoUpdate.set, so it remains stale.
Workaround
Manually update the SQLite database:
-- Find the correct project_id
SELECT id, worktree FROM project;
-- Update the session
UPDATE session
SET project_id = '<correct_project_id>',
directory = '<project_worktree_path>'
WHERE id = '<session_id>';
Environment
- opencode version: 1.2.15
- OS: macOS (arm64)
- Installation: Homebrew
Bug Description
opencode import <file>always sets the imported session'sproject_idto"global"regardless of which project directory the command is run from. The command reports success (Imported session: <id>) but the session is never associated with the current project.Steps to Reproduce
session.jsonfile)cdinto a git-backed project directory (e.g.~/my-project)opencode import session.jsonImported session: ses_xxxopencodein the project directory — the imported session does not appearproject_idis"global",directoryis/(or home dir) instead of the project worktreeExpected Behavior
The session should be assigned to the project corresponding to the current working directory (
Instance.project.id), anddirectoryshould reflect the project's worktree path.Root Cause Analysis
In
packages/opencode/src/cli/cmd/import.ts:Instance.project.idevaluates to"global"at handler execution time, even when the command is run from a valid git-backed project directory. This happens on both fresh inserts and conflict updates (onConflictDoUpdate).The
bootstrap(process.cwd(), ...)call correctly resolves the directory (confirmed via debug logs:service=project directory=/path/to/project fromDirectory), but the project context does not appear to propagate into the handler'sInstance.projectgetter.Additionally, on conflict (re-import), only
project_idis updated —directoryis not included inonConflictDoUpdate.set, so it remains stale.Workaround
Manually update the SQLite database:
Environment