English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Claude Code code-simplifier: An Agent for Cleaning Up AI-Generated Code Noise

Forum topic · 小凯 · 2026-05-19

Summary

code-simplifier is an open-source Agent originally built for internal use by Anthropic's Claude Code team (released late 2025). Powered by Claude Opus, it targets structural noise that accumulates in code produced across many AI iterations: redundant logic, inconsistent naming, deep nesting, and stale comments. Its governing rule is that it only changes how code is written, never what it does. The article explains why AI output grows uglier over long sessions (over-defensive patterns and iteratively stacked nested conditionals), then walks through the Agent's workflow: it reads project CLAUDE.md conventions, iteratively refactors file-by-file, and verifies functional equivalence. Three before/after TypeScript examples demonstrate flattening nested ternaries, replacing defensive guards with early-return type guards, and unifying naming styles. The piece also covers pre-commit and CI/CD integration, known naming-collision bugs (GitHub issues #36002 and #19889), community ports for Laravel/PHP and Rust, comparisons with ESLint, Prettier, and Copilot, and recommended usage scenarios.

Overview

code-simplifier is an open-source code-simplification Agent that Anthropic's Claude Code team originally used internally, with public release in late 2025. It runs on Claude Opus and targets one specific problem: AI-generated code accumulates structural noise across repeated iterations, including redundant logic, inconsistent naming, excessive nesting, and stale comments. The Agent only changes how code is written, never what it does, acting like a precision surgical tool that trims AI's over-defensive habits back to human-readable aesthetics.

Key points

  • The diagnosis: why AI code gets uglier over time
  • *Over-defense*: AI leans "safety-first" and produces stacked null/undefined/typeof checks before reaching real logic, where a human would rely on a single type guard and early return.
  • *Nested-condition stacking ("hadouken")*: each new turn adds a branch on top of existing nested ternaries, producing unreadable pyramids (active → verified → suspended).
  • *Sources of structural noise*: redundant logic, inconsistent naming (camelCase/snake_case/abbreviations mixed in one file), stale comments, over-abstraction (3-line logic wrapped in 3 helpers), and nesting hell.
  • What code-simplifier is
  • Official Claude Code plugin/Agent from Anthropic, open-sourced late 2025 / early 2026.
  • Backed by Claude Opus for strongest reasoning.
  • Core rule: only the writing changes, never the behavior.
  • Install via claude plugin install code-simplifier.
  • What it changes vs. preserves
  • Changes: redundant code, inconsistent naming within a file/function, unnecessary complexity, stale comments, and inefficient patterns when cheaper equivalents exist.
  • Preserves: I/O contracts, return values, side effects, edge cases, valuable doc comments.
  • How the Agent works
  • 1. User invokes /simplify or asks to run code-simplifier. 2. Claude Code launches the Agent on Opus. 3. Agent reads CLAUDE.md for project coding standards. 4. Agent analyzes recent edits (default scope) and identifies improvements for elegance and consistency. 5. Iterates file-by-file, focusing on one issue at a time. 6. Verifies functional equivalence. 7. Outputs simplified code plus a change summary.
  • Core prompt emphasizes: *"Prioritize readable, explicit code over overly compact solutions."*
  • The Agent is not a fixed rule set; it adapts to each project's conventions in CLAUDE.md.
  • Practical refactoring examples (TypeScript)
  • *Nested ternaries → flat switch/if*: a 4-level ternary computing user status becomes a named getUserStatus function with early returns, preserving every status path.
  • *Over-defensive guards → type guard + early return*: a 30-line validator shell collapses into a single isValidOrder call, letting real business logic start on line 3 instead of line 30.
  • *Mixed naming styles → consistent camelCase verbs*: fetch_user_data, getUserProfile, loadUserOrders become fetchUserData, fetchUserProfile, fetchUserOrders.
  • Automation: pre-commit hook and CI/CD
  • Pre-commit hook lists staged files matching .(ts|tsx|js|jsx|py|go|rs)$, runs claude agent code-simplifier:code-simplifier --files "$STAGED_FILES", then re-stages any modifications.
  • GitHub Actions workflow runs the plugin on pull requests and fails the check if git diff is non-empty, forcing contributors to simplify locally first.
  • Known issues and ecosystem
  • GitHub issue #36002: plugin name and Agent name both code-simplifier, so the fully qualified name is code-simplifier:code-simplifier; /simplify fails to resolve via short name.
  • Workaround: invoke with the full qualified name.
  • GitHub issue #19889: the Agent is incorrectly listed under the Skill tool and returns "Unknown skill" when invoked there; it must be called via the Task tool.
  • Community ports: a Laravel/PHP version (by Taylor Otwell) aware of Laravel conventions, and a Rust version from the MCP marketplace that handles ownership patterns and idiomatic code.
  • Install Laravel port: /plugin marketplace add laravel/claude-code then /plugin install laravel-simplifier@laravel.
  • Positioning vs. other tools
  • ESLint/Prettier: static rule-based formatting; no AI.
  • Claude Code itself: conversational, may change functionality.
  • GitHub Copilot: inline completion, generates new functionality.
  • code-simplifier: the only tool dedicated to cleaning structural noise from AI-generated code, using a stronger reasoning model (Opus) to audit weaker-AI output aesthetics.
  • Usage guidance
  • Recommended: cleanup after long sessions (e.g., 2 hours), before opening a PR, when inheriting AI-generated code, and before code review.
  • Not recommended: emergency hotfixes, performance-tuned algorithms, code without test coverage, throwaway scripts.
  • Best practice: install the plugin, write a CLAUDE.md defining function patterns (top-level function keyword, avoid nested ternaries, prefer early returns) and naming (camelCase verbs + nouns), commit a WIP backup before running, then review git diff after simplification.
  • Reference links
  • GitHub issues: #36002 (name collision), #19889 (Skill/Agent confusion)
  • Claude Code plugin docs: https://code.claude.com/docs/en/plugins
  • Official plugin repo: anthropics/claude-plugins-official
  • aiproductivity.ai pre-commit guide
  • claudecn.com Chinese community docs

Tags

#claude-code#code-simplifier#anthropic#ai-coding#code-refactoring#agent#developer-tools#code-quality

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177620435