refactoring
Skill1 starsChanged 9 months agoMITView on GitHub
General code refactoring and optimization skill for TypeScript, React, and Node.js projects.
69 other projects use a version of this.
Adopted by
Most recently taken up by
- juninmd/skillstheir own version, first seen Nov 29, 2026
- odjacobs/claude-skillstheir own version, first seen Nov 29, 2026
- gurinderu/crafttheir own version, first seen Nov 29, 2026
- wormeyman/wormeyman-skillstheir own version, first seen Nov 26, 2026
- fabiandistler/agentstheir own version, first seen Nov 25, 2026
- syanga/astacktheir own version, first seen Nov 24, 2026
Used with
Projects with it also use ci-cd, logging and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
JohnJBorenSkillci-cd
CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies
Also in 5 projects that use this
diego-tobalinaSkilllogging
Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.
Also in 4 projects that use this
AWSSkillplanning
Discovers user intent and generates a structured, step-by-step plan for model customization workflows. This skill must always be activated alongside any other skill when the user's request relates to model customization — including fine-tuning, training, building, customizing, reviewing data, or getting advice on approach, regardless of domain. Do not skip this skill even if the immediate ask is narrow (e.g., reviewing data format or a single workflow step), because planning discovers the full scope of work needed. Also activate when the user wants to resume, continue, or modify an existing plan.
Also in 8 projects that use this
dkprogSkilldependency-management
Apply when wiring dependencies, integrating external services, or designing interfaces between modules. Ensures loose coupling through dependency injection, interface segregation, and proper abstraction boundaries.
Also in 3 projects that use this
javalenciacaiSkillmulti-agent-orchestration
Design and coordinate multi-agent systems where specialized agents work together to solve complex problems. Covers agent communication, task delegation, workflow orchestration, and result aggregation. Use when building coordinated agent teams, complex workflows, or systems requiring specialized expertise across domains.
Also in 3 projects that use this
harrissohail6Skilldatabase-design
Database schema design and SQL best practices. Use when designing tables, writing queries, or optimizing database performance.
Also in 5 projects that use this
Other versions69 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 69
- handsontable/handsontable★ 22ksame name
- ciembor/agent-rules-books★ 2.8ksame name
- hitobito/hitobito★ 485same name
- databrickslabs/ontobricks★ 474same name
- DevelopersGlobal/ai-agent-skills★ 220same name
- REPOZY/superpowers-optimized★ 147same name
- extra-org/extra★ 121same name
- tmcfarlane/team-avatar★ 113same name
- larchanka/skills★ 66same name
- nimadorostkar/Claude-Skills-collection★ 41same name
59 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- adjust-personaSkill
- project-contextSkill
- refactor-optimizeSkill
- update-docsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. 0 are common, 13 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 61 edited versions we read keep these.
13
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Before modifying any code, the AI MUST analyze the target file(s) using this framework:
- Distinctive: line 20
Regex Check: Ensure regex patterns are correctly escaped for their context (constructor vs literal).
- Distinctive: line 26
When a file mixes many concerns, apply this extraction order:
- Distinctive: line 39
Prefer constructor injection for classes and parameter injection for functions.
- Distinctive: line 49
Validation: Use schemas for all request data (query, params, body).
- Distinctive: line 54
Error Handling: Use standardized error formats and centralized error handlers.
- Distinctive: line 58
When optimizing UI components:
- Very specific: line 60
Memoization: Use useMemo for expensive calculations and useCallback for stable event handlers.
- Distinctive: line 69
Read the code and analyze it against the Analysis Framework (Section 1).
- Very specific: line 70
Create a refactoring log (e.g., docs/refactoring/[filename]_log.md).
- Distinctive: line 71
Document findings, violations, and a step-by-step refactoring plan with a checklist.
- Very specific: line 73
Backup/Safety: Ensure you have a way to roll back.
- Distinctive: line 77
Follow the extraction order (constants -> pure functions -> state -> etc.).
- Distinctive: line 81
After completing a step, update the refactoring log.
- Very specific: line 85
Check for type errors (tsc).
- Distinctive: line 86
Ensure tests pass (if available).
- Distinctive: line 87
Verify the logic remains consistent with the original implementation.
“Common” is measured: kept by at least 6 in 10 of the 61 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code Refactoring & Optimization Skill
This skill guides the AI to refactor and optimize code, ensuring improvements align with modern architecture, patterns, and quality standards for TypeScript-based stacks.
1. Analysis Framework
Before modifying any code, the AI MUST analyze the target file(s) using this framework:
- Responsibility Check: Does this file/function do too much? (e.g., mixing data fetching, business logic, and UI rendering). Files with excessive responsibilities or too many mutable closure variables are "god objects" — split them.
- Dependency Check: Are there circular dependencies or cross-boundary imports? Are there duplicate instantiations of core services or stores?
- Security Check: Are inputs validated (e.g., using Zod)? Do string validations explicitly use
.trim()and.max(limit)to prevent DoS attacks? Are objects.strict()to prevent prototype pollution or JSON bloat? Are outputs sanitized? - Performance Check: Are expensive operations cached? Are unrelated computations blocking the event loop? Watch for O(n²) patterns in data processing.
- Type Safety: Are there
anytypes or loose casts (as string) that can be made strict? Replace loose state variables with a typed state object. - Regex Check: Ensure regex patterns are correctly escaped for their context (constructor vs literal).
2. Standard Refactoring Patterns
A. "God File" Decomposition
When a file mixes many concerns, apply this extraction order:
- Constants first: Extract magic numbers and static configurations to a
constants.tsorconfig.tsfile. - Pure functions next: Extract stateless logic to its own utility module. These are easiest to test and reuse.
- Stateful classes/logic: Extract logic that manages internal state into classes or dedicated state handlers. Pass dependencies via constructor or factory functions.
- Typed state object: Replace loose variables with a typed
interface+ factory function. This makes state explicit and easier to debug. - Protocol/serialization layer: Extract message parsing and serialization into a dedicated module if handling network traffic or complex data formats.
- Edge/Integration module: Extract external API connections or third-party integrations into a bridge module.
- Feature-specific modules: Extract complex feature logic into standalone modules.
- Slim orchestrator: The original file should become a thin orchestrator that wires modules together and handles lifecycle.
B. Dependency Injection (DI)
Prefer constructor injection for classes and parameter injection for functions. Avoid importing singletons or global state directly into the middle of business logic modules.
- Useful for testing: allows mocking dependencies.
- Clearer contracts: all dependencies are visible at the entry point.
C. API/Server Route Refactoring
When refactoring routes:
- Dependency Injection: Inject services or stores instead of importing them directly.
- Validation: Use schemas for all request data (query, params, body).
- CRITICAL: String validations must include
.trim()and.max(N)to prevent memory exhaustion. - CRITICAL: Object schemas should use
.strict().
- CRITICAL: String validations must include
- Service Extraction: Move complex business logic to a service layer.
- Middleware: Extract cross-cutting concerns (auth, logging) to middleware.
- Error Handling: Use standardized error formats and centralized error handlers.
D. Client-Side Optimization (React)
When optimizing UI components:
- Memoization: Use
useMemofor expensive calculations anduseCallbackfor stable event handlers. - Splitting: Break large components into smaller, single-purpose sub-components.
- Hooks: Extract logic into custom hooks to keep view components clean and focused.
3. Execution Workflow
To apply this skill:
- Analyze & Plan:
- Read the code and analyze it against the Analysis Framework (Section 1).
- Create a refactoring log (e.g.,
docs/refactoring/[filename]_log.md). - Document findings, violations, and a step-by-step refactoring plan with a checklist.
- Backup/Safety: Ensure you have a way to roll back. Using git or creating a
-legacyvariant is recommended for significant manual refactors. - Refactor (Iterative):
- Execute the next step(s) from the plan.
- Follow the extraction order (constants -> pure functions -> state -> etc.).
- Apply changes incrementally.
- Update Log:
- After completing a step, update the refactoring log.
- Mark completed items and note any deviations.
- Verify:
- Check for type errors (
tsc). - Ensure tests pass (if available).
- Verify the logic remains consistent with the original implementation.
- Check for type errors (
4. Common Technical Pitfalls
| Bug Pattern | Example | Fix |
| Regex double-escaping | [^\\w\\s] in regex literal | Use [^\w\s] |
| Duplicate singletons | Multiple files instantiating the same store | Initialize once at entry point, inject elsewhere |
| Stale closure state | Accessing local variables after async gaps | Use a unified state object or refs |
| Unguarded network calls | Sending to closed connections/sockets | Always check connection state before sending |
| Missing input limits | Accepting unbound strings in API | Always use .max() and .trim() in validations |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

