session-guard

Monitors long agent sessions and prevents context compaction amnesia through behavioral self-enforcement.

39.3k|4.2k|Updated Jul 24, 2025
One-click install
npx skills add https://github.com/wshobson/agents --skill session-guard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: session-guard
Source: https://github.com/wshobson/agents/tree/main/plugins/skill-forge-essentials/skills/session-guard
Command: npx skills add https://github.com/wshobson/agents --skill session-guard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Long AI agent sessions silently degrade: after 40+ tool calls or a context compaction event, the agent forgets rules it followed earlier, drifts from naming conventions, and contradicts prior decisions. Hooks do not fix this because post-compaction injections get ignored. This Skill provides a behavioral protocol that detects degradation signals and anchors critical rules before damage occurs.

Core Features & Use Cases

  • Health Signal Monitoring: Tracks tool call counts and drift signals with a Green/Yellow/Red zone model, triggering checkpoints, rule recitation, or session splits at defined thresholds.
  • Context Anchoring After Compaction: Defines a re-read, recite, verify protocol to restore critical rules from files after any compaction event.
  • Compaction-Safe Patterns: Enforces keeping critical instructions in files (CLAUDE.md, CONTEXT.md) rather than conversation, so rules survive compaction.
  • Use Case: During a large multi-file refactoring exceeding 60 tool calls, the agent stops, writes a handoff document, re-reads project rules, and splits the work into a fresh session instead of producing drifted, inconsistent code.

Quick Start

Ask the agent to apply the session-guard protocol to monitor this long refactoring session and checkpoint or split before context degrades.

Frequently Asked Questions about session-guard

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent an AI agent from forgetting rules in long sessions?

Use a behavioral self-enforcement protocol that monitors tool call counts and drift signals. At 40+ calls, checkpoint progress and recite critical rules aloud; at 60+, stop, write a handoff document, and split into a fresh session before quality degrades.

What should I do after a context compaction event?

Immediately re-read the project's rules file, recite the 3-5 most critical active rules in your response, and verify your next planned action matches those rules before executing. Never trust memory of pre-compaction decisions; re-read source files when uncertain.

Do hooks fix context compaction problems in AI agents?

No. Hooks do not reliably fix compaction because the agent ignores post-compaction injections due to narrative momentum created by the compaction summary. Behavioral self-monitoring and file-based rule anchoring are the working countermeasures.

Why does agent output quality degrade after many tool calls?

Degradation happens because early decisions and verbally stated rules fall out of context, and compaction silently drops instructions. Signals include contradicted decisions, naming drift, and unexpected file contents, which indicate cached state can no longer be trusted.

When should I split a task into a new agent session?

Split when tool calls exceed 60, when any drift signal appears, or when task scope grows unbounded. Splitting before problems appear is prevention; splitting after noticing damage is recovery and costs more.