From workspace
Finalize and clean up a workspace — safety checks, capture learnings, remove worktree, free slot. Use when the user is done with a feature, wants to clean up, or says "finish", "done", "close workspace", "remove workspace", "clean up".
How this skill is triggered — by the user, by Claude, or both
Slash command
/workspace:finishThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Respond in the user's language.**
Respond in the user's language.
You are finalizing and removing a workspace. Follow the steps below in order. Never skip ahead. Never batch multiple questions in a single message.
Read the registry:
cat ~/.claude-workspaces/registry.json 2>/dev/null || echo '{"workspaces":{},"next_slot":1}'
Match pwd against the workspace_path of each registry entry (check if pwd starts with or equals the workspace path).
For each repo in the workspace, run these three commands:
git -C <repo_path> status --short
git -C <repo_path> branch --show-current
git -C <repo_path> log main..HEAD --oneline 2>/dev/null || git -C <repo_path> log develop..HEAD --oneline 2>/dev/null || echo "COULD_NOT_COMPARE"
Also run for worktree mode repos:
git ls-remote --heads origin <branch> | wc -l
If git status --short output is not empty for any repo, show the user the list of uncommitted files and require explicit confirmation:
⚠️ You have uncommitted files in
<repo_name>:<list>. These will be LOST. Continue? [y/N]
Default is NO. Only proceed if the user explicitly answers y or yes.
If git log main..HEAD (or develop..HEAD) shows any commits for any repo, show them and require explicit confirmation:
⚠️ Branch
<branch>has N commit(s) not in main/develop in<repo_name>:<commit list>This branch is NOT merged. Deleting it means losing this work. Tip: consider creating a PR first (gh pr create).Are you absolutely sure you want to delete unmerged work? Type "delete unmerged" to confirm.
Default is NO. Only proceed if the user explicitly types delete unmerged. This is stricter than other confirmations because losing unmerged work is the most dangerous action.
If git ls-remote --heads origin <branch> returns 0, note:
ℹ️ Branch
<branch>has not been pushed to remote.
This check is informational only — it does not block the cleanup.
Before any cleanup, ask:
Before cleanup: did you learn anything surprising or non-obvious during this workspace that should be remembered for future sessions?
Examples: tricky API behavior, undocumented convention, pattern that worked well, important architectural decision.
Answer freely, or say "no" to skip.
Wait for the user's answer. Do NOT proceed until answered.
feedback, project, reference, or user.---
name: <short-identifier>
description: <one-line summary>
type: <feedback|project|reference|user>
---
<content>
MEMORY.md).MEMORY.md to add an entry in the index.Proceed to Step 4.
Show a complete summary of what will be destroyed:
Cleanup recap for workspace w<slot> (<slug>):
Mode : <worktree|sandbox>
Branch : <branch or N/A>
Path : <workspace_path>
Repos : <repo_name> (port <port>), ...
Actions:
1. Kill processes on ports <port_list>
2. Execute hooks (pre_destroy, db_destroy) if defined
3. git worktree remove for each repo (worktree mode)
4. Remove directory <workspace_path>
5. Free slot <slot> in registry
⚠️ This is **irreversible**. Proceed? [y/N]
Default is NO. Only proceed if the user explicitly answers y or yes. Anything else cancels — inform the user that the workspace was NOT removed.
CRITICAL: run cd $HOME first if the current directory is inside the workspace.
# Check if inside workspace before proceeding
[[ "$PWD" == <workspace_path>* ]] && cd $HOME
Execute each sub-step in order. If a step fails, log a warning and continue — do not abort the entire cleanup.
For each port in the workspace:
pids=$(lsof -ti :<port> 2>/dev/null || true)
if [ -n "$pids" ]; then
echo "$pids" | xargs kill -TERM 2>/dev/null || true
sleep 2
pids=$(lsof -ti :<port> 2>/dev/null || true)
[ -n "$pids" ] && echo "$pids" | xargs kill -KILL 2>/dev/null || true
fi
Log: ✓ Killed process on port <port> or - Nothing on port <port>.
If a pre_destroy hook is defined in the project config (.claude-workspaces.json), run it with variable substitution:
$SLOT → slot number$BRANCH → branch name$SLUG → workspace slug$WORKSPACE_PATH → workspace root path (with ~ expanded to $HOME)eval "<pre_destroy_command_with_substitutions>"
If a db_destroy hook is defined in the project config, run it with the same variable substitution as above.
For each repo in the workspace:
git -C <project_root>/<repo_origin> worktree remove <repo_path> --force
Where <repo_origin> is the relative origin path from .claude-workspaces.json.
Log: ✓ Removed worktree <repo_name> or ⚠ Failed to remove worktree <repo_name>: <error>.
rm -rf <workspace_path>
Log: ✓ Removed directory <workspace_path>.
Read the registry, remove the entry for this slot, and write it back:
cat ~/.claude-workspaces/registry.json
Remove the key matching this slot from workspaces. Recalculate next_slot as max(remaining_slots) + 1 (or 1 if no workspaces remain). Slot reuse is handled automatically by the "scan 1, 2, 3... for first free" allocation algorithm in the start skills.
Write the updated registry to ~/.claude-workspaces/registry.json.
Reset the terminal title and background color:
# Detect the parent terminal device (Claude Code captures stdout)
TTY_DEV="/dev/$(ps -o tty= -p $PPID 2>/dev/null | tr -d ' ')"
# Reset background, tab name, and window title
printf '\033]11;\007' > "$TTY_DEV" 2>/dev/null
printf '\033]1;\007' > "$TTY_DEV" 2>/dev/null
printf '\033]0;\007' > "$TTY_DEV" 2>/dev/null
Show a concise success message:
✅ Workspace w<slot> (<slug>) removed. Slot freed.
<if memory saved> 💾 Memory "<name>" saved.
You can: /workspace:list, /workspace:start-worktree, /workspace:start-sandbox
y/yes.y/yes.~ to $HOME in all paths before running shell commands.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub sommesi/claude-workspaces --plugin workspace