Skip to content

Continue Pi sessions in Worktrunk worktrees - #3

Merged
mavam merged 4 commits into
mainfrom
continue-session
Aug 9, 2026
Merged

Continue Pi sessions in Worktrunk worktrees#3
mavam merged 4 commits into
mainfrom
continue-session

Conversation

@mavam

@mavam mavam commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Problem

Worktree creation and path resolution leave the active Pi session in its original working directory. Continuing in the target currently requires a separate manual session operation.

Solution

  • Add /worktree continue [target] for existing worktrees.
  • Add /worktree create <branch> --continue for a one-step create-and-continue flow.
  • Confirm the source and target before creating a target-cwd session copy.
  • Use Pi's public SessionManager.forkFrom() and ctx.switchSession() APIs.
  • Preserve the source session and historical message text, then add a visible working-directory transition to the continued session.
  • Keep session switching command-only because agent tools don't receive session replacement APIs.

Prior art

The continuation flow is inspired by pi-session-move, while keeping the implementation narrowly Worktrunk-specific and avoiding session-history rewrites or a package dependency.

This is a follow-up to #1 and #2.

mavam added 2 commits August 5, 2026 09:18
Add explicit command flows for continuing the current Pi session in an
existing or newly created worktree. Fork the persisted session through
Pi's public API, preserve its history, and record the working-directory
transition before switching runtimes.

Assisted-by: GPT-5.6-sol (pi 0.83.0)
Assisted-by: GPT-5.6-sol (pi 0.83.0)
@mavam

mavam commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

@edahlseng Thanks again for pointing me to pi-session-move. This PR incorporates the core workflow directly into /worktree: you can now use /worktree continue [target] or /worktree create <branch> --continue to create a linked session copy and switch the live Pi process into the target worktree.

I would appreciate your take on how this fits the workflow you described.

@mavam
mavam force-pushed the continue-session branch 3 times, most recently from cae616f to 2459ac6 Compare August 9, 2026 18:02
Pi does not write new sessions before the first assistant response, so
SessionManager.forkFrom had no source file. Snapshot in-memory history
for that case and preserve both source and target after switching.

Also shorten the visible transition message and give it a user-facing
title.

Assisted-by: gpt-5.6-sol (pi 0.84.1)
@mavam
mavam force-pushed the continue-session branch from 2459ac6 to a7d4223 Compare August 9, 2026 18:03
Carry custom session directories into continued worktrees and persist fresh sources before the fallible runtime switch. Avoid cloning persisted histories and cover both storage paths plus switch failure.

Assisted-by: gpt-5.6-sol (pi)
@mavam
mavam merged commit d8d6b6c into main Aug 9, 2026
@mavam
mavam deleted the continue-session branch August 9, 2026 18:17
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.

1 participant