[PR #7824] feat: add /branch command to create new session with compacted context #12523

Open
opened 2026-02-16 18:17:25 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7824

State: open
Merged: No


Been using OpenCode since early days and finally pulled off some improvements, at least for my workflow. Hope you like it and support it.

Fixes #7826

Summary

Add /branch command that creates a new session with compacted context from the current conversation.

Problem

When working on larger tasks, you often want to explore different ideas or directions without losing the context of what you've already discussed. Currently you'd have to start fresh and re-explain everything.

Solution

/branch creates a new session with a summary of the conversation. You can branch off to try different approaches while preserving the shared context of what was discussed.

Usage

  • Type /branch in the prompt
  • Use command palette (ctrl+p) → "Branch session"
  • API: POST /session/:sessionID/branch

Implementation

  • New BranchPart type triggers compaction with source session messages
  • Server endpoint creates session and starts prompt loop immediately
  • TUI navigates to new session where compaction streams in
  • New session gets title "Branch: [original title]"

Changes

  • core: Added Session.branch(), BranchPart type, branch handling in prompt loop
  • tui: Wired up /branch command and command palette action
  • docs: Added documentation for /branch
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7824 **State:** open **Merged:** No --- Been using OpenCode since early days and finally pulled off some improvements, at least for my workflow. Hope you like it and support it. Fixes #7826 ### Summary Add `/branch` command that creates a new session with compacted context from the current conversation. ### Problem When working on larger tasks, you often want to explore different ideas or directions without losing the context of what you've already discussed. Currently you'd have to start fresh and re-explain everything. ### Solution `/branch` creates a new session with a summary of the conversation. You can branch off to try different approaches while preserving the shared context of what was discussed. ### Usage - Type `/branch` in the prompt - Use command palette (`ctrl+p`) → "Branch session" - API: `POST /session/:sessionID/branch` ### Implementation - New `BranchPart` type triggers compaction with source session messages - Server endpoint creates session and starts prompt loop immediately - TUI navigates to new session where compaction streams in - New session gets title "Branch: [original title]" ### Changes - `core`: Added `Session.branch()`, `BranchPart` type, branch handling in prompt loop - `tui`: Wired up `/branch` command and command palette action - `docs`: Added documentation for `/branch`
yindo added the pull-request label 2026-02-16 18:17:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12523