session-guard
Helps your agent stay on track during long tasks. It's useful for preventing errors and memory loss in extended work sessions.
What it does
This agent helps keep track of long and complicated tasks. It checks if the AI is following the rules and prevents it from 'forgetting' what was agreed upon earlier, especially when the conversation gets too long or parts of it are lost.
When to use it
- ✓When the AI has already done many things (more than 40 steps).
- ✓When the AI starts doing things that don't follow the rules agreed upon earlier.
- ✓After the AI loses part of the conversation (context compaction).
Example of what to ask your AI
“AI, please check if you are still following the file naming rules we set at the beginning.”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
It works by observing what the AI is doing. If the AI does too much, or starts to stray, it reminds the AI of important rules or suggests splitting the task to avoid confusion.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add wshobson/agents --skill session-guardOr download just the file:
curl -L https://raw.githubusercontent.com/wshobson/agents/main/plugins/skill-forge-essentials/skills/session-guard/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
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.
FAQ
What is 'context compaction'?
It's when the AI, to save memory, discards older parts of the conversation. This can cause it to 'forget' important rules or decisions.
Why does the AI 'forget' things?
In very long conversations, the AI can struggle to remember all instructions and rules. Context compaction makes this worse by removing old information.
How can I ensure the AI follows the rules?
Put the most important rules in text files that the AI can re-read. This way, even if the conversation is compacted, the AI can refer to the file to remember.
Details
Original description by the author
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
Popularity
- GitHub stars
- 41k
- Ranking position
- #4956
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
screen-reader-testing
Has your agent test websites using screen readers to ensure they are accessible.
wshobson/agents
wcag-audit-patterns
Helps your agent audit websites for accessibility and fix issues according to WCAG guidelines.
wshobson/agents
multi-reviewer-patterns
Enables your agent to coordinate parallel code reviews, deduplicating findings and consolidating reports.
wshobson/agents
parallel-debugging
Allows the agent to debug complex issues with parallel investigations and root cause analysis.
wshobson/agents
Similar skills
benchmark
Helps your agent measure code speed and performance. It's useful for ensuring things are fast and finding slowness issues.
affaan-m/ECC
content-hash-cache-pattern
Lets your agent use content hashes to cache file processing results. This avoids repeated processing and auto-invalidates the cache when content changes. Useful for speeding up slow tasks.
affaan-m/ECC
parallel-execution-optimizer
Makes your agent speed up complex tasks by breaking them into smaller parts and running them in parallel. It ensures everything is verified at the end.
affaan-m/ECC