repo-rename
Imported from paulrberg/agent-skills/skills/repo-rename.
Install
npx skills add https://github.com/PaulRBerg/agent-skills/tree/main/skills/repo-rename
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install paulrberg-agent-skills@llmmart
git clone https://github.com/PaulRBerg/agent-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole paulrberg/agent-skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Repo Rename
If these instructions are already present in the conversation from a slash or dollar invocation, follow them directly; do not invoke this skill again through a skill tool.
Preview the complete GitHub, Git, filesystem, and agent-continuity mutation set before applying a repository rename.
Scope
- Rename the current GitHub repository, matching local folder, and
originURL. - Update literal old paths in
~/.claude/projects,~/claude/projectswhen present,~/.codex/sessions, and~/.codex/config.tomlonly when the repository has an active Claude Code or Codex transcript; this continuity update does not apply to repos with no active transcripts. - Update constrained literal old-name references inside the repository, excluding VCS, dependencies (including Python virtual environments), caches, and generated build directories.
- By default, skip
PROMPT.md,TODO.md, and symlinks before reading replacement candidates; prune excluded directories during discovery. When the user explicitly authorizes updating notes, dependencies, caches, or generated files, pass--include-local-stateto both preview and apply. This includes those repository text files while preserving file permissions; symlinks, binary files, and.gitremain excluded. - The helper honors
CLAUDE_CONFIG_DIRandCODEX_HOME, gates continuity updates on active transcripts, and replaces only the absolute repository path in continuity stores and Codex config. - Do not modify other transcript stores, archives, remotes, or repositories.
Workflow
Check whether the repository has any active AI chat transcript before treating continuity preservation as in scope:
- Claude Code: resolve
${CLAUDE_CONFIG_DIR:-~/.claude}/projects/<encoded-repo-path>(the absolute repo path with every non-alphanumeric character replaced by-) and check it exists and is non-empty. - Codex: resolve
${CODEX_HOME:-~/.codex}/sessionsand check whether any session file references the exact absolute repo path. - If neither exists, state that the transcript-continuity update does not apply; the rename may still proceed for the GitHub, git, filesystem, and repository-content changes below.
- Claude Code: resolve
Resolve the skill directory and run the helper from the repository to produce a read-only preview:
uv run <skill-dir>/scripts/repo-rename.py <new-name> --dry-runThe helper requires a clean worktree, matching GitHub repo/folder names, a free target path, and valid GitHub context. It prints the old/new repo and paths, exact confirmation token, external commands, directory moves, every replacement file, occurrence counts, and rollback coverage.
If
--dry-runwas requested, return the preview and stop. A successful dry run must not change the GitHub repo, remote, folder, config, transcripts, or repository files.Otherwise present the complete preview and require explicit confirmation in a subsequent user message. Explain that the confirmation authorizes the GitHub rename, local folder move, Claude project-folder move when enabled, origin update, and every listed continuity/repository replacement. Lead with
### ⚠️ Rename preview — no changes made; show GitHub, folder, origin, replacement counts, and rollback coverage in compact tables, then the exhaustive file/count list. Put the exact confirmation token alone in code formatting. If any preview fact changes, regenerate it and ask again.After confirmation, pass the preview's exact token:
uv run <skill-dir>/scripts/repo-rename.py <new-name> --apply --confirm '<owner/old->owner/new>'The helper re-runs preflight, backs up every replacement file, applies deterministic literal replacements, and attempts rollback on failure. Never bypass its clean-tree, target-path, or confirmation checks.
Verify the helper's result with
gh repo view,git remote get-url origin,pwd -P, and a search for remaining old absolute-path/name references in the listed scope. Report intentional remaining matches separately.
Completion
Dry-run completion is a full mutation preview with zero writes. Apply completion requires the new GitHub identity,
folder, remote, and listed continuity references to agree, plus a clean verification report. If rollback is incomplete,
stop and lead with ### ⛔ Rollback incomplete, then report every failed rollback action before doing anything else. On
success, use ### ✅ Repository renamed and a surface/expected/verified table. Keep helper JSON, confirmation tokens,
commands, paths, URLs, and rollback errors exact and undecorated.
Files (agent-skills)
-
agents
-
openai.yaml 43 B
policy: allow_implicit_invocation: false
-
-
scripts
-
repo-rename.py 12.5 KB
#!/usr/bin/env -S uv run --script """Preview and apply a constrained GitHub repository rename.""" from __future__ import annotations import argparse import json import os import re import shutil import subprocess import sys import tempfile from dataclasses import dataclass from pathlib import Path EXCLUDED_PARTS = {".git", "node_modules", ".venv", "venv", ".cache", "__pycache__", "dist", "build", ".next", "coverage"} PROTECTED_FILES = {"PROMPT.md", "TODO.md"} class RenameError(RuntimeError): pass @dataclass(frozen=True) class Replacement: path: Path pairs: tuple[tuple[bytes, bytes], ...] occurrences: int def claude_project_name(root: Path) -> str: return re.sub(r"[^A-Za-z0-9]", "-", str(root)) def run(*args: str, cwd: Path | None = None) -> str: result = subprocess.run(args, cwd=cwd, check=False, text=True, capture_output=True) if result.returncode: detail = result.stderr.strip() or result.stdout.strip() or f"exit {result.returncode}" raise RenameError(f"{' '.join(args)}: {detail}") return result.stdout.strip() def readable_files(root: Path, *, repo: bool = False, include_local_state: bool = False) -> list[Path]: protected = set() if include_local_state else PROTECTED_FILES excluded = {".git"} if include_local_state else EXCLUDED_PARTS if root.is_symlink() or not root.exists() or root.name in protected: return [] if root.is_file(): return [root] files: list[Path] = [] for directory, names, filenames in os.walk(root): parent = Path(directory) names[:] = [ name for name in names if not (parent / name).is_symlink() and not (repo and name in excluded) ] for name in filenames: path = parent / name if name not in protected and not path.is_symlink() and path.is_file(): files.append(path) return files def count_pairs(path: Path, pairs: tuple[tuple[bytes, bytes], ...]) -> int: try: data = path.read_bytes() except OSError: return 0 if b"\0" in data: return 0 return sum(data.count(old) for old, _ in pairs) def continuity_paths() -> tuple[Path, Path]: home = Path.home() return ( Path(os.environ.get("CLAUDE_CONFIG_DIR") or home / ".claude") / "projects", Path(os.environ.get("CODEX_HOME") or home / ".codex"), ) def collect_replacements( old_root: Path, new_root: Path, old_name: str, new_name: str, *, include_local_state: bool = False ) -> list[Replacement]: claude_projects, codex_home = continuity_paths() path_pair = ((str(old_root).encode(), str(new_root).encode()),) replacements = [] for path in readable_files(codex_home / "sessions"): occurrences = count_pairs(path, path_pair) if occurrences: replacements.append(Replacement(path, path_pair, occurrences)) project = claude_projects / claude_project_name(old_root) claude_active = project.is_dir() and next(project.iterdir(), None) is not None if claude_active or replacements: candidates = set() for root in (claude_projects, Path.home() / "claude/projects", codex_home / "config.toml"): candidates.update(readable_files(root)) for path in candidates: occurrences = count_pairs(path, path_pair) if occurrences: replacements.append(Replacement(path, path_pair, occurrences)) name_pair = ((old_name.encode(), new_name.encode()),) for path in readable_files(old_root, repo=True, include_local_state=include_local_state): occurrences = count_pairs(path, name_pair) if occurrences: replacements.append(Replacement(path, name_pair, occurrences)) return sorted(replacements, key=lambda item: str(item.path)) def preflight(new_name: str, *, include_local_state: bool = False) -> dict[str, object]: if not new_name or new_name.startswith(".") or "/" in new_name: raise RenameError(f"invalid repo name: {new_name!r}") old_root = Path(run("git", "rev-parse", "--show-toplevel")).resolve() status = run("git", "status", "--short", cwd=old_root) if status: raise RenameError(f"working tree is not clean:\n{status}") repo = json.loads(run("gh", "repo", "view", "--json", "nameWithOwner,sshUrl,url", cwd=old_root)) old_repo = repo["nameWithOwner"] owner, repo_name = old_repo.split("/", 1) old_name = old_root.name if repo_name != old_name: raise RenameError(f"repo/folder mismatch: {repo_name} vs {old_name}") new_root = old_root.parent / new_name if new_root.exists(): raise RenameError(f"target folder already exists: {new_root}") remote = run("git", "remote", "get-url", "origin", cwd=old_root) if remote.startswith("git@github.com:"): new_remote = f"git@github.com:{owner}/{new_name}.git" elif remote.startswith("https://github.com/"): new_remote = f"https://github.com/{owner}/{new_name}.git" else: new_remote = f"git@github.com:{owner}/{new_name}.git" claude_projects, _ = continuity_paths() old_claude = claude_projects / claude_project_name(old_root) new_claude = claude_projects / claude_project_name(new_root) if old_claude.exists() and new_claude.exists(): raise RenameError(f"target Claude project directory exists: {new_claude}") replacements = collect_replacements(old_root, new_root, old_name, new_name, include_local_state=include_local_state) token = f"{old_repo}->{owner}/{new_name}" return { "old_root": old_root, "new_root": new_root, "old_name": old_name, "new_name": new_name, "owner": owner, "old_repo": old_repo, "new_repo": f"{owner}/{new_name}", "old_remote": remote, "new_remote": new_remote, "old_claude": old_claude, "new_claude": new_claude, "move_claude": old_claude.is_dir() and next(old_claude.iterdir(), None) is not None, "replacements": replacements, "confirm": token, "include_local_state": include_local_state, } def preview(plan: dict[str, object]) -> dict[str, object]: replacements = plan["replacements"] assert isinstance(replacements, list) return { "mode": "dry-run", "old_repo": plan["old_repo"], "new_repo": plan["new_repo"], "old_root": str(plan["old_root"]), "new_root": str(plan["new_root"]), "confirmation_token": plan["confirm"], "include_local_state": plan["include_local_state"], "mutations": [ {"kind": "github-rename", "command": f"gh repo rename {plan['new_name']} --yes"}, {"kind": "origin", "from": plan["old_remote"], "to": plan["new_remote"]}, {"kind": "folder", "from": str(plan["old_root"]), "to": str(plan["new_root"])}, { "kind": "claude-project-folder", "enabled": plan["move_claude"], "from": str(plan["old_claude"]), "to": str(plan["new_claude"]), }, { "kind": "literal-replacements", "files": [ {"path": str(item.path), "occurrences": item.occurrences} for item in replacements ], }, ], "rollback": "replacement files are backed up; folder, origin, Claude directory, and GitHub name are restored in reverse order on failure", } def moved_path(path: Path, plan: dict[str, object]) -> Path: old_root = plan["old_root"] new_root = plan["new_root"] old_claude = plan["old_claude"] new_claude = plan["new_claude"] assert all(isinstance(item, Path) for item in (old_root, new_root, old_claude, new_claude)) try: return new_root / path.relative_to(old_root) except ValueError: pass if plan["move_claude"]: try: return new_claude / path.relative_to(old_claude) except ValueError: pass return path def apply(plan: dict[str, object]) -> dict[str, object]: old_root = plan["old_root"] new_root = plan["new_root"] old_claude = plan["old_claude"] new_claude = plan["new_claude"] replacements = plan["replacements"] assert isinstance(old_root, Path) and isinstance(new_root, Path) assert isinstance(old_claude, Path) and isinstance(new_claude, Path) assert isinstance(replacements, list) backup_dir = Path(tempfile.mkdtemp(prefix="repo-rename-rollback-")) backups: dict[Path, Path] = {} github_done = remote_done = repo_moved = claude_moved = False rollback_errors: list[str] = [] try: for index, item in enumerate(replacements): backup = backup_dir / str(index) shutil.copy2(item.path, backup) backups[item.path] = backup run("gh", "repo", "rename", str(plan["new_name"]), "--yes", cwd=old_root) github_done = True run("git", "remote", "set-url", "origin", str(plan["new_remote"]), cwd=old_root) remote_done = True old_root.rename(new_root) repo_moved = True if plan["move_claude"]: old_claude.rename(new_claude) claude_moved = True for item in replacements: target = moved_path(item.path, plan) data = target.read_bytes() for old, new in item.pairs: data = data.replace(old, new) temp = target.with_name(f".{target.name}.repo-rename.tmp") temp.write_bytes(data) shutil.copymode(target, temp) os.replace(temp, target) shutil.rmtree(backup_dir) return { "mode": "apply", "status": "success", "repo": plan["new_repo"], "root": str(new_root), "remote": plan["new_remote"], "files_updated": len(replacements), } except Exception as error: for original, backup in backups.items(): try: target = moved_path(original, plan) if repo_moved or claude_moved else original target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(backup, target) except Exception as rollback_error: # pragma: no cover - best effort reporting rollback_errors.append(f"restore {original}: {rollback_error}") if claude_moved: try: new_claude.rename(old_claude) except Exception as rollback_error: rollback_errors.append(f"restore Claude directory: {rollback_error}") if repo_moved: try: new_root.rename(old_root) repo_moved = False except Exception as rollback_error: rollback_errors.append(f"restore repository folder: {rollback_error}") rollback_cwd = old_root if old_root.exists() else new_root if remote_done: try: run("git", "remote", "set-url", "origin", str(plan["old_remote"]), cwd=rollback_cwd) except Exception as rollback_error: rollback_errors.append(f"restore origin: {rollback_error}") if github_done: try: run("gh", "repo", "rename", str(plan["old_name"]), "--repo", str(plan["new_repo"]), "--yes") except Exception as rollback_error: rollback_errors.append(f"restore GitHub name: {rollback_error}") detail = f"apply failed: {error}" if rollback_errors: detail += "; rollback incomplete: " + "; ".join(rollback_errors) else: detail += "; rollback completed" raise RenameError(detail) from error def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("new_name") mode = parser.add_mutually_exclusive_group(required=True) mode.add_argument("--dry-run", action="store_true") mode.add_argument("--apply", action="store_true") parser.add_argument("--confirm") parser.add_argument("--include-local-state", action="store_true", help="include explicitly authorized notes, dependencies, caches, and generated files") args = parser.parse_args() try: plan = preflight(args.new_name, include_local_state=args.include_local_state) if args.apply and args.confirm != plan["confirm"]: raise RenameError(f"--apply requires --confirm {plan['confirm']!r}") result = apply(plan) if args.apply else preview(plan) except RenameError as error: print(f"repo-rename: {error}", file=sys.stderr) return 64 print(json.dumps(result, indent=2, sort_keys=True)) return 0 if __name__ == "__main__": raise SystemExit(main())
-
-
SKILL.md 4.8 KB
--- argument-hint: <new-name> [--dry-run] disable-model-invocation: true name: repo-rename description: "Preview or rename a GitHub upstream repo and matching local project folder, update origin, and preserve Codex CLI and Claude Code continuity references." --- # Repo Rename If these instructions are already present in the conversation from a slash or dollar invocation, follow them directly; do not invoke this skill again through a skill tool. Preview the complete GitHub, Git, filesystem, and agent-continuity mutation set before applying a repository rename. ## Scope - Rename the current GitHub repository, matching local folder, and `origin` URL. - Update literal old paths in `~/.claude/projects`, `~/claude/projects` when present, `~/.codex/sessions`, and `~/.codex/config.toml` only when the repository has an active Claude Code or Codex transcript; this continuity update does not apply to repos with no active transcripts. - Update constrained literal old-name references inside the repository, excluding VCS, dependencies (including Python virtual environments), caches, and generated build directories. - By default, skip `PROMPT.md`, `TODO.md`, and symlinks before reading replacement candidates; prune excluded directories during discovery. When the user explicitly authorizes updating notes, dependencies, caches, or generated files, pass `--include-local-state` to both preview and apply. This includes those repository text files while preserving file permissions; symlinks, binary files, and `.git` remain excluded. - The helper honors `CLAUDE_CONFIG_DIR` and `CODEX_HOME`, gates continuity updates on active transcripts, and replaces only the absolute repository path in continuity stores and Codex config. - Do not modify other transcript stores, archives, remotes, or repositories. ## Workflow 1. Check whether the repository has any active AI chat transcript before treating continuity preservation as in scope: - Claude Code: resolve `${CLAUDE_CONFIG_DIR:-~/.claude}/projects/<encoded-repo-path>` (the absolute repo path with every non-alphanumeric character replaced by `-`) and check it exists and is non-empty. - Codex: resolve `${CODEX_HOME:-~/.codex}/sessions` and check whether any session file references the exact absolute repo path. - If neither exists, state that the transcript-continuity update does not apply; the rename may still proceed for the GitHub, git, filesystem, and repository-content changes below. 2. Resolve the skill directory and run the helper from the repository to produce a read-only preview: ```sh uv run <skill-dir>/scripts/repo-rename.py <new-name> --dry-run ``` The helper requires a clean worktree, matching GitHub repo/folder names, a free target path, and valid GitHub context. It prints the old/new repo and paths, exact confirmation token, external commands, directory moves, every replacement file, occurrence counts, and rollback coverage. 3. If `--dry-run` was requested, return the preview and stop. A successful dry run must not change the GitHub repo, remote, folder, config, transcripts, or repository files. 4. Otherwise present the complete preview and require explicit confirmation in a subsequent user message. Explain that the confirmation authorizes the GitHub rename, local folder move, Claude project-folder move when enabled, origin update, and every listed continuity/repository replacement. Lead with `### ⚠️ Rename preview — no changes made`; show GitHub, folder, origin, replacement counts, and rollback coverage in compact tables, then the exhaustive file/count list. Put the exact confirmation token alone in code formatting. If any preview fact changes, regenerate it and ask again. 5. After confirmation, pass the preview's exact token: ```sh uv run <skill-dir>/scripts/repo-rename.py <new-name> --apply --confirm '<owner/old->owner/new>' ``` The helper re-runs preflight, backs up every replacement file, applies deterministic literal replacements, and attempts rollback on failure. Never bypass its clean-tree, target-path, or confirmation checks. 6. Verify the helper's result with `gh repo view`, `git remote get-url origin`, `pwd -P`, and a search for remaining old absolute-path/name references in the listed scope. Report intentional remaining matches separately. ## Completion Dry-run completion is a full mutation preview with zero writes. Apply completion requires the new GitHub identity, folder, remote, and listed continuity references to agree, plus a clean verification report. If rollback is incomplete, stop and lead with `### ⛔ Rollback incomplete`, then report every failed rollback action before doing anything else. On success, use `### ✅ Repository renamed` and a surface/expected/verified table. Keep helper JSON, confirmation tokens, commands, paths, URLs, and rollback errors exact and undecorated.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.