Add session-management plugin: fork/move conversations across directories#29012
Open
mmostagirbhuiyan wants to merge 3 commits intoanthropics:mainfrom
Open
Add session-management plugin: fork/move conversations across directories#29012mmostagirbhuiyan wants to merge 3 commits intoanthropics:mainfrom
mmostagirbhuiyan wants to merge 3 commits intoanthropics:mainfrom
Conversation
… directories Addresses anthropics#28766. When users reorganize project files, their conversation history is stuck in the old directory. This plugin adds /fork, /move, and /sessions commands to copy or move conversations to a new working directory, preserving full history and context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…oping - Replace `eval echo` with safe case-based tilde expansion (fixes command injection) - Replace `sed` cwd replacement with Python string replacement (fixes sed injection via special characters in paths) - Scope allowed-tools: use Bash(*) for fork/move, specific Bash(cmd:*) for sessions - Add absolute-path validation after expansion - Add error handling with || exit 1 on all cp/mv/mkdir operations - Fix `for f in $(ls ...)` antipattern with `while IFS= read -r` loops - Add explicit subshell for stat fallback to clarify operator precedence - Add memory file (CLAUDE.md, memory/) detection and user notification - Add large file size warning (>10MB) - Fix author field to use actual contributor name Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
session-managementplugin with/fork,/move, and/sessionscommands that let users relocate conversations to a different working directory while preserving full history./fork <path>— copies the current conversation to a new directory (original stays intact)/move <path>— moves the conversation (removes from original location)/sessions [path]— lists all stored sessions for a directory with timestamps and previewsMotivation
This is one of the most consistently requested features in the repo, going back 9 months across 10+ issues and 37+ thumbs-up reactions:
Directly addresses #28766 and provides a plugin-based solution for #5768, #12629, #12941, #24745, #26766, #27473, #27883, #28745.
How it works
Claude Code stores conversations as JSONL files in
~/.claude/projects/, keyed by the working directory path (with/replaced by-). When users move their project files, the conversation stays tied to the old path.This plugin:
str.replace()to safely updatecwdreferences in the JSONLSecurity hardening
eval— tilde expansion usescase-based pattern matching, noteval echostr.replace()viasys.argv(no shell interpolation of path characters like|,&,\)Bash(*)for fork/move, specificBash(ls:*),Bash(du:*)etc. for read-only sessions commandcp/mv/mkdiroperations guarded with|| exit 1stat -fwith GNUstat -cfallback,sed -i.bakfor portabilityTested on real data
Validated by forking a 9MB conversation (4,543 cwd references) from one project to another. Confirmed:
claude --resumeworks from the target directoryTest plan
/fork,/move,/sessionscommands appear/sessionsto list existing conversations/fork ~/test-dirto fork a conversation, verifyclaude --resumeworks from target/move ~/test-dirto move a conversation, verify original removed and resume works🤖 Generated with Claude Code