Skip to content

feat(session): add methods to migrate session#24726

Closed
Alchuang22-dev wants to merge 2 commits into
anomalyco:devfrom
Alchuang22-dev:feature-session
Closed

feat(session): add methods to migrate session#24726
Alchuang22-dev wants to merge 2 commits into
anomalyco:devfrom
Alchuang22-dev:feature-session

Conversation

@Alchuang22-dev

Copy link
Copy Markdown

Issue for this PR

Related to #24708 and references #23250 for the session migration / orphan recovery design.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds first-class session history and migration support so sessions can be discovered and rebound across projects instead of being effectively locked to the original project directory.

For more details, please check the diffs in the following layers:

  1. Global session history

    • Adds Session.listGlobal()
    • Adds GET /session/history
    • Adds SDK support for session.history(...)
    • Adds opencode session list --all
    • Supports project metadata, pagination cursor, search, root filtering, archived filtering, and workspace filtering
  2. Session migration / rebind

    • Adds Session.listOrphans()
    • Adds Session.migrate()
    • Adds GET /session/orphans
    • Adds POST /session/:sessionID/migrate
    • Adds SDK support for session.orphans(...) and session.migrate(...)
    • Adds CLI commands:
      • opencode session orphans
      • opencode session migrate <sessionID> [directory]
      • opencode session rebind <sessionID> [directory]

The migration behavior is based on the approach from #23250, with the backend/API/CLI pieces implemented here first. Orphan detection handles:

  • sessions whose stored directory no longer exists
  • global sessions whose directory is inside a known project worktree

Migration updates the selected session and its child session tree to the target projectID and directory.

Notes

This PR intentionally does not include the TUI migration dialog from #23250 yet.

How did you verify your code works?

Ran targeted tests from packages/opencode:

bun test test/server/global-session-list.test.ts
bun test test/server/httpapi-session.test.ts test/server/httpapi-json-parity.test.ts
bun typecheck

Regenerated the JavaScript SDK:

./packages/sdk/js/script/build.ts

The SDK generation completed successfully and generated the new session.history, session.orphans, and session.migrate methods. To test the new opts in cli, use commands such as:

bun run dev session list --all #show all the sessions in your config

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

PTAL.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, the only related PR I found is:

PR #23250: feat(tui): add session migration dialog
#23250

This is related but not a duplicate. PR #24726 actually references #23250 in its description and explicitly notes that "This PR intentionally does not include the TUI migration dialog from #23250 yet." So #23250 addresses the TUI layer while #24726 handles the backend/API/CLI implementation of session migration.

No duplicate PRs found

@rektide

rektide commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for working on my issue. I like how ambitious you've been about trying to integrate the challenges & ideas into the opencode code broadly.

I took a much narrower pass in #24728, working to extend the existing session.ts commands without adding broader capabilities. One thing I do want to note, I'd like to see a broader ability to target sessions for move/migration if we go with a PR like this. In one directory I have over 30 sessions I want to migrate. In my PR I can do --from-dir and get them all. I also use jj workspaces, so I have workspaces like ~/src/opencode-session-move and ~/src/opencode-provider-metrics (some of my own tweaks) etc; I'll sometimes have >10 different "variants" of a directory. Since my PR has wildcard support, I can do --from-dir ~/src/opencode* and move all the sessions in one go, which super super helps. I also have --from-project and --from-id that can also be helpful for moving by project id (again useful for targetting mass moves!) or by session id.

If we go with a PR like this, I'd like to see better ability to target mass moves in user-friendly ways, where-as currently I think this PR requires looking up session ids manually, then moving them one at a time.

Thanks for hoping on this work. Definitely gave me a lot to think about! I'm happy to help out further on either PR if the opencode team has any suggestions for where to go.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants