session-guard
Skill này làm gì
Agent này giúp theo dõi các tác vụ dài và phức tạp. Nó kiểm tra xem AI có làm theo các quy tắc đã thống nhất không và ngăn AI “quên” những điều đã thỏa thuận trước đó, nhất là khi cuộc trò chuyện quá dài hoặc một phần bị mất.
Khi nào nên dùng
- ✓Khi AI đã thực hiện rất nhiều bước (hơn 40 bước).
- ✓Khi AI bắt đầu làm những việc không tuân theo quy tắc đã thống nhất trước đó.
- ✓Sau khi AI mất một phần cuộc trò chuyện (nén ngữ cảnh).
Liên kết skill
https://github.com/wshobson/agents/blob/main/plugins/skill-forge-essentials/skills/session-guard/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
“AI ơi, hãy kiểm tra xem bạn có còn tuân theo quy tắc đặt tên tệp mà chúng ta đã đặt ở đầu không.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent theo dõi những việc AI đang làm. Nếu AI làm quá nhiều hoặc bắt đầu đi lệch, nó sẽ nhắc AI các quy tắc quan trọng hoặc đề xuất chia nhỏ tác vụ để tránh nhầm lẫn.
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.
Session Guard
Overview
Long sessions corrupt silently. Context compaction drops instructions unannounced. Hooks don't fix it (confirmed by multiple developers on GitHub issues #19471, #9796, #64171). This skill prevents both through behavioral self-enforcement: monitor health, anchor critical rules through compaction, split before damage occurs. No packages, no databases - pure behavioral enforcement that works in every harness.
When to Use
- Session exceeds 40 tool calls
- Agent contradicts earlier decisions
- Style/naming conventions start drifting
- After any context compaction event
- Task scope growing unbounded
Health Signals
| Signal | Threshold | Action |
|---|---|---|
| Tool call count | >40 | YELLOW: checkpoint + recite critical rules |
| Tool call count | >60 | RED: split or compact with anchor |
| Agent contradicts earlier decision | Any | VERIFY: re-read source of truth |
| Style/naming drift | Any | RECITE: state the active rules aloud |
| File read returns unexpected content | Any | RE-READ: don't trust cached state |
| Task scope growing unbounded | Continuous | SPLIT: one task per session |
Protocol
Green Zone (0-40 tool calls)
Normal operation. No intervention needed.
Yellow Zone (40-60 tool calls)
- CHECKPOINT - summarize progress in one paragraph
- RECITE - state the 3-5 most critical active rules aloud: "Active rules: [naming convention], [file structure], [error handling pattern], [testing requirement]"
- ASSESS - almost done? Push through. Not done? Prepare split.
- REDUCE - no exploratory reads. Only targeted operations.
Red Zone (60+ tool calls OR drift signal)
- STOP - do not make more tool calls
- VERIFY - re-read project rules (don't trust memory)
- CHECKPOINT - write state to handoff document
- SPLIT - create handoff, suggest fresh session
Context Anchoring (anti-compaction)
When compaction has occurred (sudden loss of earlier context, or after /compact):
- RE-READ the project's rules file immediately
- RECITE the 3-5 critical rules aloud in your response
- VERIFY your planned next action matches those rules before executing
- If uncertain about ANY prior decision, RE-READ the source file - don't guess
What survives compaction:
- Most recent user messages (high priority)
- Currently-invoked skill body (capped at 5K tokens, oldest dropped first)
- Git status and project structure
- File contents read AFTER compaction
What gets LOST in compaction:
- Decisions made early in conversation
- Architectural rules stated only verbally (not in files)
- Context from tool outputs (file reads, command outputs)
Compaction-Safe Pattern
Keep critical instructions in FILES (CLAUDE.md, CONTEXT.md), NOT in conversation. If a rule matters, it must live in a file the agent can re-read - not in something agreed on earlier.
Common Mistakes
- Trusting that you remember the rules after 50+ tool calls (you don't - re-read)
- Re-reading EVERYTHING to be safe (wastes tool calls - be targeted)
- Feeling fine therefore assuming context is fine (compaction is SILENT)
- Splitting AFTER noticing problems (split BEFORE - prevention, not recovery)
Why This Matters
Context compaction is the #1 unsolved platform problem in 2026. Hooks don't fix it (confirmed: the agent ignores post-compaction injections because the compaction summary creates narrative momentum). This skill is the lightweight behavioral countermeasure: no infrastructure, no packages - disciplined self-monitoring that works in every harness.
Câu hỏi thường gặp
“Nén ngữ cảnh” là gì?
Đó là khi AI, để tiết kiệm bộ nhớ, bỏ bớt các phần cũ của cuộc trò chuyện. Điều này có thể khiến AI quên các quy tắc hoặc quyết định quan trọng.
Vì sao AI “quên” thông tin?
Trong các cuộc trò chuyện rất dài, AI có thể khó nhớ hết mọi chỉ dẫn và quy tắc. Nén ngữ cảnh làm tình trạng này tệ hơn vì loại bỏ thông tin cũ.
Làm sao để AI tuân theo quy tắc?
Hãy đặt các quy tắc quan trọng nhất vào tệp văn bản để AI có thể đọc lại. Như vậy, dù cuộc trò chuyện bị nén, AI vẫn có thể xem tệp để nhớ lại.
Chi tiết
Mô tả gốc của tác giả
Use when working on complex multi-step tasks, when a session is getting long (40+ tool calls), when the agent starts ignoring rules it followed earlier, when conventions drift, when output quality seems to degrade, or after any context compaction event. Prevents long-session corruption AND context compaction amnesia through behavioral self-enforcement.
repo: wshobson/agents
Độ phổ biến
- Sao GitHub
- 41k
- Vị trí xếp hạng
- #6789
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
screen-reader-testing
41kGiúp agent của bạn kiểm thử website bằng trình đọc màn hình để đảm bảo chúng có thể truy cập được.
wcag-audit-patterns
41kGiúp agent của bạn kiểm toán website về khả năng truy cập và sửa các vấn đề theo hướng dẫn WCAG.
multi-reviewer-patterns
41kCho phép agent của bạn điều phối các đợt rà soát mã song song, loại bỏ phát hiện trùng lặp và tổng hợp báo cáo.
parallel-debugging
41kCho phép agent gỡ lỗi các vấn đề phức tạp bằng cách điều tra song song và phân tích nguyên nhân gốc.
Skill tương tự
knowledge-automation
394kGiúp agent của bạn thiết lập tác vụ định kỳ đưa nội dung mới vào kho Knowledge theo lịch, rồi kiểm tra tác vụ có chạy không.
knowledge-source-ingest
394kGiúp agent của bạn cập nhật Knowledge vault với các mục mới từ kênh chat, nguồn tin hoặc hộp thư, mà không thêm lại những gì đã có.
benchmark
280kGiúp agent của bạn đo tốc độ và hiệu suất của code, hữu ích để đảm bảo mọi thứ nhanh và tìm ra những chỗ chậm.