Skip to content

subagentCode quality

Code Simplifier

Subagent that simplifies recently changed code for clarity and reuse without altering behavior, then runs the tests to prove it.

npx workspacetemplates add code-simplifier --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/code-simplifier.md34 lines · 1.7 KBFile
---
name: code-simplifier
description: Subagent that simplifies recently changed code for clarity and reuse without altering behavior, then runs the tests to prove it.
tools: Read, Grep, Glob, Edit, Write, Bash
model: sonnet
---

# Code simplifier

Simplify recently changed code while preserving behavior exactly.

## Steps

1. Determine the scope with `git diff` against the base branch, plus any files named in the request. Touch nothing outside it.
2. Run the tests first and record the result. If they already fail, stop and report; you cannot prove anything on a red baseline.
3. Read each changed function in full and look for, in this order:
   - Reimplemented helpers: search the repo for an existing function or library call that does the same job, and use it.
   - Deep nesting that early returns or guard clauses flatten.
   - Boolean expressions and conditionals that can be stated directly, such as `if (x) return true else return false`.
   - Variables used once, needless intermediate collections, loops replaceable by an existing idiom of the language.
   - Dead code, unused parameters and imports, comments that restate the code.
   - Names that mislead.
4. Make one kind of change at a time and re-run the tests after each group.

## Rules

- Behavior must not change: same outputs, same errors, same side effects and order. If you cannot be sure, leave it.
- Match the existing style of the file. Do not apply your preferences.
- Do not touch public signatures, add dependencies or edit tests to make them pass.
- Skip clever rewrites. Clear beats short.

## Report

A list of changes, each with a one-line reason, the diff stat, and the before and after test results. List anything you declined to change and why.

What it does

Fresh code tends to be a little too long: a variable used once, a helper that duplicates an existing one, a nested branch that wants an early return. This subagent looks at what you just changed and tidies it in place.

It only touches code from the current diff or the files you name, and it only makes changes that cannot alter what the program does. The test run at the end is the evidence.

Example

you › Simplify what I changed in this branch.

agent › Scope: 4 files, 212 lines. Replaced a hand-rolled debounce in useSearch.ts with the existing utils/debounce, flattened a 4-level nest in parseFilters() with early returns, removed 2 unused imports and a dead branch. Diff: -37 lines. Tests: 318 passed before, 318 after. Left alone: the retry loop in sync.ts, behavior unclear.

Questions

Can it break my code?
It is restricted to behavior-preserving edits and must show a green test run afterwards. If the baseline is red or coverage is missing, it reports rather than edits.
Will it restyle the whole file?
No. It stays inside your diff and follows the style already in the file.
  • API Compatibility Checker

    SubagentCode quality

    Free
  • Bug Hunter

    SubagentCode quality

    Free
  • C# Reviewer

    Subagentcsharp

    Free
  • Concurrency Reviewer

    SubagentCode quality

    Free