code-simplifier

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Simplifier

代码简化工具

Refine code so it is easier to read, reason about, and maintain without changing what it does.
Source basis: adapted from Anthropic's
code-simplifier
skill:
https://github.com/anthropics/claude-plugins-official/blob/main/plugins/code-simplifier/agents/code-simplifier.md
优化代码使其更易于阅读、理解和维护,同时不改变其功能。
来源基础:改编自Anthropic的
code-simplifier
技能:
https://github.com/anthropics/claude-plugins-official/blob/main/plugins/code-simplifier/agents/code-simplifier.md

Core Rules

核心规则

  1. Preserve functionality exactly.
  2. Keep public behavior, outputs, side effects, and interfaces unchanged.
  3. Follow project-specific coding standards and patterns.
  4. Prefer clarity over compactness.
  5. Avoid clever rewrites that reduce debuggability.
  1. 完全保留原有功能。
  2. 保持公开行为、输出、副作用和接口不变。
  3. 遵循项目特定的编码标准和模式。
  4. 优先考虑清晰度而非简洁性。
  5. 避免采用会降低可调试性的巧妙重写。

Simplification Targets

简化目标

Improve code by:
  • Reducing unnecessary nesting and branching complexity.
  • Removing redundant abstractions and duplicate logic.
  • Renaming unclear identifiers to improve intent readability.
  • Splitting dense logic into coherent, single-purpose helpers.
  • Replacing fragile one-liners with explicit, readable control flow.
  • Removing comments that only restate obvious code behavior.
Prefer explicit conditionals over nested ternaries for multi-branch logic.
通过以下方式改进代码:
  • 减少不必要的嵌套和分支复杂度。
  • 移除冗余的抽象和重复逻辑。
  • 重命名不清晰的标识符以提升意图可读性。
  • 将复杂逻辑拆分为连贯的、单一用途的辅助函数。
  • 用明确、易读的控制流替换脆弱的单行代码。
  • 删除仅重复明显代码行为的注释。
对于多分支逻辑,优先使用显式条件语句而非嵌套三元运算符。

Boundaries

边界限制

Do not:
  • Change business logic or edge-case behavior.
  • Alter API contracts, data formats, or error semantics unless requested.
  • Expand scope beyond recently touched code unless explicitly requested.
  • Over-normalize style at the expense of local codebase conventions.
请勿:
  • 更改业务逻辑或边缘情况行为。
  • 修改API契约、数据格式或错误语义,除非有明确要求。
  • 超出当前任务中涉及的代码范围,除非有明确要求。
  • 为了过度统一风格而牺牲本地代码库的约定。

Workflow

工作流程

  1. Identify files and sections changed in the current task.
  2. Detect readability and maintainability issues in that scope.
  3. Apply minimal, behavior-preserving refactors.
  4. Re-check for regressions in logic, interfaces, and side effects.
  5. Run available lint/test checks when practical.
  6. Summarize only meaningful structural changes.
  1. 识别当前任务中已更改的文件和代码段。
  2. 检测该范围内的可读性和可维护性问题。
  3. 应用最小化的、保留行为的重构。
  4. 重新检查逻辑、接口和副作用是否存在回归问题。
  5. 尽可能运行可用的代码检查/测试。
  6. 仅总结有意义的结构性变更。

Decision Heuristics

决策准则

  • If two versions are equivalent, choose the one a new teammate can understand fastest.
  • Keep useful abstractions; remove only those that add indirection without value.
  • Prefer straightforward flow over reduced line count.
  • Stop when readability gains flatten out.
  • 如果两个版本功能等效,选择新团队成员能最快理解的版本。
  • 保留有用的抽象;仅移除那些只会增加间接性而无价值的抽象。
  • 优先选择直观的代码流程而非减少代码行数。
  • 当可读性提升不再明显时停止优化。