Coding prompts · Prompt

Turn a messy diff into clean code (prompt)

turn-messy-diff-into-clean-code-prompt

A prompt that simplifies the code you just changed - same behaviour, clearer and consistent with the project, by flattening nesting, removing needless layers and comments, and using plain names. Use when the user wants to simplify or clean up code after a feature or an AI edit, tidy a diff before a pull request, or make freshly written code readable.

Works with: Any AI Not yet model-tested; testing Jan 2027

Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works

Install in Claude Code, Cursor or Codex (optional)

Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.

Claude Code (all your projects)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/raw' -o ~/'.claude/skills/turn-messy-diff-into-clean-code-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/files/LICENSE.txt' -o ~/'.claude/skills/turn-messy-diff-into-clean-code-prompt/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/files/NOTICE.txt' -o ~/'.claude/skills/turn-messy-diff-into-clean-code-prompt/NOTICE.txt'

Cursor (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/raw' -o '.cursor/skills/turn-messy-diff-into-clean-code-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/files/LICENSE.txt' -o '.cursor/skills/turn-messy-diff-into-clean-code-prompt/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/files/NOTICE.txt' -o '.cursor/skills/turn-messy-diff-into-clean-code-prompt/NOTICE.txt'

Codex and other Agent Skills tools (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/raw' -o '.agents/skills/turn-messy-diff-into-clean-code-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/files/LICENSE.txt' -o '.agents/skills/turn-messy-diff-into-clean-code-prompt/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/turn-messy-diff-into-clean-code-prompt/files/NOTICE.txt' -o '.agents/skills/turn-messy-diff-into-clean-code-prompt/NOTICE.txt'

Or connect the whole library over MCP

Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):

{
  "mcpServers": {
    "theskillvault": {
      "url": "https://theskillvault.ai/mcp"
    }
  }
}

Fresh code, especially AI-written code, often works but reads badly. This prompt runs a short tidy-up over only what changed, so the diff gets easier to review and nothing else moves.

When to use

  • You just finished a feature and the diff feels messy.
  • An AI agent wrote code that works but is hard to follow.
  • You want to polish a branch before asking for review.

When not to use

  • The code is old and tangled and needs restructuring. Use fix-code-smells-prompt.
  • You want bugs found. Use review-code-prompt.

Steps

  1. Make sure your tests pass and your work is committed.
  2. Paste the prompt below into your AI coding tool in the same repo.
  3. Read its list of proposed edits and drop any you disagree with.
  4. Let it apply the rest, then run the tests and read the diff.
  5. Commit the tidy-up separately from the feature, so reviewers can skip it.

Prompt

Simplify the code I changed recently. Scope: only the lines in `git diff main...HEAD` (plus uncommitted changes). Do not touch other code unless I ask.

Goal: same behaviour, easier to read, consistent with this project's existing style (look at nearby files, lint config and any AGENTS.md or contributing notes).

Look for:
- Deep nesting that guard clauses or early returns would flatten.
- Nested ternaries or dense one-liners; prefer if/else, a switch or named steps.
- Helpers, wrappers or layers used once that add nothing; inline them.
- Duplicate logic inside the diff; merge it.
- Vague names (data, tmp, handle2); rename to what they hold or do.
- Comments that repeat the code; delete them. Keep comments that explain why.
- Leftovers: debug logs, unused imports, commented-out code, unused variables.

Do not:
- Change public function signatures, outputs, error messages or side effects.
- Trade clarity for fewer lines, or merge unrelated concerns into one function.
- Remove an abstraction other code depends on.

First list each proposed edit with file and line and a one-line reason. Wait for my OK. Then apply them, run the tests and show the final diff.

How to adapt

  • Not on git? Name the files or functions instead of the diff.
  • Strict house style? Paste the key rules (naming, function style, imports) into the "consistent with" line.
  • Large diff? Run it per folder so each change list stays short.

Example of one edit

// Before: clever but hard to scan
const label = n === 0 ? "none" : n === 1 ? "one item" : n < 10 ? "a few" : "many";

// After: same results, easy to extend
function countLabel(n: number): string {
  if (n === 0) return "none";
  if (n === 1) return "one item";
  if (n < 10) return "a few";
  return "many";
}

Gotchas

  • "Simplifying" can quietly change behaviour, such as error text, ordering or null handling. Run the tests after every batch.
  • The AI may want to restyle the whole file. Hold it to the diff.
  • Do not paste secrets, tokens or private customer data into the chat while reviewing logs or config.

Portability

Works with any language, any git host and any AI coding tool or chat AI. If you use another version control tool, replace the git diff line with its equivalent.

Done when

  • Tests pass and behaviour is unchanged.
  • Every edit is inside the recent diff and matches the project's style.
  • The tidy-up sits in its own commit, separate from the feature.

Example prompt

"Simplify what I changed on this branch. Keep behaviour identical, match our style and show me the list of edits before applying them."

---

Modified from "code-simplifier" in getsentry/skills (Apache-2.0, Copyright 2025 Functional Software, Inc. dba Sentry), which is based on Anthropic's code-simplifier agent in anthropics/claude-plugins-official (Apache-2.0). Original: https://github.com/getsentry/skills/blob/d12f250460ffd961f549dbebf7eeb0cf4afd4c2e/skills/code-simplifier/SKILL.md. Changes by TheSkillVault are listed in the metadata above and in NOTICE.txt. See LICENSE.txt.

Bundled files

Licence

Adapted from David Cramer (Sentry, getsentry/skills code-simplifier), based on Anthropic's code-simplifier agent (Copyright 2025 Functional Software, Inc. dba Sentry; based on Anthropic's code-simplifier agent (anthropics/claude-plugins-official, Apache-2.0). Apache License 2.0 text in LICENSE.txt, attributions in NOTICE.txt), Apache License 2.0. Modified by TheSkillVault on 2026-11-02: rewritten as a copy-paste prompt with a scope rule, a behaviour-check loop and original examples; the role-play framing and project-specific style list were removed; added steps, adapt notes, gotchas and done-when. Not the original file.

Licence: Apache License 2.0. Attribution when you reuse it: Based on work by David Cramer (Sentry, getsentry/skills code-simplifier), based on Anthropic's code-simplifier agent (Copyright 2025 Functional Software, Inc. dba Sentry; based on Anthropic's code-simplifier agent (anthropics/claude-plugins-official, Apache-2.0). Apache License 2.0 text in LICENSE.txt, attributions in NOTICE.txt, Apache License 2.0), https://github.com/getsentry/skills/tree/d12f250460ffd961f549dbebf7eeb0cf4afd4c2e/skills/code-simplifier; adapted by TheSkillVault, https://theskillvault.ai