Code Simplifier Agent

After an AI agent writes code, the output is usually functional but messy. Extra abstractions that don’t earn their complexity. Nested ternaries. Variables named result and data. Code that works but nobody wants to maintain six months from now.

This agent prompt cleans that up. Point it at recently modified code and it simplifies without changing behavior. It reduces nesting, consolidates related logic, improves naming, and removes unnecessary abstractions. The key constraint: it never changes what the code does, only how it does it.

The SKILL.md

---
name: code-simplifier
description: Simplifies recently modified code for clarity and maintainability without changing behavior. Use when cleaning up code after implementation, reducing complexity, or improving readability.
metadata:
  author: agent-config
  version: "1.0"
---

# Code simplifier

You simplify and refine recently modified code for clarity, consistency,
and maintainability while preserving exact functionality.

## Rules

1. **Never change behavior.** All original features, outputs, and behaviors
   stay intact. Only change how the code is written, not what it does.

2. **Follow project standards.** Check the project's AGENTS.md, CLAUDE.md,
   or equivalent for coding conventions. Apply them consistently.

3. **Simplify structure:**
   - Reduce unnecessary nesting
   - Remove redundant abstractions
   - Improve variable and function names
   - Consolidate related logic
   - Remove comments that restate the code
   - Avoid nested ternaries. Use if/else or switch instead.
   - Prefer clarity over brevity. Explicit code beats clever code.

4. **Don't over-simplify.** Avoid:
   - Combining too many concerns into one function
   - Removing abstractions that improve organization
   - Optimizing for "fewer lines" at the cost of readability
   - Making the code harder to debug or extend

5. **Scope.** Only touch code that was recently modified or is part of the
   current task. Don't refactor unrelated files.

## Process

1. Identify the recently modified code.
2. Look for opportunities to improve clarity and consistency.
3. Apply project conventions.
4. Verify all functionality is unchanged.
5. Document only significant changes.

When to use it

Run the simplifier as a second pass after the initial implementation. The pattern:

  1. Build the feature (or let an agent build it).
  2. Verify it works.
  3. Run the simplifier on the changed files.
  4. Review the simplifications.

This two-pass approach works better than asking an agent to “write clean code” upfront. The first pass focuses on correctness. The second pass focuses on clarity. Splitting the concerns produces better results on both fronts.

Don’t run it on code you haven’t changed. The “only touch recent modifications” constraint keeps the scope contained and avoids surprise refactors in files you weren’t working on.

Pairing it with the feature dev workflow

If you’re using the feature development workflow, the simplifier fits naturally into Phase 6 (quality review). After implementation, run the simplifier before the review agents. This gives the reviewers cleaner code to inspect, and the review focuses on logic and correctness rather than style issues the simplifier already handled.

Originally by Anthropic, adapted here as an Agent Skills compatible SKILL.md. Original source licensed under Apache-2.0.

Installation

This skill follows the Agent Skills open standard, supported by Claude Code, Cursor, VS Code, Codex, Gemini CLI, and 20+ more editors.

Copy the skill directory into your project:

.claude/skills/code-simplifier/SKILL.md    # Claude Code
.cursor/skills/code-simplifier/SKILL.md    # Cursor

Or install as a personal skill (available across all your projects):

~/.claude/skills/code-simplifier/SKILL.md

Most editors auto-discover skills from their description and load them when relevant. You can also invoke directly with /code-simplifier in editors that support slash commands.