code-change-refactor

A rule set for refactoring existing code, meaning improving its structure without changing what it does. It emphasizes small changes, tests, existing project patterns, and preserved public interfaces.

In plain words
What is it for?
Simplifying code, extracting reusable parts, adopting established patterns, and integrating new functionality while keeping behavior and testability intact.
Why use it?
Large or unfocused refactors can break behavior, APIs, validation, or error handling while making problems harder to trace.

Cursor rule for Cursor

Install

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.

agentmods
npx agentmods add rules/oakensoul/nextjs-cursor-prompts/code-change-refactor
Clone the repo
git clone --depth 1 https://github.com/oakensoul/nextjs-cursor-prompts

Made for: Cursor.

Per session 23 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,997 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5 $0.00023 $0.01997
Opus 5 $0.00012 $0.00999
Sonnet 5 $0.00005 $0.00399
Haiku 4.5 $0.00002 $0.00200

Measured 2d ago against content hash 43f486126f8b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-change-refactor 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.

.cursor/rules/code-change-refactor.mdc · 217 lines

How it starts

The opening of the file, as written. The whole thing — 217 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Code Refactoring Rule

This rule applies when refactoring existing code to improve quality, adopt new patterns, or integrate with newly created functionality.

🎯 REFACTORING PRINCIPLES:

  1. PRESERVE FUNCTIONALITY - External behavior must remain identical
  2. IMPROVE INCREMENTALLY - Make steady, measurable improvements
  3. MAINTAIN TESTABILITY - Keep or improve test coverage
  4. FOLLOW EXISTING PATTERNS - Adopt established project conventions
  5. REDUCE COMPLEXITY - Simplify without breaking existing contracts

🚫 FORBIDDEN ACTIONS:

  1. DO NOT change external APIs or public interfaces without explicit approval
  2. DO NOT break existing functionality or user-facing behavior
  3. DO NOT refactor without tests - ensure test coverage exists or create it first
  4. DO NOT make massive changes in a single refactoring session
  5. DO NOT introduce new dependencies unless necessary for the improvement
  6. DO NOT refactor multiple concerns simultaneously (separate data flow from UI changes)
  7. DO NOT remove error handling or validation without replacement
  8. DO NOT change business logic while refactoring structure

ENCOURAGED ACTIONS:

  1. EXTRACT reusable components and utilities from duplicated code
  2. CONSOLIDATE similar patterns into consistent implementations
  3. IMPROVE naming to be more descriptive and intention-revealing
  4. ENHANCE error handling and edge case management
  5. OPTIMIZE data flow and state management patterns
  6. STRENGTHEN type safety and validation
  7. SIMPLIFY complex functions by breaking them into smaller, focused units
  8. ADOPT project standards and established patterns

🏗️ BUILT-IN ARCHITECTURAL REQUIREMENTS:

  • Follow NextJS App Router patterns - use app directory structure, proper layouts
  • Maintain server/client boundaries - use 'use client' appropriately, avoid server-side DOM
  • Implement proper error boundaries - handle errors at appropriate component levels
  • Follow established folder structure - components, utils, hooks, types in standard locations
  • Use consistent naming conventions - kebab-case files, PascalCase components

Read the full file on GitHub · 217 lines

Changes

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.

  1. 2d ago First seen · 217 lines · 23 tokens per session scan A 43f486126f8b

Subscribe to this mod's changes

code-change-refactor is a cursor rule published in the GitHub repository oakensoul/nextjs-cursor-prompts (4 stars, last pushed 1y ago), licensed MIT. It adds 23 tokens to every session and 1,997 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.