{"id":"code-refactor","name":"code-refactor","summary":"ファイル間の変数や関数の名前変更、パターンの置き換え、API呼び出しの更新など、一括コードリファクタリング操作を行います。","body":"# Code Refactor\n\nSystematic code refactoring across files. **Auto-switches to execution mode** for 10+ files (90% token savings).\n\n## Mode Selection\n\n- **1-9 files**: Use native tools (Grep + Edit with replace_all)\n- **10+ files**: Automatically use `code-execution` skill\n\n**Execution example (50 files):**\n```python\nfrom api.code_transform import rename_identifier\nresult = rename_identifier('.', 'oldName', 'newName', '**/*.py')\n# Returns: {'files_modified': 50, 'total_replacements': 247}\n# ~500 tokens vs ~25,000 tokens traditional\n```\n\n## When to Use\n\n- \"rename [identifier] to [new_name]\"\n- \"replace all [pattern] with [replacement]\"\n- \"refactor to use [new_pattern]\"\n- \"update all calls to [function/API]\"\n- \"convert [old_pattern] to [new_pattern]\"\n\n## Core Workflow (Native Mode)\n\n### 1. Find All Occurrences\n```\nGrep(pattern=\"getUserData\", output_mode=\"files_with_matches\")     # Find files\nGrep(pattern=\"getUserData\", output_mode=\"content\", -n=true, -B=2, -A=2)  # Verify with context\n```\n\n### 2. Replace All Instances\n```\nEdit(\n  file_path=\"src/api.js\",\n  old_string=\"getUserData\",\n  new_string=\"fetchUserData\",\n  replace_all=true\n)\n```\n\n### 3. Verify Changes\n```\nGrep(pattern=\"getUserData\", output_mode=\"files_with_matches\")  # Should return none\n```\n\n## Workflow Examples\n\n### Rename Function\n1. Find: `Grep(pattern=\"getUserData\", output_mode=\"files_with_matches\")`\n2. Count: \"Found 15 occurrences in 5 files\"\n3. Replace in each file with `replace_all=true`\n4. Verify: Re-run Grep\n5. Suggest: Run tests\n\n### Replace Deprecated Pattern\n1. Find: `Grep(pattern=\"\\\\bvar\\\\s+\\\\w+\", output_mode=\"content\", -n=true)`\n2. Analyze: Check if reassigned (let) or constant (const)\n3. Replace: `Edit(old_string=\"var count = 0\", new_string=\"let count = 0\")`\n4. Verify: `npm run lint`\n\n### Update API Calls\n1. Find: `Grep(pattern=\"/api/auth/login\", output_mode=\"content\", -n=true)`\n2. Replace: `Edit(old_string=\"'/api/auth/login'\", new_string=\"'/api/v2/authentication/login'\", replace_all=true)`\n3. Test: Recommend integration tests\n\n## Best Practices\n\n**Planning:**\n- Find all instances first\n- Review context of each match\n- Inform user of scope\n- Consider edge cases (strings, comments)\n\n**Safe Process:**\n1. Search → Find all\n2. Analyze → Verify appropriate\n3. Inform → Tell user scope\n4. Execute → Make changes\n5. Verify → Confirm applied\n6. Test → Suggest running tests\n\n**Edge Cases:**\n- Strings/comments: Ask if should update\n- Exported APIs: Warn of breaking changes\n- Case sensitivity: Be explicit\n\n## Tool Reference\n\n**Edit with replace_all:**\n- `replace_all=true`: Replace all occurrences\n- `replace_all=false`: Replace only first (or fail if multiple)\n- Must match EXACTLY (whitespace, quotes)\n\n**Grep patterns:**\n- `-n=true`: Show line numbers\n- `-B=N, -A=N`: Context lines\n- `-i=true`: Case-insensitive\n- `type=\"py\"`: Filter by file type\n\n## Integration\n\n- **test-fixing**: Fix broken tests after refactoring\n- **code-transfer**: Move refactored code\n- **feature-planning**: Plan large refactorings","author":"@mhattingpete","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/mhattingpete/claude-skills-marketplace/tree/main/code-operations-plugin/skills/code-refactor","license":"Apache-2.0","category":"coding","lang":"en","tokens":821,"stars":0,"calls30d":2,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":[]}}