Skip to content

Add session-management plugin: fork/move conversations across directories#29012

Open
mmostagirbhuiyan wants to merge 3 commits intoanthropics:mainfrom
mmostagirbhuiyan:feat/session-management-plugin
Open

Add session-management plugin: fork/move conversations across directories#29012
mmostagirbhuiyan wants to merge 3 commits intoanthropics:mainfrom
mmostagirbhuiyan:feat/session-management-plugin

Conversation

@mmostagirbhuiyan
Copy link
Copy Markdown

@mmostagirbhuiyan mmostagirbhuiyan commented Feb 26, 2026

Summary

Adds a session-management plugin with /fork, /move, and /sessions commands 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 previews

Motivation

This is one of the most consistently requested features in the repo, going back 9 months across 10+ issues and 37+ thumbs-up reactions:

Issue Title Status Reactions Since
#1516 Ability to move directories and not break --continue Closed (autoclose) 👍 5, 💬 10 Jun 2025
#5768 Resuming sessions only works from the directory they were started Open 👍 11, 💬 15 Aug 2025
#12629 Session Branching / Conversation Forking Open 👍 12, 💬 5 Nov 2025
#12941 Clone/duplicate conversation to try different approaches Open 👍 9, 💬 3 Dec 2025
#24745 Cannot rename project directory Open 💬 2 Feb 2026
#26766 Allow seamless session resumption by name across directories Open 👍 1, 💬 3 Feb 2026
#27473 Session resume should support moved/renamed project directories Closed 💬 1 Feb 2026
#27883 --resume fails to find session from different directory Open 💬 1 Feb 2026
#28745 Allow resuming conversations from different directories Open 💬 1 Feb 2026
#28766 Fork/move conversation to a different working directory Open Feb 2026

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:

  1. Locates the session JSONL file for the current conversation
  2. Copies/moves it (and companion data: subagent logs, tool results) to the target directory's storage
  3. Uses Python str.replace() to safely update cwd references in the JSONL
  4. Notifies the user about memory files (CLAUDE.md, memory/) that may need manual copying

Security hardening

  • No eval — tilde expansion uses case-based pattern matching, not eval echo
  • No sed injection — cwd replacement uses Python str.replace() via sys.argv (no shell interpolation of path characters like |, &, \)
  • Scoped tool accessBash(*) for fork/move, specific Bash(ls:*), Bash(du:*) etc. for read-only sessions command
  • Absolute path validation — rejects relative paths after expansion
  • Error handling — all cp/mv/mkdir operations guarded with || exit 1
  • Cross-platform — macOS stat -f with GNU stat -c fallback, sed -i.bak for portability

Tested on real data

Validated by forking a 9MB conversation (4,543 cwd references) from one project to another. Confirmed:

  • All cwd references updated correctly (including variant paths from devcontainer sessions)
  • JSONL integrity preserved (valid JSON on every line)
  • Companion directory (52 subagent logs + tool results) copied
  • claude --resume works from the target directory

Test plan

  • Install the plugin and verify /fork, /move, /sessions commands appear
  • Run /sessions to list existing conversations
  • Run /fork ~/test-dir to fork a conversation, verify claude --resume works from target
  • Run /move ~/test-dir to move a conversation, verify original removed and resume works
  • Test edge cases: non-existent target (prompts to create), empty args (prompts for path), paths with spaces

🤖 Generated with Claude Code

mmostagirbhuiyan and others added 2 commits February 26, 2026 09:14
… 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>
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