Skip to content

feat(tui): add Claude Code-style --fork flag to duplicate sessions before continuing (resolves #11137)#11340

Open
ariane-emory wants to merge 18 commits intoanomalyco:devfrom
ariane-emory:feat/fork-session-take-2
Open

feat(tui): add Claude Code-style --fork flag to duplicate sessions before continuing (resolves #11137)#11340
ariane-emory wants to merge 18 commits intoanomalyco:devfrom
ariane-emory:feat/fork-session-take-2

Conversation

@ariane-emory
Copy link
Contributor

@ariane-emory ariane-emory commented Jan 30, 2026

What does this PR do?

  • Add Claude CodeStyle --fork-session CLI flag for session forking with --continue or --session
  • Simlilar behaviour as Claude Code's --fork-session switch offer familiarity to converts from Claude Code.
  • Forked sessions get the same automatic (fork #N) title suffixes via existing Session.fork() that forking via the /fork command or TUI message modal receive
  • Validates that --fork is correctly paired with either --continue or --session
  • Works with both the interacture TUI and opencode run commands
  • Graceful handling for edge cases (such as no session being available to fork) is included
  • Applies to both attach mode and bootstrap mode

Resolves #11137.

Supported syntax examples:

opencode --continue --fork
Start the TUI, continuing and forking (duplicating) the last session

opencode run --continue --fork "tell me a better joke"
Run one prompt, continuing and forking (duplicating) the last session

opencode run --fork "tell me a better joke"
Same as previous, but using terse syntax for the --continue switch

opencode --fork --session ses_3f2424a04ffeu0ZUiE12HfD2OI
Fork a particular session.

opencode --fork --session ses_that_doesnt_exist
Fails gracefully: OpenCode starts, but displays a Failed to fork session toast.

opencode run --fork --session ses_that_doesnt_exist "I'm not gonna work."
Fails gracefully: an Error: Session not found message is written to STDERR and an exit code of 1 is used.

How did you verify your code works?

Manual testing, bun test, bun typecheck

- Add --fork CLI flag for session forking with --continue or --session
- Forked sessions get automatic (fork #N) title suffix via existing Session.fork()
- Validate that --fork requires --continue or --session
- Applies to both attach mode and bootstrap mode

Fixes anomalyco#11137
- Add fork option to Args interface
- Add --fork-session flag to TUI command (thread.ts)
- Add validation that --fork-session requires --continue or --session
- Fork session before navigating when --fork-session is set
Replace verbose if/else if blocks with ternary expressions
to match repo style guide preference for const over let.

-8 lines total
When using --session with --fork, the app would briefly show the forked
session then navigate to a blank screen. Root cause: race condition where
reconcile overwrites the newly forked session from the store.

Fix: Wait for sync.status to be "complete" before forking, ensuring
session list is fully loaded before the fork operation.
@github-actions
Copy link
Contributor

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

No duplicate PRs found

@ariane-emory
Copy link
Contributor Author

ariane-emory commented Jan 30, 2026

A few comments exchanged between @IdrisGit and myself on the topic of this PR can be found alongside my initial dummy PR, located here: ariane-emory#147

@ariane-emory ariane-emory marked this pull request as ready for review January 30, 2026 17:05
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Jan 30, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 1, 2026
… to duplicate sessions before continuing (resolves #11137)
opencode-agent bot added a commit that referenced this pull request Feb 2, 2026
… to duplicate sessions before continuing (resolves #11137)
@ariane-emory ariane-emory force-pushed the feat/fork-session-take-2 branch from 71151ae to 4410d8b Compare February 2, 2026 23:21
Remove the alias and make --fork the primary CLI option name.
Update args.forkSession references to args.fork.
@ariane-emory ariane-emory changed the title feat(tui): add Claude Code-style --fork-session flag to duplicate sessions before continuing (resolves anomalyco#11137) feat(tui): add Claude Code-style --fork flag to duplicate sessions before continuing (resolves anomalyco#11137) Feb 3, 2026
@ariane-emory ariane-emory changed the title feat(tui): add Claude Code-style --fork flag to duplicate sessions before continuing (resolves anomalyco#11137) feat(tui): add Claude Code-style --fork flag to duplicate sessions before continuing (resolves #11137) Feb 3, 2026
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.

[FEATURE]: Add cli flag to fork session

1 participant