refactor
<!-- plugin/skills/refactor/SKILL.md -->
What this skill does
<!-- plugin/skills/refactor/SKILL.md -->
---
name: refactor
description: This skill should be used when the user asks to "refactor this", "restructure code", "reorganize modules", "rename and move", "safe restructuring", "reorganize code", "move and rename", or wants to reorganize code without changing behavior.
argument-hint: "[refactoring goal]"
disable-model-invocation: true
---
# Safe Refactoring
> **Requires:** Claude Code Agent Teams feature.
Architect-planned, reviewer-validated code restructuring with per-step compilation checks.
**Arguments:** $ARGUMENTS
## Instructions
1. **Parse arguments** (optional):
- Any text -> use as the refactoring goal/context for the architect
2. **Determine context**: What code to refactor, the goal of the restructuring, and any constraints. If no context is obvious, ask the user what they'd like refactored.
---
### Phase 1: Analysis
3. **Launch for analysis**: Call the Mira `launch` MCP tool to get the architect agent spec:
```
launch(team="refactor-team", scope=user_context, members="atlas")
```
4. **Create the team**:
```
TeamCreate(team_name=result.data.suggested_team_id)
```
5. **Create and assign** the analysis task:
```
TaskCreate(subject=atlas_agent.task_subject, description=atlas_agent.task_description)
TaskUpdate(taskId=id, owner="atlas", status="in_progress")
```
6. **Spawn Atlas (architect)** using `Task` tool:
```
Task(
subagent_type="general-purpose",
name="atlas",
model=atlas_agent.model,
team_name=result.data.suggested_team_id,
prompt=atlas_agent.prompt + "\n\n## Refactoring Goal\n\n" + user_context,
run_in_background=true
)
```
IMPORTANT: Do NOT use `mode="bypassPermissions"` -- Atlas is read-only.
IMPORTANT: Always pass model="sonnet" to the Task tool. This ensures read-only agents use a cost-efficient model.
7. **Wait** for Atlas to report via SendMessage.
---
### Phase 2: Validation
8. **Launch for validation**: Call `launch` to get the reviewer agent spec:
```
launch(team="refactor-team", scope=user_context, members="iris")
```
9. **Spawn Iris (safety reviewer)** using `Task` tool:
```
Task(
subagent_type="general-purpose",
name="iris",
model=iris_agent.model,
team_name=result.data.suggested_team_id,
prompt=iris_agent.prompt + "\n\n## Refactoring Plan\n\n" + atlas_plan,
run_in_background=true
)
```
IMPORTANT: Do NOT use `mode="bypassPermissions"` -- Iris is read-only.
IMPORTANT: Always pass model="sonnet" to the Task tool. This ensures read-only agents use a cost-efficient model.
10. **Send Atlas's plan** to Iris via `SendMessage` so she has the specific plan to validate.
11. **Create and assign** the validation task.
12. **Wait** for Iris to report via SendMessage. Then shut down both analyst agents.
---
### Phase 3: Synthesis
13. **Combine** Atlas's plan with Iris's feedback:
- If Iris found missing callers or risks, incorporate them
- If rated "needs revision" or "too risky", revise accordingly
14. **Present** the validated refactoring plan to the user and **WAIT for approval**.
---
### Phase 4: Implementation
15. **Execute the refactoring steps** yourself. For each step:
- Make the changes
- Run `cargo test --no-run` to verify compilation (NEVER use --release)
- If it doesn't compile, fix before moving to the next step
16. For **large refactors** (5+ files), launch implementation agents:
```
launch(team="refactor-team", scope=implementation_plan, members="ash")
```
Spawn implementation agents with `mode="bypassPermissions"`:
- Group steps by file ownership to avoid conflicts
- Max 3 steps per agent
- Each agent verifies with `cargo test --no-run`
---
### Phase 5: Verification
17. **Launch for verification**: Call `launch` to get the verifier agent spec:
```
launch(team="refactor-team", scope=summary_of_changes, members="ash")
```
18. **Spawn Ash (build verifier)** using `Task` tool:
```
Task(
subagent_type="general-purpose",
name="ash",
model=ash_agent.model,
team_name=result.data.suggested_team_id,
prompt=ash_agent.prompt + "\n\n## Changes Made\n\n" + summary_of_changes,
run_in_background=true,
mode="bypassPermissions"
)
```
19. **Wait** for Ash to report. If tests fail: fix regressions or update test imports/paths.
---
### Phase 6: Finalize
20. **Report** summary of structural changes to the user.
21. **Cleanup**: Send `shutdown_request` to remaining agents, then `TeamDelete`.
## Examples
```
/mira:refactor
-> Prompts for what to refactor, then runs the full analysis -> validation -> implementation cycle
/mira:refactor Split the database module into separate files per concern
-> Atlas analyzes the DB module, plans the split, Iris validates, then implements
/mira:refactor Rename the "watcher" module to "file_monitor" across the codebase
-> Safe rename with caller analysis and per-step compilation checks
```
## Agent Roles
| Phase | Agent | Focus |
|-------|-------|-------|
| Analysis | Atlas (architect) | Map current structure, design target, plan migration steps |
| Validation | Iris (safety reviewer) | Verify completeness, check for hidden behavior changes |
| Verification | Ash (build verifier) | Run tests, compilation, linters between steps |
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.