Skip to content

Conversation

@tobiastornros
Copy link

@tobiastornros tobiastornros commented Jan 11, 2026

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

Users can now branch from a session to start fresh with a summary of the
conversation. Useful when context window is filling up but you want to
continue the same task without losing important context.
Branch can be triggered via /branch in the prompt or through the command
palette (ctrl+p). Navigates to new session immediately while compaction
streams in the background.
Explains how to branch sessions when context window fills up during long tasks.
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

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

No duplicate PRs found

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: /branch command to create new session with compacted context

1 participant