AGENT SKILL

cleanup-legacy-install

Use when upgrading from a pre-plugin clauDNA install (install.sh, claudefather, or claudfather) to the marketplace plugin. Detects and removes the legacy ~/.claude/ overlay so plugin-installed skills don't get shadowed by stale copies.

License 许可
Apache-2.0
最近更新
2026-11-15
Stars
★ 0
Forks
1

01 前言 Front Matter

name
cleanup-legacy-install
hosts
[ "claude-code" ]
description
Use when upgrading from a pre-plugin clauDNA install (install.sh, claudefather, or claudfather) to the marketplace plugin. Detects and removes the legacy ~/.claude/ overlay so plugin-installed skills don't get shadowed by stale copies.
allowed-tools
Read(*), Bash(ls *), Bash(cat *), Bash(diff *), Bash(cp *), Bash(rm -rf ~/.claude/*), Bash(rm ~/.claude/*), Bash(rmdir *), Bash(mkdir *), Bash(date *), Bash(find *), Bash(test *)
user-invocable
true
disable-model-invocation
true

03 SKILL.md 正文

Cleanup Legacy Install

Removes the pre-plugin clauDNA overlay from ~/.claude/ so plugin-installed skills don't get shadowed by stale copies. Works for users who previously installed via clauDNA's install.sh, or via the sibling claudefather / claudfather projects.

Backups belong under the effective clauDNA state root R/backups/legacy-install/<run>/. In this native Claude Code skill, <run> must use this invocation's actual native Claude session ID. Never invent or infer a session ID. If the skill does not receive a usable native ID, stop; standalone maintainer backup operations are separate operator-run operations outside any Claude, Codex, or Cursor workflow and are not a fallback for this skill. The local skill mechanism documents ${CLAUDE_SESSION_ID} substitution, but native acceptance of its rendered value remains pending. This skill remains discovery-first and requires the explicit confirmations below before source deletion.

The skill is discovery-based: it enumerates the names this plugin would now install (skills, agents, hook scripts) and only removes matching-name files in ~/.claude/. Anything you added yourself with a different name is untouched.

Procedure

Follow these steps exactly in order.

Step 1: Detect Legacy Install

Look for breadcrumb files written by the old install scripts:

ls -la ~/.claude/.clauDNA-repo ~/.claude/.claudfather-repo ~/.claude/.claudefather-repo 2>/dev/null

Also check the actual overlay directories — a breadcrumb may be absent if the user removed it manually, but the overlay still exists:

ls -d ~/.claude/skills ~/.claude/hooks ~/.claude/commands 2>/dev/null

If none of these exist and no breadcrumbs are present, print:

No legacy clauDNA / claudfather / claudefather install detected. Nothing to clean up.

And stop.

Otherwise, continue.

Step 2: Enumerate the Plugin's Own Components

Locate the plugin's installed directory. The plugin is at ~/.claude/plugins/cache/Claudfather/claudna/<version>/. Find the version:

ls -d ~/.claude/plugins/cache/Claudfather/claudna/*/ 2>/dev/null | sort -V | tail -1

Call this PLUGIN_ROOT. Then list what the plugin ships:

ls "$PLUGIN_ROOT/skills/" | grep -v '^_'    # skill names (skip _shared)
ls "$PLUGIN_ROOT/agents/"                   # agent file names
ls "$PLUGIN_ROOT/plugin-hooks/"*.sh         # hook script names

If PLUGIN_ROOT doesn't exist (plugin not installed yet), tell the user:

The plugin must be installed before this cleanup runs. Please run: /plugin marketplace add Claudfather/clauDNA /plugin install claudna@Claudfather Then re-run this skill.

And stop.

Step 3: Build the Cleanup Manifest

For each component the plugin ships, check whether a matching file exists in the legacy overlay location.

Skills: for each <name> in the plugin's skills/ directory, check if ~/.claude/skills/<name>/SKILL.md exists.

Agents: for each <name>.md in the plugin's agents/ directory, check if ~/.claude/agents/<name>.md exists.

Hook scripts: for each <basename>.sh in the plugin's plugin-hooks/ directory, check if ~/.claude/hooks/<basename>.sh exists.

Commands: check for known-legacy command files in ~/.claude/commands/:

  • clauDNA-sync.md
  • clauDNA-setup.md
  • clauDNA-migrate.md
  • claudfather-sync.md
  • claudefather-sync.md (These were never plugin components — they're install.sh artifacts that the plugin doesn't replace.)

Breadcrumb files: .clauDNA-repo, .claudfather-repo, .claudefather-repo in ~/.claude/.

Docs: check ~/.claude/docs/SETUP_GUIDE.md and ~/.claude/docs/CLAUDE_MD_TEMPLATE.md — install.sh copied these. They're stale once the plugin is in place.

Build a manifest of full paths to be removed.

Step 4: Detect Customizations (Safety Check)

For each candidate file in the manifest, compare its content to the plugin's version:

diff -q ~/.claude/skills/<name>/SKILL.md "$PLUGIN_ROOT/skills/<name>/SKILL.md"

Categorize:

  • Identical to plugin version → safe to remove without question.
  • Differs from plugin version → may be user customization. Flag for explicit confirmation.

Skills with subdirectories (e.g., references/) — diff the full tree using diff -rq.

For hook scripts, agents, docs: same approach — diff -q against the plugin's copy.

Breadcrumb files and legacy command files have no plugin equivalent, so they're always safe to remove.

Step 5: Present the Plan

Show the user what will happen, grouped by category:

Cleanup Plan
═══════════════════════════════════════════════════════════════

Breadcrumbs (always safe to remove):
  ~/.claude/.clauDNA-repo

Legacy command files (no plugin equivalent — safe):
  ~/.claude/commands/clauDNA-sync.md
  ~/.claude/commands/clauDNA-setup.md

Skills (N total: M identical to plugin, K differ — see below):
  Identical (safe):
    ~/.claude/skills/access-path-audit/      (matches plugin)
    ~/.claude/skills/cache-audit/            (matches plugin)
    ...
  Differ (you may have customized these — confirm individually):
    ~/.claude/skills/tech-debt/              (differs from plugin)

Hooks (N total: M identical, K differ):
  Identical (safe):
    ~/.claude/hooks/auto-format.sh           (matches plugin)
    ...
  Differ:
    ~/.claude/hooks/pretooluse-permissions.sh  (differs from plugin)

Agents (N total: M identical, K differ):
  ...

Docs:
  ~/.claude/docs/SETUP_GUIDE.md   (stale copy of plugin's SETUP_GUIDE.md — safe to remove)
  ~/.claude/docs/CLAUDE_MD_TEMPLATE.md   (stale copy — safe to remove)

═══════════════════════════════════════════════════════════════
Summary: N files/directories total, M safe, K need confirmation.

Step 6: Confirm Differing Items One-by-One

For each item flagged as "differs":

  1. Show the diff (diff -u between the user's copy and the plugin's copy).
  2. Ask: Keep / Remove / Show full diff.
  3. If Keep: drop from the manifest, leave the file in place. Note that this file will shadow the plugin's /claudna:<name> version under its bare /<name> invocation. The user can later rename or delete it manually.
  4. If Remove: keep in the manifest.

Do not auto-resolve. Ambiguous cases must be the user's call.

Step 7: statusLine Check

If ~/.claude/settings.json exists, check whether statusLine.command points at ~/.claude/hooks/statusline.sh (the old install location):

grep -l '~/.claude/hooks/statusline.sh' ~/.claude/settings.json 2>/dev/null

If yes, the user's statusLine will break once ~/.claude/hooks/statusline.sh is removed. Ask:

  1. Update path to plugin cache — rewrite the command to bash ~/.claude/plugins/cache/Claudfather/claudna/<version>/plugin-hooks/statusline.sh. Warn that this version is pinned and will need updating on plugin bumps.
  2. Remove statusLine entirely — delete the statusLine key from settings.json. User can re-add later.
  3. Skip — leave settings.json alone; user will fix it manually.

Use Read + Edit (not Bash) to modify settings.json. Never use > redirect to overwrite — that can race with other writers.

Step 8: Final Confirmation

Print the full final manifest (after Step 6 user choices), identify the current native Claude session as the run owner, and ask one last time:

Will remove N files/directories. Continue? [y/N]

Require explicit y or yes. Anything else aborts. If the loaded local skill does not provide a usable native session ID, stop this workflow; do not rename it standalone or switch to an operation ID.

Step 9: Backup

Before any destructive operation, back up the entire manifest beneath the effective clauDNA root. The documented local Claude Code skill mechanism renders ${CLAUDE_SESSION_ID}; native acceptance of that substitution remains pending. Resolve R with the phase-01 path resolver and use that exact validated native ID:

SESSION_ID='${CLAUDE_SESSION_ID}'
case "$SESSION_ID" in
  ''|*CLAUDE_SESSION_ID*) echo "No resolved native Claude session ID; stop before cleanup."; exit 1 ;;
esac
SESSION_ARTIFACTS=$(python3 -B "${CLAUDE_PLUGIN_ROOT}/lib/claudna/session_store" paths \
  --host claude --session "$SESSION_ID" --kind artifacts) || exit 1
STATE_ROOT=${SESSION_ARTIFACTS%/sessions/*}
RUN="session-$SESSION_ID"
BACKUP_DIR="$STATE_ROOT/backups/legacy-install/$RUN"
if [ -e "$BACKUP_DIR" ]; then
  echo "Backup path already exists; stop without overwriting it: $BACKUP_DIR"
  exit 1
fi
umask 077
mkdir -p -m 700 "$STATE_ROOT/backups/legacy-install"
mkdir -m 700 "$BACKUP_DIR" || exit 1

When ${CLAUDE_PLUGIN_ROOT} is unavailable, substitute the absolute package <claudna-root> resolved from the loaded skill per ../_shared/claudna-root.md. Do not replace a missing native session ID with a standalone operation ID. A maintainer who is explicitly operating outside all native Claude, Codex, and Cursor workflows must run the separate standalone operation contract (session_store operation-dir --label legacy-cleanup --create) as its own operation; this skill's manifest and source-deletion workflow do not perform that operation.

For each path in the manifest, cp -r (or cp for files) into a mirror structure under $BACKUP_DIR. Preserve the original path structure so restoration is cp -r back.

If any backup copy fails or the copied count does not match the manifest, stop before Step 10. Keep the partial backup for review; do not remove source files or silently reuse this run path.

Print:

Backed up N items to R/backups/legacy-install/<run>/

Step 10: Execute

Remove each item in the manifest:

  • Skills: rm -rf ~/.claude/skills/<name> (skill dirs are subdirectories)
  • Agents: rm ~/.claude/agents/<name>.md
  • Hooks: rm ~/.claude/hooks/<name>.sh
  • Commands: rm ~/.claude/commands/<name>.md
  • Breadcrumbs: rm ~/.claude/.clauDNA-repo etc.
  • Docs: rm ~/.claude/docs/SETUP_GUIDE.md etc.

After removing all items, prune now-empty parent directories:

rmdir ~/.claude/skills ~/.claude/hooks ~/.claude/agents ~/.claude/commands ~/.claude/docs 2>/dev/null

(rmdir only succeeds if the directory is empty — don't add -rf.)

Step 11: Print Next Steps

Cleanup complete.
═══════════════════════════════════════════════════════════════
  Removed:  N files/directories
  Backup:   R/backups/legacy-install/<run>/
  
Restore any file with:
  cp -r "$BACKUP_DIR/<path>" "$HOME/.claude/<path>"

Next:
  - Run /reload-plugins (or restart Claude Code) to pick up the cleanup.
  - Invoke any claudna skill as /claudna:<skill-name> to verify the plugin is the only source.
═══════════════════════════════════════════════════════════════

Safety Notes

  • Never run without an installed plugin. Step 2 enforces this. Without the plugin, the discovery step has no manifest to work from.
  • Never auto-resolve customized files. Step 6 requires per-file confirmation for anything that differs from the plugin's version.
  • Always back up before removing. Step 9 is mandatory.
  • Keep existing backups read-only. Existing ~/.local/share/clauDNA/backups/cleanup-legacy-install-<timestamp>/ directories are not migrated or removed. To restore an item from an old backup, copy its mirrored path back, for example cp -r "$HOME/.local/share/clauDNA/backups/cleanup-legacy-install-<timestamp>/skills/<name>" "$HOME/.claude/skills/<name>". From a new backup, restore using the same relative path beneath $BACKUP_DIR; restoration is an explicit operator action.
  • Never overwrite a run backup. If the new backup path already exists, stop and retain it. Do not use a timestamp, PID, cwd, or fabricated session as a fallback identity.
  • Never modify permissions.allow entries in settings.json. Old Bash(...) patterns added by install.sh are additive and still useful in the plugin world. Leaving them alone is correct.
  • Use Read + Edit for settings.json edits. Never > overwrite — that races with concurrent Claude sessions writing to the same file.

04 同仓库更多 Skills