agentleFS
UIhoshiUIhoshi/AgentLogic/skills/engineering/code-simplifier/SKILL.md

code-simplifier

Skill0 starsChanged 6 days agoMITView on GitHub

Autonomous post-implementation code refinement, AST-aware structural refactoring, and 80/20 code-smell cleanup without altering behavior. Triggered automatically after feature/refactor implementation or when simplifying, cleaning up, or refactoring code.

61 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use tdd-rust, comment-analyzer and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • FlorianBruniauxSkill

    tdd-rust

    Also in 3 projects that use this

  • PaulKinlanSkill

    comment-analyzer

    Analyzes code comments for accuracy, completeness, and long-term maintainability. Identifies misleading comments, comment rot, and documentation gaps.

    Also in 4 projects that use this

  • PaulKinlanSkill

    type-design-analyzer

    Analyzes type design quality focusing on encapsulation, invariant expression, usefulness, and enforcement. Provides quantitative ratings (1-10) for each dimension.

    Also in 3 projects that use this

  • ufodev-ioSkill

    security-guardian

    Comprehensive security layer for all interactions with Claude: audits code, dependencies, commands, configs, and AI-generated output for vulnerabilities. Protects against prompt injection, data leaks, unsafe advice, and social engineering. Works in Cursor, Claude Code, claude.ai, and API contexts. Use always as a background security protocol in any Claude-powered environment.

    Also in 3 projects that use this

  • SentrySkill

    find-bugs

    Find bugs, security vulnerabilities, and code quality issues in local branch changes. Use when asked to review changes, find bugs, security review, or audit code on the current branch.

    Also in 3 projects that use this

  • GitHubSkill

    pr-triage

    Triage open pull requests in github/explore, producing a status table with CI results and merge recommendations. Use when asked to review, triage, or summarize open PRs in this repository.

    Also in 3 projects that use this

  • +1 more from PaulKinlan

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 5 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 57 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do NOT wait for the user to type /code-simplifier or name this skill.

    line 12
  2. Distinctive:

    Never simplify or refactor against a broken baseline.

    line 24
  3. Distinctive:

    Verify that the relevant test, typecheck, or build command passes before structural refinement begins.

    line 25
  4. Very specific:

    Read CONTEXT.md (if present), CODE_MAP.md, and local conventions so naming and module boundaries match the repository's established …

    line 26
  5. Distinctive:

    When applying the refinements identified in Phase 2:

    line 43
  6. Very specific:

    Check whether ast-grep (sg) is available on the host (Get-Command sg -ErrorAction SilentlyContinue or ast-grep).

    line 46
  7. Very specific:

    When sg is available and a structural pattern is being rewritten across multiple locations, use sg run --pattern '<pattern>' --rewrite …

    line 47
  8. Very specific:

    When ast-grep is unavailable or the refinement is local to 1–2 hunks, apply bounded file edits one cohesive transformation at a time.

    line 49
  9. Very specific:

    Preserve Documentation & Shortcut Ledger Integrity: Never delete unrelated comments, docstrings, shortcut: <limit>, <when to upgrade> (or …

    line 50
  10. Distinctive:

    Balance Clarity over Brevity: Do not compress readable 4-line logic into an unreadable 1-line clever expression.

    line 51
  11. Distinctive:

    If any test or check breaks, revert the offending simplification hunk immediately rather than piling on workarounds.

    line 56
  12. Very specific:

    Update CODE_MAP.md if any public symbol, signature, or key flow path changed during the refactor.

    line 57

“Common” is measured: kept by at least 6 in 10 of the 57 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Simplifier & AST-Aware Refactoring (code-simplifier)

This skill refines and simplifies newly written or modified code for clarity, consistency, and maintainability without changing external behavior. It synthesizes patterns from Anthropic's official code-simplifier (anthropics/claude-plugins-official), ast-grep structural refactoring (ast-grep/ast-grep), obra/superpowers v7.0.2 Red-Green-Refactor & verification-before-completion discipline, and DietrichGebert/ponytail (pre-implementation YAGNI subtraction & shortcut: debt ledger), complementing improve-codebase-architecture (macro module deepening).

Automatic Trigger Contract (Encounter -> Auto-Use)

Do NOT wait for the user to type /code-simplifier or name this skill. Activate this workflow automatically whenever:

  1. Post-Implementation Polish: You have just implemented a feature, major_feature, or refactor and the initial behavior/tests pass, before claiming final completion or entering code-review.
  2. Refactoring / Cleanup Request: The user asks to improve, clean up, polish, deduplicate, simplify, or refactor existing code.
  3. Multi-Site Structural Change: A rename, API migration, or pattern rewrite spans >= 3 call sites or multiple files.

The 4-Phase Refinement Loop

Phase 1: Green Baseline Lock (Pre-Condition)

  • Never simplify or refactor against a broken baseline.
  • Verify that the relevant test, typecheck, or build command passes before structural refinement begins.
  • Read CONTEXT.md (if present), CODE_MAP.md, and local conventions so naming and module boundaries match the repository's established standards.

Phase 2: 80/20 Smell & AI-Slop Triage

Scan only the recently modified hunks or explicitly targeted files (never perform unrequested repo-wide formatting churn). Rank and target the highest-leverage improvements:

Smell / Slop CategoryWhat to SpotRequired Refinement
1. Deep Nesting & Arrow Codeif/else/try blocks nested > 3 levels deepInvert conditions and use early returns / guard clauses to flatten control flow.
2. Dense / Nested TernariesNested ternary expressions (a ? (b ? c : d) : e) or long inline boolean chainsReplace with clear if/else statements, switch/match blocks, or named lookup maps.
3. Redundant AI Defensive SlopSpeculative try/catch that swallows errors, duplicate null checks already guaranteed by caller types, single-use wrapper functions, or pass-through middlemenDelete redundant wrappers; keep validation strictly at real trust boundaries (per ponytail Rung 1 & 7).
4. Duplicated Logic ShapesIdentical 5+ line transformation or validation blocks repeated across functions in the diffExtract a single shared helper in the existing module (reuse before inventing new files).
5. Mysterious or Drifting NamesGeneric identifiers (data, res, temp, handleThing, processData2) or terms that drift from CONTEXT.mdRename to explicit domain terms that state what the value holds or what the function returns.
6. Data Clumps & Long Parameter ListsThe same 3+ parameters passed together across multiple functionsGroup into an existing domain struct/type or options object when it clarifies the seam.

Phase 3: AST-First Structural Execution

When applying the refinements identified in Phase 2:

  1. Prefer AST-Aware Rewrites for Multi-Site Patterns (>= 3 sites):
    • Check whether ast-grep (sg) is available on the host (Get-Command sg -ErrorAction SilentlyContinue or ast-grep).
    • When sg is available and a structural pattern is being rewritten across multiple locations, use sg run --pattern '<pattern>' --rewrite '<rewrite>' (with metavariables like $FUNC, $$$ARGS) instead of fragile regex or repetitive manual edits.
  2. Atomic Bounded Edits:
    • When ast-grep is unavailable or the refinement is local to 1–2 hunks, apply bounded file edits one cohesive transformation at a time.
    • Preserve Documentation & Shortcut Ledger Integrity: Never delete unrelated comments, docstrings, shortcut: <limit>, <when to upgrade> (or legacy ponytail:) debt markers, or mandatory logic-gate headers.
    • Balance Clarity over Brevity: Do not compress readable 4-line logic into an unreadable 1-line clever expression; explicit and boring beats dense and clever.

Phase 4: Zero-Behavior-Change Verification & Closure

  1. Re-run the exact test, build, or runtime verification command from Phase 1 immediately after refinement (superpowers verification-before-completion: inspect fresh command output in the current turn before claiming success).
  2. If any test or check breaks, revert the offending simplification hunk immediately rather than piling on workarounds.
  3. Update CODE_MAP.md if any public symbol, signature, or key flow path changed during the refactor.
  4. Record closure evidence (refinement_or_smell_check and behavior_preserved_verification).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.