code-simplification

A code-refactoring guide for making existing code easier to read, understand, maintain, and extend without changing what it does.

In plain words
What is it for?
Use it to simplify deeply nested logic, long functions, unclear names, duplicated changes, or related logic spread across files, especially during code review.
Why use it?
It helps remove unnecessary complexity while preserving outputs, errors, side effects, and edge-case behavior. This makes rushed or tangled code easier to work on safely.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/233i/agent-skills/code-simplification
Any agent
npx skills add 233i/agent-skills --skill code-simplification
Clone the repo
git clone --depth 1 https://github.com/233i/agent-skills

Made for: Claude Code, Codex.

Per session 55 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,345 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00055 $0.03345
Opus 5 $0.00028 $0.01673
Sonnet 5 $0.00011 $0.00669
Haiku 4.5 $0.00006 $0.00334

Measured 2d ago against content hash 0e9382866de7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-simplification scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/code-simplification/SKILL.md · 332 lines

How it starts

The opening of the file, as written. The whole thing — 332 lines — stays where its author put it; the contents beside it link to each section on GitHub.

代码简化

Inspired by the Claude Code Simplifier plugin. Adapted here as a model-agnostic, process-driven skill for any AI coding agent.

概览

通过降低复杂度来简化代码,同时保持行为完全不变。目标不是让代码行数更少,而是让它更容易读、容易理解、容易修改、也更容易调试。每一次简化都应该通过一个简单测试:“一个新加入团队的人,会不会比看原始版本更快看懂它?”

何时使用

  • 功能已经能跑、测试也通过了,但实现比它应该有的样子更重
  • Code review 中指出了可读性或复杂度问题
  • 你碰到深层嵌套逻辑、超长函数或命名不清的代码
  • 你在整理那些赶工写出来的代码
  • 你要把散落在多个文件中的相关逻辑收拢起来
  • 合并一些引入重复或不一致的改动之后

不适用的场景:

  • 代码已经足够干净清晰,不要为了“简化而简化”
  • 你还没真正理解代码在干什么,先看懂再简化
  • 这段代码是性能热点,而“更简单”的写法会带来可测量的性能损失
  • 你马上就要彻底重写这个模块,对废弃代码做简化是在浪费精力

五个原则

1. 精确保留行为

不要改变代码做的事情,只改变它的表达方式。所有输入、输出、副作用、错误行为和边界情况都必须保持一致。如果你不确定某次“简化”是否保留行为,就不要做。

ASK BEFORE EVERY CHANGE:
→ Does this produce the same output for every input?
→ Does this maintain the same error behavior?
→ Does this preserve the same side effects and ordering?
→ Do all existing tests still pass without modification?

2. 遵守项目约定

简化代码,意味着让它更贴近当前代码库,而不是把你自己的偏好强行带进来。开始简化前:

1. Read CLAUDE.md / project conventions
2. Study how neighboring code handles similar patterns
3. Match the project's style for:
   - Import ordering and module system
   - Function declaration style
   - Naming conventions
   - Error handling patterns
   - Type annotation depth

如果所谓“简化”打破了代码库一致性,那它不是简化,而是无意义扰动。

3. 清晰优先于聪明

当紧凑写法需要人停下来想一下时,显式代码通常更好。

// UNCLEAR: Dense ternary chain
const label = isNew ? 'New' : isUpdated ? 'Updated' : isArchived ? 'Archived' : 'Active';

// CLEAR: Readable mapping
function getStatusLabel(item: Item): string {
  if (item.isNew) return 'New';
  if (item.isUpdated) return 'Updated';
  if (item.isArchived) return 'Archived';
  return 'Active';
}
// UNCLEAR: Chained reduces with inline logic
const result = items.reduce((acc, item) => ({
  ...acc,
  [item.id]: { ...acc[item.id], count: (acc[item.id]?.count ?? 0) + 1 }
}), {});

// CLEAR: Named intermediate step
const countById = new Map<string, number>();
for (const item of items) {
  countById.set(item.id, (countById.get(item.id) ?? 0) + 1);
}

Read the full file on GitHub · 332 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 332 lines · 55 tokens per session scan A 0e9382866de7

Subscribe to this mod's changes

code-simplification is a skill published in the GitHub repository 233i/agent-skills (6 stars, last pushed 4mo ago), licensed MIT. It adds 55 tokens to every session and 3,345 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

obra/superpowers · 37 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

agent-host-chat-contributions

Build and review cross-cutting agent-host chat behavior through lifecycle contributions. Use when adding turn lifecycle side effects, prompt or context injection, restored-history transformation, protocol-action observation, or when reviewing changes that add code to AgentSideEffects or AgentService.

microsoft/vscode · 56 tokens

auto-perf-optimize

Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.

microsoft/vscode · 62 tokens