Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/apexiq/skillsmith/refactoring_patternsnpx skills add ApexIQ/skillsmith --skill refactoring_patternsgit clone --depth 1 https://github.com/ApexIQ/skillsmithWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/apexiq/skillsmith/refactoring_patterns)<a href="https://agentmods.dev/skills/apexiq/skillsmith/refactoring_patterns"><img src="https://agentmods.dev/badge/skills/apexiq/skillsmith/refactoring_patterns.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00027 | $0.00548 |
| Opus 5 | $0.00014 | $0.00274 |
| Sonnet 5 | $0.00005 | $0.00110 |
| Haiku 4.5 | $0.00003 | $0.00055 |
Grade A, and why
refactoring-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
♻️ Refactoring Patterns
Rule: Refactor with tests. No tests = No refactor.
1. When to Refactor
| Signal | Action |
|---|---|
| Same code in 3+ places | Extract to function/component. |
| Function >50 lines | Split into smaller functions. |
| File >500 lines | Split into modules. |
| "I don't understand this" | Add comments, then simplify. |
When NOT to Refactor:
- No tests covering the code.
- Deadline pressure (ship first, refactor later).
- "Just because" - there must be a clear benefit.
2. Common Refactoring Patterns
Extract Function
# Before
def process_email(email):
# 50 lines of validation
# 50 lines of processing
# After
def process_email(email):
validate_email(email)
transform_email(email)
Extract Component (React)
// Before: 200-line component
// After: Split into <EmailList />, <EmailRow />, <EmailActions />
Replace Magic Numbers
# Before
if priority > 7:
# After
HIGH_PRIORITY_THRESHOLD = 7
if priority > HIGH_PRIORITY_THRESHOLD:
Introduce Parameter Object
# Before
def send_email(to, subject, body, cc, bcc, attachments): ...
# After
def send_email(request: SendEmailRequest): ...
3. Safe Refactoring Workflow
- Write tests (if they don't exist).
- Run tests - they should pass.
- Refactor in small steps.
- Run tests after each step.
- Commit when green.
Examples
- Good refactor: Extract
calculatePriority()from a 100-line function. Tests pass before and after. - Bad refactor: "Cleaned up" a file with no tests. Shipped a bug.
Guidelines
- One refactor per commit. Don't mix refactors with features.
- Use IDE refactoring tools (Rename, Extract) - they're safer.
- If refactor is risky, create a feature flag to roll back.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 3d ago First seen · 87 lines · 27 tokens per session scan A 77658d59be41
refactoring-patterns is a skill published in the GitHub repository ApexIQ/skillsmith (5 stars, last pushed 5mo ago), licensed MIT. It adds 27 tokens to every session and 548 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
refactor-agent
Safe, systematic code refactoring — extract functions, reduce complexity, eliminate duplication, improve naming. Use when improving code structure without changing behavior.
agent-discussion-panel
Use when rendering a multi-agent discussion as a TUI panel. Defines terminal panel layout, component architecture, real-time streaming behavior, and integration points for displaying AgentOpinion data with bordered boxes, severity badges, and consensus indicators.
cost-budget
Use when managing AI session costs, setting budget limits, or preventing cost overruns in autonomous workflows like taskMaestro, autopilot, ralph loops, and parallel agent execution. Defines cost tracking protocol, threshold alerts, and auto-pause mechanism.
agent-design
Use when creating new specialist agent definitions for codingbuddy. Covers JSON schema design, expertise definition, system prompt authoring, and differentiation from existing agents.
refactoring
Improve code structure without changing behavior using proven refactoring patterns. Use when cleaning up code, reducing duplication, improving readability, or restructuring modules.
code-refactoring-advisor
Enterprise code refactoring advisor that detects code smells, anti-patterns, and complexity issues with specific refactoring recommendations, test generation, and maintainability metrics.