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 rules/nedcodes-ok/cursor-doctor/refactoringgit clone --depth 1 https://github.com/nedcodes-ok/cursor-doctorWhat 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.00683 | $0.00683 |
| Opus 5 | $0.00342 | $0.00342 |
| Sonnet 5 | $0.00137 | $0.00137 |
| Haiku 4.5 | $0.00068 | $0.00068 |
Grade A, and why
refactoring 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 2d 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.
How it starts
The opening of the file, as written. The whole thing — 80 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Refactoring Cursor Rules
You are an expert in systematic code refactoring. Follow these rules:
Before Refactoring
- Ensure tests exist for the code being refactored — no tests, no refactoring
- Run the full test suite before starting — establish a green baseline
- Commit the current state before making any changes
- Identify the specific code smell you're fixing — don't refactor "just because"
Guard Clauses & Early Returns
- Replace nested if/else with early returns for error cases
- Check preconditions at the top of the function, return/throw early
- Each guard clause should handle one condition — not compound boolean expressions
- After all guards pass, the main logic runs at the base indentation level
// ❌ Nested
function process(user) {
if (user) {
if (user.isActive) {
if (user.hasPermission) {
// actual logic buried 3 levels deep
}
}
}
}
// ✅ Guard clauses
function process(user) {
if (!user) throw new Error('User required');
if (!user.isActive) return;
if (!user.hasPermission) throw new ForbiddenError();
// actual logic at base level
}
Extract Function/Method
- Extract when a code block needs a comment explaining what it does — the function name IS the comment
- Extracted functions should do one thing and be nameable with a verb phrase
- Pass only what the extracted function needs — not the entire context/object
- If you extract and the original function is just a list of calls, that's good — it reads like a plan
Inline
- Inline when a function/variable adds indirection without clarity
- Inline temporary variables that are used once and the expression is clear
- Inline trivial delegating functions that just call another function
Rename
- Rename when the name doesn't match what the code does (after behavior changes)
- Use find-all-references, not find-and-replace — catch all usages including types
- Rename in a separate commit from behavior changes
Simplify Conditionals
- Replace complex boolean expressions with named boolean variables or functions
- Use De Morgan's laws to simplify negated compound conditions
- Replace switch/case with object lookup when mapping values
- Replace type-checking conditionals with polymorphism when the pattern repeats
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.
- 2d ago First seen · 80 lines · 683 tokens per session scan A c5c297793cbe
refactoring is a cursor rule published in the GitHub repository nedcodes-ok/cursor-doctor (9 stars, last pushed 5mo ago), licensed MIT. It adds 683 tokens to every session, about $0.0034 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 cursor rules, from other repositories
java
Modern Java: records, sealed classes, streams, virtual threads.
javascript
Modern JavaScript: ES2023+, async patterns, common traps.
accessibility
Accessibility: semantic HTML, ARIA, keyboard navigation, testing.
cross-tool-config
Cross-tool AI config: what transfers between Cursor, Claude Code, Copilot, Windsurf, Gemini, and Codex.
angular
Angular: signals, standalone components, RxJS patterns.
django
Django: models, views, ORM best practices.