- Published on
Day 13 - Skills tái sử dụng
- Authors

- Name
- Trần Mạnh Thắng
- @TranManhThang96
1. Mục tiêu bài học
Sau khoảng 2 tiếng, học viên có thể:
- Giải thích Skill trong Claude Code là gì và khác gì với prompt dài,
CLAUDE.md, hoặc.claude/commands/*.md. - Nhận biết khi nào nên tạo Skill thay vì tiếp tục copy một prompt dài qua nhiều task.
- Tạo project Skill ở
.claude/skills/<skill-name>/SKILL.md. - Viết
SKILL.mdcó frontmatter rõ, instruction ngắn, output format đoán được, và guardrail phù hợp. - Tạo 2 Skill thực tế cho
taskflow-ai:api-reviewervàtest-writer. - Dùng Skill trong workflow review API, viết test, và cải thiện chất lượng output của Claude Code.
- Kiểm soát rủi ro context bloat, tool permission quá rộng, secret leakage, và Skill bị auto-invoke sai ngữ cảnh.
2. Bối cảnh thực tế
Khi làm taskflow-ai, có nhiều quy trình lặp lại:
- Review endpoint trước khi merge.
- Viết regression test cho bug vừa sửa.
- Kiểm tra auth, authorization, validation, error shape.
- Review UI theo design system và accessibility.
- Refactor nhưng vẫn giữ behavior cũ.
Nếu mỗi lần đều paste một prompt dài, workflow sẽ không ổn định. Người học dễ quên một phần checklist, team prompt mỗi người một kiểu, Claude nhận nhiều nội dung lặp lại và context bị nhiễu. Skill giải quyết vấn đề này bằng cách đóng gói instruction thành một đơn vị tái sử dụng. Claude có thể tự chọn Skill dựa trên description, hoặc người dùng gọi trực tiếp bằng /skill-name.
Ví dụ thay vì paste prompt review API 30 dòng, dùng:
/api-reviewer Review PATCH /api/tasks/:id. Focus on ownership, validation, response contract, and missing tests.
Không nên tạo Skill khi task chỉ làm một lần, checklist chưa ổn định, hoặc instruction chỉ 2-3 dòng. Skill có giá trị nhất khi nó biến một workflow lặp lại thành chuẩn vận hành có thể dùng lại.
3. Kiến thức nền
Skill là một thư mục có file SKILL.md làm entrypoint. Vị trí quyết định phạm vi áp dụng:
~/.claude/skills/<skill-name>/SKILL.md
.claude/skills/<skill-name>/SKILL.md
~/.claude/skills phù hợp với workflow cá nhân dùng trên nhiều repo. .claude/skills phù hợp với project Skill phụ thuộc convention của taskflow-ai và có thể commit cho team.
Một SKILL.md thường có YAML frontmatter và phần instruction:
---
name: api-reviewer
description: Review taskflow-ai backend API routes, controllers, services, schemas, auth middleware, or API tests for validation, auth, response contract, errors, security, tests, rollback risk, and maintainability.
argument-hint: "[endpoint-or-files]"
allowed-tools: Read Grep Glob Bash
---
# API Reviewer
Review API-facing changes. Return findings first, ordered by severity.
Các field quan trọng:
| Field | Ý nghĩa |
|---|---|
name | Tên hiển thị; nếu bỏ qua, Claude dùng tên thư mục |
description | Tín hiệu chính để Claude tự quyết định có dùng Skill không; nên ghi cả khi nào dùng |
when_to_use | Bổ sung điều kiện kích hoạt nếu description đã quá dài |
argument-hint | Gợi ý tham số khi gọi trực tiếp bằng /skill-name |
disable-model-invocation | true nghĩa là chỉ user gọi, Claude không tự kích hoạt |
allowed-tools | Tool được pre-approve khi Skill active; không phải deny-list |
paths | Giới hạn auto-invocation theo glob path, hữu ích trong monorepo hoặc repo nhiều package |
Không tự thêm field frontmatter không có trong tài liệu hiện hành chỉ để mô tả ý tưởng. Nếu cần thu hẹp điều kiện dùng, ưu tiên viết rõ trong description, when_to_use, hoặc paths thay vì nhét thêm instruction mơ hồ vào thân file. Nếu muốn Skill chỉ chạy khi gọi trực tiếp, dùng disable-model-invocation: true.
Điểm cần nhớ: khi Skill được invoke, nội dung render của SKILL.md đi vào conversation và có thể ở lại trong context. Vì vậy, Skill phải ngắn và tập trung. Nội dung dài như checklist security chi tiết, ví dụ output, template test plan nên đặt ở supporting files và chỉ reference khi cần.
4. Step-by-step thực hành
Mục tiêu thực hành: trong taskflow-ai, tạo 2 project Skill:
.claude/skills/api-reviewer/SKILL.md
.claude/skills/test-writer/SKILL.md
Bước 1: Kiểm tra repo và tạo thư mục
Chạy ở root taskflow-ai:
git status --short
Lệnh này kiểm tra working tree. Output kỳ vọng là rỗng hoặc chỉ có file bạn hiểu rõ. Rủi ro: nếu repo đang có thay đổi của người khác, đừng để bài thực hành lẫn vào diff đó.
Tạo thư mục Skill:
mkdir -p .claude/skills/api-reviewer .claude/skills/test-writer
PowerShell:
New-Item -ItemType Directory -Force .claude/skills/api-reviewer, .claude/skills/test-writer
Output kỳ vọng: thư mục được tạo hoặc đã tồn tại.
Bước 2: Tạo Skill api-reviewer
Tạo .claude/skills/api-reviewer/SKILL.md:
---
name: api-reviewer
description: Review taskflow-ai API routes, controllers, services, request or response schemas, auth middleware, database-facing API logic, or API tests for request validation, auth, response contract, error handling, security, tests, rollback risk, and maintainability.
argument-hint: "[endpoint-or-files]"
allowed-tools: Read Grep Glob Bash
---
# API Reviewer
Review API changes in `taskflow-ai` with a production-readiness mindset.
Do not edit files unless the user explicitly asks for fixes.
## Process
1. Identify the changed API surface: route, method, request shape, response shape, auth requirements.
2. Check contract risk: renamed fields, removed fields, changed status codes, inconsistent error format.
3. Check security: missing auth, missing ownership checks, unsafe user input, leaked internal errors, over-broad data exposure.
4. Check maintainability: unclear boundaries, duplicated validation, hidden side effects, weak naming.
5. Check tests: success, validation failure, unauthorized, forbidden, not found, service/database failure.
## Output Format
Return findings first, ordered by severity.
- Severity: Critical | High | Medium | Low
- File:
- Issue:
- Risk:
- Suggested fix:
- Test to add:
If no issues are found, say that clearly and list remaining test gaps or residual risk.
Kiểm tra file:
sed -n '1,120p' .claude/skills/api-reviewer/SKILL.md
PowerShell:
Get-Content .claude/skills/api-reviewer/SKILL.md -TotalCount 120
Output kỳ vọng có frontmatter ---, name: api-reviewer, description, và heading # API Reviewer.
Bước 3: Tạo Skill test-writer
Tạo .claude/skills/test-writer/SKILL.md:
---
name: test-writer
description: Write or improve focused tests for taskflow-ai services, API routes, UI components, hooks, utilities, or bug fixes by preserving existing behavior, following local test patterns, and covering realistic edge cases.
argument-hint: "[code-path-or-behavior]"
allowed-tools: Read Grep Glob Bash Edit
---
# Test Writer
Write tests for `taskflow-ai` that protect behavior without overfitting implementation details.
## Process
1. Inspect nearby tests before writing new tests.
2. Identify the behavior under test.
3. Choose the smallest useful test level: unit, service, API, component, or e2e.
4. Cover happy path, important failure path, and boundary or permission case.
5. Run the narrowest relevant test command first.
6. Report what was covered and what remains untested.
## Rules
- Prefer behavior assertions, clear test names, stable fixtures, and minimal mocking.
- Avoid snapshot-only logic tests, over-mocking, brittle timing assumptions, and generated tests with unclear intent.
- Do not change production behavior just to make a weak test pass.
## Output Format
- Test file path:
- Test cases added or proposed:
- Command run:
- Result:
- Remaining gaps:
Kiểm tra:
sed -n '1,140p' .claude/skills/test-writer/SKILL.md
Bước 4: Gọi Skill trực tiếp
Trong Claude Code:
/api-reviewer Review POST /api/tasks for validation, auth, response contract, and missing tests. Do not edit files.
Output kỳ vọng:
Findings
- Severity: ...
- File: ...
- Issue: ...
- Risk: ...
- Suggested fix: ...
- Test to add: ...
Gọi test-writer:
/test-writer Add focused tests for task creation validation and unauthorized access. Follow existing test patterns.
Output kỳ vọng có test file path, test cases, command, result hoặc proposed command.
Bước 5: Áp dụng vào taskflow-ai
Ví dụ review PATCH /api/tasks/:id:
/api-reviewer Review the current PATCH /api/tasks/:id implementation in taskflow-ai.
Check ownership, validation, partial update behavior, error status codes, response shape, and tests.
Do not edit files. Return findings first.
Sau khi có findings:
/test-writer Based on the API review findings for PATCH /api/tasks/:id, add focused tests.
Follow existing test patterns. Run the narrowest relevant test command and report the exact result.
Command test tham khảo:
npm run test -- tasks
npm test
npm run test:api
Chạy các command này ở root taskflow-ai. npm run test -- tasks nên chỉ chạy nhóm test liên quan tới task nếu test runner hỗ trợ filter; npm test thường chạy suite mặc định; npm run test:api chỉ dùng khi script này có thật trong package.json. Output kỳ vọng là test pass hoặc lỗi cụ thể để Claude sửa tiếp. Rủi ro: chạy full suite có thể tốn thời gian, chạm service phụ thuộc database/cache, hoặc fail do môi trường local chưa sẵn sàng.
Nếu project không có command đó, đọc package.json trước thay vì đoán.
Bước 6: Rollback khi Skill gây nhiễu
Nếu Skill quá rộng hoặc sai:
Do not use any Skill for the next answer. Answer directly.
Nếu muốn xóa Skill thử nghiệm:
rm -rf .claude/skills/api-reviewer .claude/skills/test-writer
PowerShell:
Remove-Item -Recurse -Force .claude/skills/api-reviewer, .claude/skills/test-writer
Chỉ rollback thư mục bạn vừa tạo. Không xóa .claude toàn bộ vì có thể chứa settings, hooks, agents hoặc memory khác.
5. Prompt mẫu nên dùng
Tạo Skill mới:
Create a project-level Claude Code Skill named api-reviewer for taskflow-ai.
It should live at .claude/skills/api-reviewer/SKILL.md.
Do not edit files yet. Return the full SKILL.md content.
The skill must focus on API contract, validation, auth, security, error handling, tests, rollback risk, and maintainability.
Keep the instruction concise to avoid context bloat.
Cải thiện Skill hiện có:
Review .claude/skills/api-reviewer/SKILL.md.
Make the description more precise, reduce unnecessary text, and keep the output format actionable.
Return a patch proposal only.
Review API bằng Skill:
/api-reviewer Review the current git diff for API-facing changes.
Prioritize breaking API contract, missing authorization, unsafe input, inconsistent errors, and missing tests.
Do not fix yet. Findings first, ordered by severity.
Viết test bằng Skill:
/test-writer Write focused tests for task deletion.
Cover success, unauthorized, forbidden ownership, and not found.
Follow existing test style.
Run the narrowest relevant test command and report the exact result.
Khi Skill bị gọi sai:
Use /api-reviewer only. Ignore test-writing unless the review finds missing coverage.
6. Trade-offs
| Lựa chọn | Lợi ích | Rủi ro |
|---|---|---|
| Prompt trực tiếp | Nhanh, linh hoạt | Dễ thiếu checklist, khó chuẩn hóa |
.claude/commands/*.md | Gọi thủ công dễ | Ít linh hoạt hơn Skills |
| Skill | Tái sử dụng tốt, có auto-invocation, supporting files | Có thể phình context hoặc bị gọi sai |
| Supporting files | Giữ SKILL.md gọn | Cần thêm quản lý file |
allowed-tools | Giảm friction khi Skill chạy | Không thay thế permission policy |
Best solution cho taskflow-ai: tạo Skill cho workflow lặp lại có checklist rõ, ví dụ API review, test writing, security review. Không tạo Skill cho mọi việc nhỏ.
Rủi ro thực tế:
descriptionquá rộng làm Claude tự dùng Skill không cần thiết.SKILL.mdquá dài làm tốn context.allowed-toolsquá rộng làm tăng rủi ro command/edit ngoài ý muốn.- Skill review nhưng lại tự sửa file vì instruction không cấm rõ.
- Skill cũ không còn khớp architecture mới.
7. Best practices
- Đặt tên Skill theo workflow:
api-reviewer,test-writer,security-reviewer. - Viết
descriptionbằng câu cụ thể, đưa use case chính lên đầu. - Đưa điều kiện dùng cụ thể vào
description; ví dụ nói rõ chỉ dùng cho backend API-facing changes, không dùng cho docs/UI-only changes. - Dùng
disable-model-invocation: truecho Skill chỉ nên chạy khi user gọi trực tiếp. - Với Skill review, ghi rõ
Do not edit files unless explicitly asked. - Output format nên cố định cho review và test.
- Giữ
SKILL.mdngắn; chuyển ví dụ dài sang supporting files. - Không đưa secret, private endpoint, credential, hoặc production data vào Skill.
- Không pre-approve tool không cần thiết.
- Review Skill như review code: scope, permissions, maintainability, security.
- Khi commit project Skill, giải thích trong PR vì sao team cần Skill đó.
8. Performance / cost / context
Skill tiết kiệm token khi thay thế prompt dài lặp lại, nhưng chỉ khi Skill ngắn và đúng phạm vi. Trong session thường, Claude chỉ cần thấy metadata như description để biết Skill tồn tại; nội dung đầy đủ của SKILL.md chỉ vào context khi Skill được invoke. Sau khi invoked, nội dung đó có thể ở lại các turn sau và được mang qua compact theo ngân sách context, nên Skill dài sẽ làm workflow nặng hơn.
Cách tối ưu:
- Giữ phần chính của
SKILL.mdkhoảng 80-150 dòng nếu có thể. - Không copy nguyên docs framework vào Skill.
- Không liệt kê mọi edge case hiếm.
- Dùng supporting files cho checklist dài.
- Dùng
disable-model-invocation: truecho workflow có side effect hoặc cần user chủ động gọi. - Dùng
pathskhi Skill chỉ nên tự kích hoạt trong một vùng file cụ thể. - Với test, yêu cầu chạy narrow test trước full suite.
- Với review, yêu cầu findings theo severity và bỏ advice chung chung.
Prompt tiết kiệm context:
/api-reviewer Review only the current git diff. Inspect related files only if needed to validate a concrete finding.
Prompt tốn context:
/api-reviewer Review the whole backend and tell me everything that can be improved.
9. Checklist cuối bài
- Tôi hiểu Skill là gì và nằm ở đâu.
- Tôi phân biệt được Skill với prompt dài,
CLAUDE.md, và.claude/commands. - Tôi biết gọi Skill bằng
/skill-name. - Tôi biết
descriptionảnh hưởng tới auto-invocation. - Tôi đã tạo
.claude/skills/api-reviewer/SKILL.md. - Tôi đã tạo
.claude/skills/test-writer/SKILL.md. -
api-reviewercó checklist API contract, auth, validation, security, tests, rollback. -
test-writerinspect nearby tests trước khi viết test mới. - Tôi hiểu
allowed-toolskhông phải deny-list. - Tôi biết Skill content có thể ở lại context sau khi invoked.
- Tôi biết rollback hoặc disable Skill khi nó gây nhiễu.
10. Bài tập
Bài cơ bản: tạo Skill api-reviewer và dùng nó review một endpoint thật trong taskflow-ai.
Bài thực tế: tạo Skill test-writer, dùng nó đề xuất hoặc thêm test cho endpoint vừa review, rồi chạy command test liên quan.
Bài nâng cao: thêm supporting file checklists/security.md cho api-reviewer, sau đó yêu cầu Skill dùng checklist này khi API chạm auth, ownership hoặc sensitive data.
Bài áp dụng cá nhân: chọn một workflow bạn hay lặp lại như UI review, refactor, migration review hoặc release notes. Viết nháp một SKILL.md, rồi review frontmatter, permission và context cost trước khi dùng.
Tài liệu
Tóm tắt kiến thức
Skill trong Claude Code là một gói instruction tái sử dụng. Một Skill thường nằm ở:
~/.claude/skills/<skill-name>/SKILL.md
.claude/skills/<skill-name>/SKILL.md
Với taskflow-ai, ưu tiên project Skill trong .claude/skills khi Skill phụ thuộc convention của repo. Skill có thể được Claude tự chọn qua description hoặc được gọi trực tiếp bằng /skill-name.
Một Skill tốt có:
- Frontmatter rõ:
name,description,when_to_use,argument-hint,disable-model-invocationkhi cần gọi thủ công,pathskhi cần giới hạn theo file, vàallowed-toolskhi thật sự cần pre-approve tool. - Instruction ngắn và cụ thể.
- Output format đoán được.
- Guardrail về quyền sửa file, command, secret, và scope.
- Supporting files cho tài liệu dài.
Hai Skill chính của Day 13:
.claude/skills/api-reviewer/SKILL.md
.claude/skills/test-writer/SKILL.md
allowed-tools chỉ pre-approve tool khi Skill active. Nó không cấm các tool khác theo nghĩa deny-list; permission settings vẫn là lớp kiểm soát chính.
Về context, phần mô tả Skill giúp Claude biết Skill có tồn tại, còn nội dung đầy đủ của SKILL.md chỉ được đưa vào conversation khi Skill được invoke. Sau đó nội dung này có thể ở lại các turn sau, vì vậy SKILL.md nên ngắn, còn checklist dài nên để supporting files.
Sơ đồ tư duy hoặc luồng xử lý
Workflow lặp lại nhiều lần?
|
+-- Không --> Dùng prompt trực tiếp
|
+-- Có
|
v
Checklist đã ổn định?
|
+-- Không --> Dùng prompt tạm, refine thêm
|
+-- Có
|
v
Tạo Skill
|
v
.claude/skills/<name>/SKILL.md
|
v
Viết description có điều kiện dùng cụ thể
|
v
Viết process + output format
|
v
Test bằng task nhỏ trong taskflow-ai
|
v
Điều chỉnh scope, allowed-tools, context cost
Luồng dùng api-reviewer:
API diff
-> /api-reviewer
-> xác định route/method/request/response/auth
-> check contract/security/maintainability/tests
-> findings theo severity
-> fix hoặc gọi /test-writer
Luồng dùng test-writer:
Behavior cần test
-> /test-writer
-> inspect nearby tests
-> chọn test level nhỏ nhất
-> viết happy path + failure path + edge case
-> chạy narrow test
-> báo coverage và gaps
Bảng so sánh
| Tiêu chí | Prompt trực tiếp | .claude/commands/*.md | Skills |
|---|---|---|---|
| Phù hợp | Việc ngắn, một lần | Shortcut thủ công | Workflow lặp lại có checklist |
| Tự động chọn theo ngữ cảnh | Không | Hạn chế | Có, qua description |
| Gọi trực tiếp | Không có tên cố định | Có | Có, bằng /skill-name |
| Supporting files | Không | Hạn chế | Có |
| Context cost | Mỗi lần paste lại | Tùy command | Chỉ tốn khi invoked |
| Rủi ro | Thiếu ý, lệch chuẩn | Command quá cứng | Skill dài hoặc auto-invoke sai |
| Skill | Mục đích | Khi dùng | Output tốt |
|---|---|---|---|
api-reviewer | Review API readiness | Route, controller, service, schema, auth | Findings theo severity |
test-writer | Viết test tập trung | Feature, bug fix, API, service, component | Test cases, command, result |
security-reviewer | Review security risk | Auth, input, secrets, logging | Risk, exploit scenario, fix |
ui-reviewer | Review UI workflow | Form, list, dashboard, responsive | UX/accessibility findings |
Lỗi thường gặp
descriptionquá chung Ví dụdescription: Helps with code.làm Claude khó chọn đúng. Nên viết rõ use case, project, và tiêu chí.Skill quá dài Copy toàn bộ coding standard vào
SKILL.mdlàm context phình. Chuyển ví dụ dài sang supporting files.Hiểu nhầm
allowed-toolsallowed-toolskhông phải deny-list. Nếu cần cấm hành động, dùng permission settings hoặc hook.Review Skill tự sửa file Với Skill review, thêm câu:
Do not edit files unless the user explicitly asks for fixes.Skill không theo project convention
test-writerphải đọc nearby tests trước, không tự thêm test framework mới khi repo đã có Jest/Vitest.Tạo quá nhiều Skill trùng vai trò
api-reviewer,backend-reviewer,route-reviewerdễ làm Claude chọn không nhất quán. Gộp hoặc phân định rõ scope.
Cách debug
Kiểm tra Skill có đúng vị trí:
find .claude/skills -maxdepth 3 -type f -name SKILL.md
PowerShell:
Get-ChildItem .claude/skills -Recurse -Filter SKILL.md
Chạy ở root taskflow-ai. Lệnh liệt kê các file SKILL.md trong .claude/skills; output kỳ vọng có đường dẫn tới api-reviewer/SKILL.md và test-writer/SKILL.md. Rủi ro thấp vì đây là lệnh đọc, nhưng nếu chạy sai thư mục sẽ báo không thấy .claude/skills hoặc trả về danh sách của repo khác.
Kiểm tra frontmatter:
sed -n '1,40p' .claude/skills/api-reviewer/SKILL.md
PowerShell:
Get-Content .claude/skills/api-reviewer/SKILL.md -TotalCount 40
Chạy ở root taskflow-ai. Lệnh in 40 dòng đầu để kiểm tra cặp ---, description, argument-hint, allowed-tools, và heading của Skill. Rủi ro thấp vì đây là lệnh đọc; không paste output có secret nếu Skill vô tình chứa thông tin nhạy cảm.
Nếu Skill không được auto-invoke, sửa description cho cụ thể hơn, hoặc gọi trực tiếp:
/api-reviewer Review PATCH /api/tasks/:id.
Nếu Skill bị gọi quá thường xuyên, thu hẹp:
description: Review only taskflow-ai backend API-facing changes or API tests. Do not use for UI-only, docs-only, or unrelated scripts.
paths: ["apps/api/**", "packages/api/**", "server/**"]
Nếu output quá dài:
Report only actionable findings. Limit low-priority cleanup suggestions.
Nếu test do test-writer viết bị fail:
/test-writer The new task tests fail. Identify the failing assertion, root cause, and smallest fix. Do not rewrite the whole file.
Link tài liệu nên đọc
- Claude Code Skills: https://code.claude.com/docs/en/skills
- Claude Code Permissions: https://code.claude.com/docs/en/permissions
- Claude Code Settings: https://code.claude.com/docs/en/settings
- Claude Code Best Practices: https://code.claude.com/docs/en/best-practices
Bài tập
Bài 1 — Cơ bản
Mục tiêu: tạo project Skill api-reviewer.
Chạy ở root taskflow-ai:
mkdir -p .claude/skills/api-reviewer
PowerShell:
New-Item -ItemType Directory -Force .claude/skills/api-reviewer
Chạy ở root taskflow-ai. Lệnh tạo thư mục Skill nếu chưa có; output kỳ vọng là thư mục .claude/skills/api-reviewer tồn tại sau khi chạy. Rủi ro thấp, nhưng nếu chạy sai repo sẽ tạo Skill ở nhầm project.
Tạo .claude/skills/api-reviewer/SKILL.md với các yêu cầu:
- Có YAML frontmatter.
- Có
name: api-reviewer. - Có
descriptionrõ về API review trongtaskflow-ai. - Có
argument-hint. - Có
descriptionnêu rõ khi nào dùng Skill và khi nào không dùng. - Có
allowed-tools: Read Grep Glob Bash. - Có output format findings theo severity.
- Có guardrail
Do not edit files unless the user explicitly asks for fixes.
Prompt kiểm thử:
/api-reviewer Review POST /api/tasks for validation, auth, response contract, and missing tests.
Do not edit files. Return findings only.
Output kỳ vọng:
Findings
- Severity:
- File:
- Issue:
- Risk:
- Suggested fix:
- Test to add:
Rollback:
rm -rf .claude/skills/api-reviewer
PowerShell:
Remove-Item -Recurse -Force .claude/skills/api-reviewer
Chạy rollback ở root taskflow-ai và chỉ xóa thư mục Skill vừa tạo. Output kỳ vọng là thư mục api-reviewer biến mất. Rủi ro cao hơn lệnh tạo vì đây là lệnh xóa đệ quy; kiểm tra kỹ path trước khi chạy, không xóa cả .claude.
Bài 2 — Thực tế
Mục tiêu: tạo Skill test-writer và dùng cho một behavior thật.
Tạo thư mục:
mkdir -p .claude/skills/test-writer
PowerShell:
New-Item -ItemType Directory -Force .claude/skills/test-writer
Chạy ở root taskflow-ai. Lệnh tạo thư mục cho Skill test-writer; output kỳ vọng là .claude/skills/test-writer tồn tại. Rủi ro thấp, tương tự Bài 1: sai thư mục thì tạo file cấu hình ở nhầm repo.
Tạo .claude/skills/test-writer/SKILL.md với yêu cầu:
- Có
name: test-writer. - Có
descriptionnói rõ Skill viết test theo behavior hiện có. - Có
descriptionnêu rõ dùng khi thêm hoặc cải thiện test chotaskflow-ai. - Có
allowed-tools: Read Grep Glob Bash Edit. - Bắt buộc inspect nearby tests trước khi viết test mới.
- Ưu tiên behavior assertion thay vì implementation detail.
- Chạy narrow test command trước.
- Báo command, result và remaining gaps.
Prompt áp dụng:
/test-writer Add or propose focused tests for task creation validation in taskflow-ai.
Inspect existing tests first.
Cover valid creation, missing title, unauthorized request, and invalid due date if applicable.
Run the narrowest relevant test command if files are edited.
Command test tham khảo:
npm run test -- tasks
npm test
npm run test:api
Chạy ở root taskflow-ai. Ưu tiên lệnh hẹp nhất có trong package.json: filter theo tasks nếu test runner hỗ trợ, rồi mới tới test:api, cuối cùng mới chạy npm test. Output kỳ vọng là pass/fail rõ ràng kèm tên test hoặc assertion lỗi. Rủi ro: full suite có thể chậm, cần database/cache, hoặc fail do môi trường local chứ không phải do Skill.
Nếu không biết command, đọc package.json:
cat package.json
PowerShell:
Get-Content package.json
Chạy ở root taskflow-ai. Lệnh chỉ đọc script npm để chọn command test đúng; output kỳ vọng có mục scripts. Rủi ro thấp, nhưng không nên copy nội dung có token/private registry nếu dự án vô tình đặt secret trong file này.
Bài 3 — Nâng cao
Mục tiêu: thêm supporting file cho api-reviewer.
Tạo:
mkdir -p .claude/skills/api-reviewer/checklists
PowerShell:
New-Item -ItemType Directory -Force .claude/skills/api-reviewer/checklists
Chạy ở root taskflow-ai. Lệnh tạo thư mục supporting files cho api-reviewer; output kỳ vọng là thư mục checklists tồn tại dưới đúng Skill. Rủi ro thấp, nhưng cần tránh tạo checklist rời khỏi Skill vì Claude sẽ khó tìm đúng tài liệu hỗ trợ.
Tạo .claude/skills/api-reviewer/checklists/security.md:
# API Security Checklist
Check:
- Authentication is required where needed.
- Authorization verifies ownership or role.
- User input is validated before use.
- Error responses do not leak internals.
- Secrets are not logged or returned.
- Query filters cannot expose another user's data.
- Expensive endpoints consider rate limit or abuse risk.
Cập nhật SKILL.md:
If the API change touches auth, user ownership, sensitive data, or external input, consult `checklists/security.md`.
Prompt kiểm thử:
/api-reviewer Review DELETE /api/tasks/:id.
Pay special attention to ownership checks and data exposure.
Use the security checklist if relevant.
Expected result: findings có nhắc ownership, auth, error behavior, test gaps hoặc nói rõ không có high-confidence findings.
Bài 4 — Review & Reflection
Review hai Skill như review code:
Review my Day 13 Skills:
- .claude/skills/api-reviewer/SKILL.md
- .claude/skills/test-writer/SKILL.md
Focus on description precision, context efficiency, allowed-tools risk, output format, and maintainability.
Do not edit files. Return findings and suggested improvements.
Trả lời ngắn:
- Skill nào giúp giảm prompt lặp lại nhiều nhất?
descriptioncó đủ rõ không?- Skill có bị gọi sai ngữ cảnh không?
SKILL.mdcó quá dài không?- Có phần nào nên chuyển sang supporting file không?
allowed-toolscó tool nào không cần thiết không?- Skill có làm Claude tự sửa file khi bạn chỉ muốn review không?
- Output có đủ actionable không?
- Có command hoặc test nào nên đưa vào instruction không?
- Nếu team cùng dùng, cần thêm convention nào?
Tiêu chí hoàn thành
- Có
.claude/skills/api-reviewer/SKILL.md. - Có
.claude/skills/test-writer/SKILL.md. - Cả hai Skill có frontmatter hợp lệ.
-
api-reviewercó output findings theo severity. -
test-writerinspect nearby tests trước khi viết test. - Đã gọi thử
/api-reviewertrên một endpoint thật. - Đã gọi thử
/test-writercho một behavior hoặc bug cụ thể. - Có command test hoặc lý do rõ nếu chưa chạy được test.
- Có ghi chú rủi ro security, maintainability, context, permission.
- Biết rollback bằng cách xóa thư mục Skill vừa tạo.
Gợi ý nếu bí
Nếu không biết viết description:
description: Review taskflow-ai API changes for routes, controllers, services, schemas, auth, validation, response contracts, errors, security, tests, rollback risk, and maintainability.
Nếu Skill review tự sửa file, thêm:
Do not edit files unless the user explicitly asks for fixes.
Nếu output quá dài:
Report only actionable findings. Order findings by severity. Limit low-priority cleanup suggestions.
Nếu Skill không trigger, gọi trực tiếp:
/api-reviewer Review PATCH /api/tasks/:id.
Đáp án tham khảo hoặc expected result
Project structure:
.claude/
skills/
api-reviewer/
SKILL.md
checklists/
security.md
test-writer/
SKILL.md
Expected reflection:
api-reviewer giúp chuẩn hóa review API và giảm prompt lặp lại. test-writer hữu ích khi biến review findings thành regression tests. Điểm cần cải thiện là thu hẹp description để không bị gọi cho docs/UI-only changes và chuyển checklist security dài sang supporting file.