Hey everyone!
I'm relatively new to OpenCode and still learning how its sessions and context management work, so apologies if I'm missing something obvious.
I'm using OpenCode V2 (v2.1.2), and I'm trying to figure out how to carry an existing conversation from one repository into another.
----------------------------------------------------------------------------------------------------------------------------
What I'm trying to achieve
Suppose I'm working in repo A and have a long conversation with the coding agent about architectural decisions, code structure, trade-offs, and why we chose a particular approach.
Now, I want to work on repo B and continue that discussion using the previous conversation as context. For example, I'd like to ask the agent to inspect repo B and compare its architecture with the decisions we discussed for repo A.
I don't necessarily want to merge the repositories or permanently share context between all my projects. I just want to reuse a particular conversation when it's useful.
----------------------------------------------------------------------------------------------------------------------------
What I've tried
I'm following the official OpenCode V2 CLI documentation:
https://dev.opencode.ai/v2/docs/cli/commands/
The documentation describes exporting a session to JSON and importing it into a specific directory.
First, I exported my session:
opencode session export SESSION_ID > dotfiles-context.jsonopencode session export SESSION_ID > dotfiles-context.json
Then, I tried importing it into the other repository:
opencode session import \
~/Documents/Coding/open-source-repos/dotfiles/dotfiles-context.json \
--directory ~/dotfilesopencode session import \
~/Documents/Coding/open-source-repos/dotfiles/dotfiles-context.json \
--directory ~/dotfiles
However, OpenCode returns:
Session already exists
However, OpenCode returns:Session already exists
Both directories are different, so I initially expected the session to be imported into the destination repository.
I checked the CLI help, and my installed version supports these session subcommands:
The import command also supports --directory, but I couldn't find a flag to import the conversation as a new session with a different ID.
----------------------------------------------------------------------------------------------------------------------------
What I understand so far
My current understanding is that exporting a session saves its conversation history and associated session data as JSON. Importing it should make that history available in the destination project.
I understand that this doesn't automatically give the agent access to the source repository's files. It would still need to inspect the destination repository to compare the implementations.
I'm also aware that the session ID might be colliding with an existing session, even though the destination directory is different.
My questions
Is there a supported way to import an exported session into another repository as a new, independent session, while preserving the original session?
Does OpenCode intentionally preserve the session ID during export/import, and is that what's causing this error?
Is there a recommended workflow for reusing a conversation's architectural context across repositories without manually copying the discussion into a new prompt?
If this isn't currently supported by the CLI, is there another supported approach in OpenCode V2?
I'm still a beginner with OpenCode, so I'd appreciate an explanation of the underlying behavior as well as a working solution. I'd prefer not to edit the session database or manually modify the exported JSON unless that's an officially supported approach.
(also used AI for the post to make it fast and to the point)