code-simplification
Skill này làm gì
Công cụ này giúp code dễ đọc và dễ hiểu hơn. Nó cải thiện độ rõ ràng mà không làm thay đổi những gì code làm.
Khi nào nên dùng
- ✓Khi code chạy được nhưng khó đọc.
- ✓Khi bạn rà soát code có độ phức tạp quá mức.
- ✓Khi gặp logic rất phức tạp hoặc tên biến không rõ nghĩa.
Liên kết skill
https://github.com/addyosmani/agent-skills/blob/main/skills/code-simplification/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Đơn giản hóa code này để dễ hiểu hơn:”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Công cụ phân tích code và tìm cách làm nó rõ ràng hơn, như dùng tên tốt hơn hoặc sắp xếp lại logic. Nó đảm bảo code vẫn hoạt động y hệt như trước.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Code Simplification
Inspired by the Claude Code Simplifier plugin. Adapted here as a model-agnostic, process-driven skill for any AI coding agent.
Overview
Simplify code by reducing complexity while preserving exact behavior. The goal is not fewer lines — it's code that is easier to read, understand, modify, and debug. Every simplification must pass a simple test: "Would a new team member understand this faster than the original?"
When to Use
- After a feature is working and tests pass, but the implementation feels heavier than it needs to be
- During code review when readability or complexity issues are flagged
- When you encounter deeply nested logic, long functions, or unclear names
- When refactoring code written under time pressure
- When consolidating related logic scattered across files
- After merging changes that introduced duplication or inconsistency
When NOT to use:
- Code is already clean and readable — don't simplify for the sake of it
- You don't understand what the code does yet — comprehend before you simplify
- The code is performance-critical and the "simpler" version would be measurably slower
- You're about to rewrite the module entirely — simplifying throwaway code wastes effort
The Five Principles
1. Preserve Behavior Exactly
Don't change what the code does — only how it expresses it. All inputs, outputs, side effects, error behavior, and edge cases must remain identical. If you're not sure a simplification preserves behavior, don't make it.
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. Follow Project Conventions
Simplification means making code more consistent with the codebase, not imposing external preferences. Before simplifying:
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
Simplification that breaks project consistency is not simplification — it's churn.
3. Prefer Clarity Over Cleverness
Explicit code is better than compact code when the compact version requires a mental pause to parse.
// 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);
}
4. Maintain Balance
Simplification has a failure mode: over-simplification. Watch for these traps:
- Inlining too aggressively — removing a helper that gave a concept a name makes the call site harder to read
- Combining unrelated logic — two simple functions merged into one complex function is not simpler
- Removing "unnecessary" abstraction — some abstractions exist for extensibility or testability, not complexity
- Optimizing for line count — fewer lines is not the goal; easier comprehension is
5. Scope to What Changed
Default to simplifying recently modified code. Avoid drive-by refactors of unrelated code unless explicitly asked to broaden scope. Unscoped simplification creates noise in diffs and risks unintended regressions.
The Simplification Process
Step 1: Understand Before Touching (Chesterton's Fence)
Before changing or removing anything, understand why it exists. This is Chesterton's Fence: if you see a fence across a road and don't understand why it's there, don't tear it down. First understand the reason, then decide if the reason still applies.
BEFORE SIMPLIFYING, ANSWER:
- What is this code's responsibility?
…
Câu hỏi thường gặp
Điều này có làm thay đổi cách code hoạt động không?
Không, mục tiêu chỉ là cải thiện độ rõ ràng. Code sẽ làm đúng những việc như trước.
Tôi có cần biết lập trình để dùng không?
Nên có kiến thức lập trình cơ bản để hiểu code làm gì, nhưng công cụ được thiết kế để đơn giản hóa, giúp việc này dễ tiếp cận hơn.
Tôi có thể dùng để làm code ngắn hơn không?
Trọng tâm chính là sự rõ ràng và dễ hiểu, không nhất thiết là giảm số dòng code. Đôi khi code dài hơn lại dễ đọc hơn.
Chi tiết
Mô tả gốc của tác giả
Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.
repo: addyosmani/agent-skills
Độ phổ biến
- Sao GitHub
- 107k
- Vị trí xếp hạng
- #765
- Giấy phép
- MIT
- Cập nhật
- 13/10/2026
Bình luận
- …
Thêm skill từ kho mã này
api-and-interface-design
107kGiúp tạo các API và giao diện được định nghĩa rõ ràng. Hữu ích khi thiết kế cách các phần của phần mềm giao tiếp với nhau.
browser-testing-with-devtools
107kGiúp agent kiểm thử code trực tiếp trên trình duyệt thật. Hữu ích để kiểm tra cách hoạt động trong môi trường thực tế, tìm lỗi và vấn đề hiệu suất.
ci-cd-and-automation
107kDạy agent AI của bạn tự động hóa các việc lặp lại, đưa dự án đi triển khai và quản lý hạ tầng.
code-review-and-quality
107kThực hiện rà soát code chi tiết trên nhiều khía cạnh. Hữu ích trước khi gộp thay đổi mới để đảm bảo chất lượng và ngăn vấn đề sau này.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.