simplify-code
できること
このスキルは、コードの不要な複雑さを見つけて取り除く手助けをAIにします。コードが読みにくくなった、または保守しにくくなった開発者向けです。
使う場面
- ✓ほとんど何もしないラッパークラスや抽象化があるとき。
- ✓使われていないコード、未使用のimport、または追いにくい深いネストのロジックを見つけたとき。
- ✓動作を変えずに、より読みやすいコードがほしいとき。
スキルのリンク
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/simplify-code/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このモジュールを単純にしてください。使われていないものは削除し、深くネストしたロジックは平らにしてください。ただし動作は同じに保ってください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
スキルは、コードを一般的な複雑さの問題の一覧と照らし合わせて確認します。必要のないものを削除または平らにし、動作は同じに保ちます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Simplify Code — Reduce Unnecessary Complexity
The best code is the code you don't have to write. The second best is the code anyone can read.
Core Principle
Complexity is a cost. Every abstraction, every indirection, every clever pattern
adds cognitive load. Simplify ruthlessly unless complexity serves a clear purpose.
Simplification Checklist
1. Unnecessary Abstractions
| Smell | Simplification |
|---|---|
| Wrapper class that just delegates | Remove wrapper, use the inner class directly |
| Factory that creates only one type | Replace with direct constructor |
| Strategy pattern with one strategy | Replace with simple function |
| Interface with one implementation | Remove interface, use the class |
| Abstract class with one child | Merge into the child class |
| Config object for 2 values | Use function parameters |
2. Dead Code
| Smell | Action |
|---|---|
| Unused imports | Remove |
| Unreachable branches | Remove (check tests first) |
| Commented-out code | Remove (it's in git history) |
| Unused variables/functions | Remove |
| TODO comments older than 6 months | Remove or create issue |
| Feature flags for launched features | Remove flag, keep the code |
3. Deep Nesting
// ❌ Before: 4 levels deep
function process(data) {
if (data) {
if (data.items) {
for (const item of data.items) {
if (item.active) {
doSomething(item)
}
}
}
}
}
// ✅ After: Early returns + filter
function process(data) {
if (!data?.items) return
data.items
.filter(item => item.active)
.forEach(doSomething)
}
4. Over-Parameterized Functions
// ❌ Before: 8 parameters
function createUser(name, email, age, role, dept, active, verified, avatar) { }
// ✅ After: Object parameter
function createUser(opts: CreateUserOpts) { }
5. Premature Optimization
| Smell | Simplification |
|---|---|
| Custom cache for <100 items | Remove cache, measure first |
| Memoization on cheap functions | Remove memo |
| Lazy loading for small modules | Use direct import |
| Complex state machine for 3 states | Use simple if/else or switch |
Simplification Protocol
Step 1: Identify Complexity
- Count nesting levels (target: ≤3)
- Count function parameters (target: ≤4)
- Count lines per function (target: ≤30)
- Count abstractions per feature (target: ≤2)
- Check for dead code (target: 0)
Step 2: Verify Understanding
Before simplifying, ensure you understand:
- What the code does (not what it looks like it does)
- Why it was written this way (maybe there's a reason)
- What tests cover it (simplification must not break tests)
Step 3: Simplify Incrementally
1. Remove dead code first (safest)
2. Flatten nesting with early returns
3. Inline trivial abstractions
4. Merge related functions
5. Simplify data structures
Step 4: Verify Behavior Preserved
npm run test # All existing tests still pass
npm run build # Still compiles
When NOT to Simplify
| Situation | Why Keep Complexity |
|---|---|
| Performance-critical hot path | Optimization may look complex but is necessary |
| Required by framework/library | External constraints |
| Explicitly requested pattern | User chose this architecture |
| Will need extension soon | Abstraction prepares for known growth |
Ask first: "This pattern seems over-engineered. Should I simplify it, or is there a reason for the abstraction?"
よくある質問
単純化するとコードの動きが変わりますか?
スキルは動作を保つように設計されており、分岐を削除する前にテストを確認します。
使われていないコードとは何ですか?
未使用のimport、未使用の変数や関数、到達できない分岐、古いコメントアウトされたコードです。
機能フラグは削除しますか?
すでに公開された機能のフラグは削除を提案しますが、コード自体は残します。
詳細
作者による元の説明
Reduce complexity of over-engineered code. Identify unnecessary abstractions, remove dead code, flatten deep nesting, and simplify logic while preserving behavior.
repo: vudovn/ag-kit
人気
- GitHubのスター
- 8.2k
- ランキング
- #12539
- ライセンス
- MIT
- 更新日
- 2026/10/18
コメント
- …
このリポジトリの他のスキル
batch-operations
8.2k関数の名前変更や古いimportの置き換えなど、同じ変更を多くのファイルに一度に行うよう、エージェントを支援します。
brainstorming
8.2k何か新しいものや複雑なものを作る前に、エージェントが確認の質問をして、まず目標を理解するよう教えます。
code-review-checklist
8.2k正しさ、セキュリティ、性能、テスト、ドキュメントに加え、AI特有のリスクも含めて、コードをレビューするためのチェックリストをエージェントに与えます。
code-review-graph
8.2k大きなプロジェクトでは、構造のマップを使ってコードをレビューし、変更の影響を受けるファイルだけを読むよう、エージェントを支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。