session-guard – skill Agent & Tự động hóa cho agent AI
Dùng khi làm tác vụ nhiều bước phức tạp, khi phiên làm việc kéo dài (40+ lần gọi tool), khi agent bắt đầu bỏ qua quy tắc đã tuân thủ trước đó, khi quy ước bị lệch, khi chất lượng đầu ra có dấu hiệu giảm, hoặc sau bất kỳ sự kiện nén ngữ cảnh nào. Ngăn chặn hỏng phiên dài VÀ mất trí nhớ do nén ngữ cảnh th
Cài skill session-guard bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/session-guard-085ec.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /session-guard – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/session-guard-085ec.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $session-guard – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/session-guard-085ec.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /session-guard – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/session-guard-085ec.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /session-guard – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc 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)
1. CHECKPOINT - summarize progress in one paragraph
2. RECITE - state the 3-5 most critical active rules aloud: "Active rules: [naming convention], [file structure], [error handling pattern], [testing requirement]"
3. ASSESS - almost done? Push through. Not done? Prepare split.
4. REDUCE - no exploratory reads. Only targeted operations.
Red Zone (60+ tool calls OR drift signal)
1. STOP - do not make more tool calls
2. VERIFY - re-read project rules (don't trust memory)
3. CHECKPOINT - write state to handoff document
4. SPLIT - create handoff, suggest fresh session
Context Anchoring (anti-compaction)
When compaction has occurred (sudden loss of earlier context, or after /compact):
1. RE-READ the project's rules file immediately
2. RECITE the 3-5 critical rules aloud in your response
3. VERIFY your planned next action matches those rules before executing
4. 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.
Skill liên quan
- mcp-server-builder – Thiết kế và triển khai MCP (Model Context Protocol) server sẵn sàng production từ hợp…
- cursor-delegate – Giao tác vụ lập trình cho Cursor Agent CLI (`cursor-agent`) chỉ khi người dùng yêu cầu…
- scrapling – Thu thập dữ liệu website với trình duyệt tàng hình và vượt Cloudflare.
- memory-engineering – Dùng khi thiết kế, rà soát hoặc chi trả cho hệ thống bộ nhớ của agent — thêm bộ nhớ cho…
- memory-review – Phân tích auto-memory để tìm ứng viên thăng cấp, mục cũ, cơ hội hợp nhất và chỉ số sức…
- memory-status – Bảng điều khiển sức khỏe bộ nhớ: số dòng, file chủ đề, dung lượng, mục cũ và khuyến…
- merge – Hợp nhất nhánh của agent thắng cuộc vào base, lưu trữ các nhánh thua và dọn dẹp…
- datadog-automation – Tự động hóa tác vụ Datadog qua Rube MCP (Composio): truy vấn metric, tìm log, quản lý…