simplify-code
Skill này làm gì
Skill này giúp AI của bạn tìm và loại bỏ độ phức tạp không cần thiết trong mã. Dành cho lập trình viên có mã trở nên khó đọc hoặc khó bảo trì.
Khi nào nên dùng
- ✓Khi một codebase có các lớp bọc hoặc trừu tượng làm rất ít việc.
- ✓Khi bạn thấy mã chết, import không dùng hoặc logic lồng nhau sâu khó theo dõi.
- ✓Khi bạn muốn mã dễ đọc hơn nhưng vẫn giữ nguyên hành vi.
Liên kết skill
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/simplify-code/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 module này. Xóa mọi thứ không dùng và làm phẳng logic lồng nhau sâu, nhưng giữ nguyên hành vi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill kiểm tra mã theo danh sách các vấn đề phức tạp thường gặp. Sau đó nó xóa hoặc làm phẳng những gì không cần, và giữ nguyên hành vi.
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.
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?"
Câu hỏi thường gặp
Đơn giản hóa có làm thay đổi cách mã chạy không?
Skill được thiết kế để giữ nguyên hành vi, và nó kiểm tra test trước khi xóa nhánh nào.
Mã chết là gì?
Import không dùng, biến và hàm không dùng, nhánh không thể chạy tới và đoạn mã cũ bị comment.
Nó có xóa feature flag không?
Nó gợi ý xóa flag của các tính năng đã ra mắt, nhưng giữ lại phần mã.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 8.2k
- Vị trí xếp hạng
- #12539
- Giấy phép
- MIT
- Cập nhật
- 18/10/2026
Bình luận
- …
Thêm skill từ kho mã này
batch-operations
8.2kGiúp agent của bạn thực hiện cùng một thay đổi trên nhiều file cùng lúc, như đổi tên một hàm hoặc thay một import cũ ở khắp nơi.
brainstorming
8.2kDạy agent của bạn đặt câu hỏi làm rõ trước khi xây dựng bất cứ thứ gì mới hoặc phức tạp, để agent hiểu mục tiêu của bạn trước.
code-review-checklist
8.2kCung cấp cho agent của bạn một danh sách kiểm tra để rà soát mã về tính đúng đắn, bảo mật, hiệu năng, kiểm thử và tài liệu, kể cả rủi ro riêng của AI.
code-review-graph
8.2kGiúp agent của bạn rà soát mã trong dự án lớn bằng một bản đồ cấu trúc, để nó chỉ đọc các file bị ảnh hưởng bởi một thay đổi.
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á.