| description | argument-hint | allowed-tools |
|---|---|---|
Move this session's conversation history to a new working directory path |
<new-path> [--all] [--copy] |
Bash(pwd:*), Bash(realpath:*), Bash(echo:*), Bash(ls:*), Bash(find:*), Bash(mkdir:*), Bash(mv:*), Bash(cp:*) |
Relocate Claude Code session history to a new working directory.
Arguments: "$ARGUMENTS"
By default only the current session is relocated. Pass --all to relocate every session tied to this directory.
Follow these steps exactly, in order:
From "$ARGUMENTS", extract:
HAS_ALL_FLAG: true if--allappears anywhereHAS_COPY_FLAG: true if--copyappears anywhereTARGET_RAW: the remaining text after removing both flags
If TARGET_RAW is empty, print an error and stop:
Error: No target path provided. Usage: /relocate [--all] [--copy]
Run:
realpath "$TARGET_RAW"If realpath is not available, run:
cd "$TARGET_RAW" && pwdStore the result as NEW_PATH. If the command fails, print an error and stop:
Error: Target path "$TARGET_RAW" does not exist or is not accessible.
Run:
ls "$NEW_PATH"If this fails, stop:
Error: "$NEW_PATH" is not a directory.
The slug for a path is that path with every non-alphanumeric character replaced by -.
Run:
OLD_SLUG=$(pwd | sed 's/[^a-zA-Z0-9]/-/g')
NEW_SLUG=$(echo "$NEW_PATH" | sed 's/[^a-zA-Z0-9]/-/g')
echo "OLD_SLUG=$OLD_SLUG"
echo "NEW_SLUG=$NEW_SLUG"If OLD_SLUG equals NEW_SLUG, stop:
Error: The current directory and the target resolve to the same session storage path. No action taken.
If HAS_ALL_FLAG is false (default — current session only):
The current session is the most-recently-modified .jsonl file in the project storage directory (this session is actively being written to, so it always has the newest mtime).
Run:
CURRENT_SESSION=$(find ~/.claude/projects/"$OLD_SLUG" -maxdepth 1 -name "*.jsonl" -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | awk '{print $2}')
echo "CURRENT_SESSION=$CURRENT_SESSION"On macOS where -printf is not available, use:
CURRENT_SESSION=$(ls -t ~/.claude/projects/"$OLD_SLUG"/*.jsonl 2>/dev/null | head -1)
echo "CURRENT_SESSION=$CURRENT_SESSION"If no file is found, stop:
Error: No session history found for the current directory (~/.claude/projects/$OLD_SLUG/). Nothing to relocate.
Store FILE_LIST="$CURRENT_SESSION" and set FILE_COUNT=1.
If HAS_ALL_FLAG is true:
Run:
FILE_LIST=$(find ~/.claude/projects/"$OLD_SLUG" -maxdepth 1 -name "*.jsonl" 2>/dev/null)If empty, stop:
Error: No session history found for the current directory (~/.claude/projects/$OLD_SLUG/). Nothing to relocate.
Count: FILE_COUNT=$(echo "$FILE_LIST" | wc -l | tr -d ' ')
Run:
mkdir -p ~/.claude/projects/"$NEW_SLUG"Iterate over each file in FILE_LIST.
If HAS_COPY_FLAG is false (default — move):
for f in $FILE_LIST; do mv "$f" ~/.claude/projects/"$NEW_SLUG"/; doneNote: On the same filesystem, mv is atomic — the active session's open file descriptor continues writing to the same inode at its new location. If mv fails due to a cross-filesystem error, fall back to cp + rm for that file and warn the user.
If HAS_COPY_FLAG is true:
for f in $FILE_LIST; do cp -n "$f" ~/.claude/projects/"$NEW_SLUG"/; done-n avoids overwriting any sessions already at the destination.
Move, current session only:
Current session moved to ~/.claude/projects/$NEW_SLUG/
Open Claude Code from
$NEW_PATHto continue. This active session is now writing to its new location.
Move, all sessions:
All $FILE_COUNT session(s) moved to ~/.claude/projects/$NEW_SLUG/
Open Claude Code from
$NEW_PATHto continue. The active session is now writing to its new location.
Copy, current session only:
Current session copied to ~/.claude/projects/$NEW_SLUG/
Open Claude Code from
$NEW_PATHto continue. Session history is now available at both locations.
Copy, all sessions:
All $FILE_COUNT session(s) copied to ~/.claude/projects/$NEW_SLUG/
Open Claude Code from
$NEW_PATHto continue. Session history is now available at both locations. To remove the originals: rm ~/.claude/projects/$OLD_SLUG/*.jsonl