Quy trình khẩn cấp
Module 8.5: Quy trình khẩn cấp
Phần tiêu đề “Module 8.5: Quy trình khẩn cấp”Thời gian học: ~30 phút
Yêu cầu trước: Module 8.4 (Đánh giá chất lượng)
Kết quả: Sau module này, bạn sẽ có mental playbook cho emergency, thuộc recovery command, và act nhanh khi có vấn đề.
1. WHY — Tại Sao Cần Hiểu
Phần tiêu đề “1. WHY — Tại Sao Cần Hiểu”Claude supposed to “clean up config file.” Bạn approve không nhìn kỹ. Giờ file .env bị xóa, production environment variable mất, scramble nhớ lại có gì trong đó.
Hoặc: Claude modified 50 file trong “refactor” và bạn không biết actually changed gì.
Emergency xảy ra. Dù có tất cả safeguard từ module trước. Question là: bạn có recovery plan không? Lúc emergency không phải lúc để học procedure — học bây giờ.
2. CONCEPT — Ý Tưởng Cốt Lõi
Phần tiêu đề “2. CONCEPT — Ý Tưởng Cốt Lõi”Emergency Severity Level
Phần tiêu đề “Emergency Severity Level”| Level | Situation | Response Time | Example |
|---|---|---|---|
| 🔴 Critical | Production affected, data loss | Immediate | Deleted .env, broke production |
| 🟠 Major | Development blocked | Minutes | 50 file modified, không continue được |
| 🟡 Minor | Confused state, recoverable | When convenient | Context confusion, stuck loop |
Emergency Playbook
Phần tiêu đề “Emergency Playbook”Memorize sequence này:
- STOP:
Ctrl+Cngay. Đừng để Claude continue. - ASSESS:
git status+git diff— actually changed gì? - CONTAIN:
git stash— save current state trước khi recover - RECOVER: Chọn recovery strategy theo severity
- DOCUMENT: Xảy ra gì? Update CLAUDE.md để prevent recurrence.
Recovery Strategy
Phần tiêu đề “Recovery Strategy”| Strategy | Command | Khi Nào |
|---|---|---|
| Discard one file | git checkout <file> | 1 file sai |
| Discard all change | git checkout . | Mọi thứ từ last commit bad |
| Hard reset | git reset --hard HEAD | Complete disaster recovery |
| Recover deleted commit | git reflog | Nếu reset quá mạnh |
| Fresh session | /clear | Context hopelessly confused |
Pre-Emergency Preparation
Phần tiêu đề “Pre-Emergency Preparation”- Commit thường xuyên (small commit = easy recovery point)
- Dùng feature branch (isolate AI work)
- Backup .env và sensitive file ngoài git
- Thuộc recovery command
- Never Full Auto không có git safety net
3. DEMO — Từng Bước
Phần tiêu đề “3. DEMO — Từng Bước”Scenario 1: Claude Deleted Important File
Phần tiêu đề “Scenario 1: Claude Deleted Important File”STOP — Thấy Claude đang delete file? Press Ctrl+C ngay.
ASSESS:
$ git statusOutput:
Changes not staged for commit: deleted: .env deleted: config/production.json modified: src/config.tsCONTAIN:
$ git stashOutput:
Saved working directory and index state WIP on main: abc1234 Last commitRECOVER:
$ git checkout .Output:
Updated 3 paths from the indexVerify recovery:
$ ls .env config/production.jsonOutput:
.env config/production.jsonFile đã về.
Scenario 2: Claude Modified 50 File
Phần tiêu đề “Scenario 2: Claude Modified 50 File”STOP: Ctrl+C
ASSESS:
$ git diff --statOutput:
50 files changed, 2000 insertions(+), 500 deletions(-)$ git diff --name-onlyOutput:
src/api/users.tssrc/api/products.ts... (48 file nữa)CONTAIN:
$ git stashPARTIAL RECOVERY (nếu một số change good):
$ git stash pop$ git checkout src/unrelated/$ git add src/feature/$ git commit -m "Partial work from AI session"NUCLEAR RECOVERY (nếu mọi thứ bad):
$ git reset --hard HEADScenario 3: Reset Quá Mạnh, Mất Work
Phần tiêu đề “Scenario 3: Reset Quá Mạnh, Mất Work”$ git reflogOutput:
abc1234 HEAD@{0}: reset: moving to HEADdef5678 HEAD@{1}: commit: My work before disasterghi9012 HEAD@{2}: commit: Earlier workRecover:
$ git reset --hard def5678Work đã về.
4. PRACTICE — Tự Thực Hành
Phần tiêu đề “4. PRACTICE — Tự Thực Hành”Bài 1: Emergency Drill
Phần tiêu đề “Bài 1: Emergency Drill”Goal: Practice full emergency playbook trong safe environment.
Instructions:
- Tạo test repository với vài file
- Tạo intentional “bad” change (delete file, modify nhiều)
- Practice: STOP → ASSESS → CONTAIN → RECOVER
- Time yourself. Target: full recovery trong <2 phút.
💡 Hint
Setup:
mkdir emergency-drill && cd emergency-drillgit initecho "important" > config.txtecho "SECRET=abc123" > .envgit add . && git commit -m "Initial"
# Simulate disasterrm .envecho "broken" >> config.txtGiờ practice recovery.
Bài 2: Recovery Command Muscle Memory
Phần tiêu đề “Bài 2: Recovery Command Muscle Memory”Goal: Make recovery command automatic.
Practice đến khi type không cần nghĩ:
git status # Changed gì?git diff # Exactly gì?git stash # Save stategit checkout . # Discard allgit checkout <file> # Discard onegit reset --hard HEAD # Nucleargit reflog # Find lost commitBài 3: Post-Mortem Practice
Phần tiêu đề “Bài 3: Post-Mortem Practice”Goal: Build documentation habit.
Instructions:
- Simulate emergency (Bài 1)
- Sau recovery, viết brief post-mortem:
- Xảy ra gì?
- Tại sao xảy ra?
- Prevent thế nào lần sau?
- Draft CLAUDE.md addition để prevent recurrence
✅ Solution
Example post-mortem:
Xảy ra gì: Claude delete .env khi “clean up config”
Tại sao: Vague prompt (“clean up”) + approve không review
Prevention: Add vào CLAUDE.md:
## Dangerous OperationNEVER delete không có explicit approval:- .env file- config/*.json- Migration file5. CHEAT SHEET
Phần tiêu đề “5. CHEAT SHEET”Emergency Playbook
Phần tiêu đề “Emergency Playbook”- 🛑 STOP:
Ctrl+C - 🔍 ASSESS:
git status+git diff - 📦 CONTAIN:
git stash - 🔧 RECOVER: Xem command bên dưới
- 📝 DOCUMENT: Update CLAUDE.md
Recovery Command
Phần tiêu đề “Recovery Command”# Xem damagegit status && git diff --stat
# Save mess trước recovergit stash
# Undo one filegit checkout path/to/file
# Undo everythinggit checkout .
# Nuclear resetgit reset --hard HEAD
# Recover từ bad resetgit refloggit reset --hard <commit-hash>Prevention Checklist
Phần tiêu đề “Prevention Checklist”- Commit trước AI session
- Dùng feature branch
- Never Full Auto không có git branch
- Backup .env file riêng
6. PITFALLS — Lỗi Thường Gặp
Phần tiêu đề “6. PITFALLS — Lỗi Thường Gặp”| ❌ Sai Lầm | ✅ Đúng Cách |
|---|---|
| Panic chạy command random | Follow playbook: STOP → ASSESS → CONTAIN → RECOVER |
git reset --hard là first response | Assess trước. Đôi khi partial recovery tốt hơn. |
Quên git stash trước recovery | Always stash. Có thể cần inspect bad state sau. |
| Không biết reflog tồn tại | git reflog recover được gần như mọi thứ. Learn it. |
| Same emergency hai lần | Document và update CLAUDE.md sau mỗi emergency |
| Không commit trước AI session | Clean commit = clean recovery point. Non-negotiable. |
| Chỉ giữ .env trong working directory | Backup sensitive file riêng ngoài git |
7. REAL CASE — Câu Chuyện Thực Tế
Phần tiêu đề “7. REAL CASE — Câu Chuyện Thực Tế”Scenario: Startup Việt Nam, Friday 6pm. Dev rush finish feature, dùng Full Auto “clean up and refactor.” Đi lấy coffee. Quay lại thấy Claude đã delete 3 migration file nó consider “outdated” và modified database schema.
Panic response (sai):
- Cố recreate migration file từ memory
- Chạy migration trên staging — broke everything
- Mất 4 giờ cố recover database
Nên làm:
- STOP:
Ctrl+C(hoặc đừng approve deletion) - ASSESS:
git diff --statsẽ show migration deletion - CONTAIN:
git stash - RECOVER:
git checkout db/migrations/ - DOCUMENT: Add vào CLAUDE.md: “NEVER delete migration file không có explicit approval”
Lesson learned: “2 phút emergency procedure tiết kiệm 4 giờ panic. Giờ emergency command được in ra dán lên monitor.”
Phase 8 Hoàn Thành! Bạn đã có thể debug Claude — detect hallucination, break loop, fix context confusion, assess quality, recover từ emergency.
Phase Tiếp Theo: Phase 9: Legacy Code & Brownfield — Apply Claude Code vào codebase có sẵn.