---
title: "Refactoring Prompt"
description: "Structured prompt for safe refactoring with Claude Code"
type: "prompt"
category: "atomic"
tags: ["claude-code", "prompt", "refactoring"]
url: "https://theglitch.ai/academy/prompts/refactoring-prompt"
---

# Refactoring Prompt

Structured prompt for safe refactoring with Claude Code

## The Prompt

```
Refactor [file/module/function] to [goal].

Current issues:
- [Issue 1]
- [Issue 2]

Constraints:
- Don't change external API/interface
- Maintain test coverage
- Keep existing behavior
- [Additional constraint]

When done:
- Run tests to verify behavior unchanged
- Run lint
```


# Refactoring Prompt

```
Refactor [file/module/function] to [goal].

Current issues:
- [Issue 1]
- [Issue 2]

Constraints:
- Don't change external API/interface
- Maintain test coverage
- Keep existing behavior
- [Additional constraint]

When done:
- Run tests to verify behavior unchanged
- Run lint
```

---

**Example:**

```
Refactor /src/services/order.ts to reduce complexity.

Current issues:
- processOrder function is 200 lines
- Nested if statements 5 levels deep
- Duplicate validation logic
- Hard to test individual steps

Constraints:
- Don't change OrderService public methods
- Maintain test coverage (all 23 tests must pass)
- Keep existing behavior exactly
- Don't add new dependencies

When done:
- Run tests to verify behavior unchanged
- Run lint
```

---

**Key:** Explicit constraints prevent unintended changes.

