refactor
Use when refactoring, cleaning up code, reducing complexity, fixing code smells, or improving code quality. Audits code for dead code, nesting, and patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when refactoring, cleaning up code, reducing complexity, fixing code smells, or improving code quality. Audits code for dead code, nesting, and patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when committing changes, staging files, saving work, or making a git commit. Creates clean commits in the repository's own convention (conventional commits, area prefix, tracker ID, or plain) with secret scanning (GitLeaks).
Use when creating a branch, starting work on an issue, or checking out a new feature branch. Validates branch naming and links to GitHub issues automatically.
Use when opening a PR, submitting for review, pushing a branch, or creating a pull request. Pushes and creates GitHub PRs with auto-assignment and description.
Use when hardening a dependency supply chain, pinning versions, adding registry/security flags, or setting up Renovate. Detects the language and locks down install scripts, versions, and CI checks (JS/TS, Python, Go, Rust).
Use when adding CI/CD, creating workflows, auditing GitHub Actions, or fixing action pinning. Creates and audits workflows for SHA pinning and permissions.
Use when filing a bug, requesting a feature, creating an issue, or updating issue details. Manages issues on GitHub (and GitLab via glab) with templates, formatting, and auto-assignment.
| name | refactor |
| description | Use when refactoring, cleaning up code, reducing complexity, fixing code smells, or improving code quality. Audits code for dead code, nesting, and patterns. |
| license | MIT |
| allowed-tools | Read Glob Grep Edit |
| model | sonnet |
| effort | high |
| context | fork |
| agent | general-purpose |
| compatibility | Any language; general + design rules always apply, the TS/JS idiom rules apply only to TS/JS files |
| metadata | {"short-description":"Refactor and reduce code complexity."} |
You are an expert code reviewer focused on refactoring.
Read individual rule files in rules/ for detailed explanations and code examples.
| Section | Prefix | Rules |
|---|---|---|
| General Patterns | general- | dead-code, deep-nesting, long-functions, magic-values, boolean-params, duplication |
| TypeScript/JS Idioms | ts- | type-assertions, optional-chaining, nullish-coalescing, barrel-reexports, enum-union, async-await |
| Design Principles | design- | single-responsibility, interface-segregation, god-objects, tight-coupling |
Language gating: the General Patterns and Design Principles rules apply to any language. The ts- idiom rules apply only to TS/JS files (.ts/.tsx/.js/.jsx/.mts/.cts) — skip them for other languages.
Classify the request before acting, and default to read-only when intent is ambiguous or diagnostic:
When intent is ambiguous, stay in Audit mode and end the report by offering to apply the fixes.
Scan the target scope (specific files, directory, or full codebase) for violations:
General Patterns:
TypeScript/JS Idioms (TS/JS files only — skip for other languages):
as type assertions (excluding test files)&& for null checks where ?. applies|| used for defaults where ?? is saferindex.ts re-export files (hurt tree-shaking, slow bundlers, risk circular deps).then() chains in async codeDesign Principles:
List all findings grouped by category:
## Refactoring Audit Results
### General Patterns
- `src/services/order.ts:45` - Function `processOrder` is 62 lines → extract validation and submission
- `src/utils/helpers.ts:12-18` - Commented-out code block → remove
### TypeScript/JS Idioms
- `src/api/client.ts:23` - `as UserResponse` → add type guard
- `src/config.ts:8` - `port || 3000` → use `??` (port could be 0)
### Design Principles
- `src/services/user.ts` - 14 named exports → split into focused modules
### Summary
| Category | Violations | Files |
|----------------------|------------|-------|
| General Patterns | X | N |
| TypeScript/JS Idioms | Y | N |
| Design Principles | Z | N |
| **Total** | **X+Y+Z** | **N** |
Skip this step entirely in Audit mode. Only apply changes when the request is in Fix mode (see Mode Detection).
Apply refactorings. For each fix: