From agent-dashboard
Safely restructure code in an isolated git worktree with test-preserved, incremental transformations
How this skill is triggered — by the user, by Claude, or both
Slash command
/agent-dashboard:refactorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Safely refactor code while preserving all existing behavior.
Safely refactor code while preserving all existing behavior.
Refactoring goal: $ARGUMENTS
Follow these phases in order. Each phase has a gate — do not proceed until the gate is satisfied. Apply all project rules and conventions that are in your context.
basename $(git rev-parse --show-toplevel)git checkout maingit pull origin mainrefactor/<name> and worktree ../worktrees/<app>/<name> from main:
mkdir -p ../worktrees/<app> && git worktree add ../worktrees/<app>/<name> -b refactor/<name> main
find . -name '.env*' -not -path './.git/*' -not -path './node_modules/*'./.env → ../worktrees/<app>/<name>/.env./services/api/.env.local → ../worktrees/<app>/<name>/services/api/.env.localfor f in $(find . -name '.env*' -not -path './.git/*' -not -path './node_modules/*'); do mkdir -p "../worktrees/<app>/<name>/$(dirname "$f")" && cp "$f" "../worktrees/<app>/<name>/$f"; done.claude/settings.local.json exists: mkdir -p ../worktrees/<app>/<name>/.claude && cp .claude/settings.local.json ../worktrees/<app>/<name>/.claude/pwd and git branch --show-currentfind command in both directories and diff the file lists. If any files are missing in the worktree, halt and report failure. If the source repo had no .env* files, note that explicitly.Gate: Working directory is the new worktree on the correct branch, based on latest main. If .env* files existed in the source repo, they are all present in the worktree.
Start two tracks in parallel:
Background — Environment setup: Launch a background agent (run_in_background: true) to set up the dev environment. The agent must:
Auto-detect project type from project files (highest match wins):
| Priority | Signal | Type |
|---|---|---|
| 1 | react-native in package.json dependencies | Mobile |
| 2 | next, vite, or webpack in package.json | Web |
| 3 | requirements.txt, pyproject.toml, or setup.py | Python |
| 4 | go.mod | Go |
| 5 | Dockerfile or docker-compose.yml | Containerized |
Ask the user only if no signal matches.
Install dependencies appropriate for the project type (e.g. pip install, npm install, go mod download). Configure ports, create emulators/simulators as needed.
Symlink large data directories (data/, datasets/, evals/, models/, artifacts/) from the source repo rather than copying.
On success, write a sentinel file: touch .env-setup-done
On failure, write the error: echo "<error message>" > .env-setup-failed
Foreground — Scoping:
Gate: The scope is clear. Affected files and their test coverage are identified.
Pre-gate: Check for .env-setup-done in the worktree root.
node_modules/ exists, pip list succeeds, go env GOPATH works) and data symlinks resolve correctly..env-setup-failed exists: surface the error and halt.make test to establish a passing baseline./fix first.Gate: All tests pass. The baseline is established.
Apply the refactoring in small, atomic steps. For each step:
make test immediately after the change.git checkout -- <file1> <file2> ...)Do not batch multiple changes between test runs. One change, one test run.
Gate: All transformations applied. All tests pass after each step.
make test one final time.Gate: No dead code remains. All tests pass.
refactor: conventional commit message that describes what was restructured and why.Gate: Clean commit with conventional message. Behavior is unchanged. No critical or high-severity review issues.
Triggered when the user indicates the refactor has been merged upstream.
.env-setup-done/.env-setup-failed sentinel filesnpx claudepluginhub bjornjee/agent-dashboard --plugin agent-dashboardSafely refactors code test-first: verifies/writes tests, one structural change at a time, preserves behavior. Use for 'refactor this', 'clean this up', reorganization.
Orchestrates a multi-step refactoring pipeline: analyzes code quality, plans improvements, optionally writes tests, implements changes, and reviews results. Routes simple refactors to a lighter workflow.
Orchestrates behavior-preserving refactors: confirm tests green, restructure in small steps, keep tests green, review, and gated commit. Use when structure should improve but behavior must not change.