A tiny wrapper for pi that keeps session history stable across directory renames/moves by using a persistent workspace ID.
Pi stores sessions by working-directory path by default. That is simple and fast, but if your project path changes (rename/move), Pi treats it as a different workspace with a different session bucket.
That means these workflows effectively BREAK with default Pi after a path change:
pi -c/--continuepi -r/--resumeand in-app/resume/tree(branch/message history and labels)/forkand/newcontinuity--session <partial-uuid>lookup/sessionmetadata/path reporting- follow-on session workflows like
/exportand/share
This wrapper introduces a stable workspace key in:
<workspace>/.pi/workspace-id
Then it always runs pi with:
pi --session-dir ~/.pi/agent/workspaces/<workspace-id>- Works in git and non-git directories
- Auto-creates a workspace ID if missing
- Uses git root when available
- For non-git folders, reuses nearest ancestor with
.pi/workspace-id - Falls back to current directory if no root marker exists
This repo ships a plugin file: pi-workspace-id.plugin.zsh.
ln -s ~/web-jm/pi-workspace-id ~/.oh-my-zsh/custom/plugins/pi-workspace-idThen add to your plugins list in ~/.zshrc:
plugins+=(pi-workspace-id)zinit light <your-github-user>/pi-workspace-idBy default, the plugin aliases:
pi='piw'
pi-raw='command pi'If you want only PATH wiring (no aliases), set this before loading the plugin:
export PIW_NO_ALIASES=1git clone <this-repo-url>
cd pi-workspace-id
./install.shRestart shell, or run:
source ~/.zshrc # or ~/.bashrcIf plugin aliases are enabled, use pi as usual (it maps to piw).
pi
pi -c
pi -r
pi "help me refactor this"You can always call piw directly too:
piw -c
piw -rThis wrapper improves both continue and history browsing workflows because the session bucket is stable per workspace ID.
pi -c # continue most recent session in this workspace
pi -r # open resume picker for this workspace
/resume # inside pi: pick another session file
/tree # inside pi: browse branch/message history of current session
Because piw always passes --session-dir based on .pi/workspace-id, these workflows stay intact even if you rename/move directories.
piw init [path] # initialize workspace-id in path (or current dir)
piw id # print effective workspace id
piw dir # print effective session dir
piw info # print root, id file, id, and session dir
piw --helpIf you are not using the plugin, add these to your shell profile:
alias pi='piw'
alias pi-raw='command pi'Use pi-raw if you ever want original, unwrapped pi behavior.
Set custom base directory for workspace session buckets:
export PI_WORKSPACES_DIR="$HOME/.pi/agent/workspaces"Default:
~/.pi/agent/workspaces
- This wrapper does not modify pi session format.
- Existing old path-based session files remain valid and can still be opened via
pi -r/pi --session. - For teams using non-git folders, committing
.pi/workspace-idcan keep workspace identity stable across machines.
MIT