Skip to content

[BUG] opencode import always assigns session to global project, ignoring current working directory #15797

@or1is1

Description

@or1is1

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

  1. Export a session from a project (or have a session.json file)
  2. cd into a git-backed project directory (e.g. ~/my-project)
  3. Run opencode import session.json
  4. Output says: Imported session: ses_xxx
  5. Open opencode in the project directory — the imported session does not appear
  6. 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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions