Skills · Data & AI

Session Guard

Unverified30/40

>- 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.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add session-guard

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

>- 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.

The whole source

No sign-in, no blur, nothing truncated
session-guard/SKILL.md86 lines3.9 KBRawView on GitHub
Frontmatter — 2 properties
namesession-guard
description>- 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.
1---
2name: session-guard
3description: >-
4 Use when working on complex multi-step tasks, when a session is getting long
5 (40+ tool calls), when the agent starts ignoring rules it followed earlier,
6 when conventions drift, when output quality seems to degrade, or after any
7 context compaction event. Prevents long-session corruption AND context
8 compaction amnesia through behavioral self-enforcement.
9---A5No allowed-tools declared — no way to tell what this skill may touch
10 
11# Session Guard
12 
13## Overview
14 
15Long 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.
16 
17## When to Use
18 
19- Session exceeds 40 tool calls
20- Agent contradicts earlier decisions
21- Style/naming conventions start drifting
22- After any context compaction event
23- Task scope growing unbounded
24 
25## Health Signals
26 
27| Signal | Threshold | Action |
28|--------|-----------|--------|
29| Tool call count | >40 | YELLOW: checkpoint + recite critical rules |
30| Tool call count | >60 | RED: split or compact with anchor |
31| Agent contradicts earlier decision | Any | VERIFY: re-read source of truth |
32| Style/naming drift | Any | RECITE: state the active rules aloud |
33| File read returns unexpected content | Any | RE-READ: don't trust cached state |
34| Task scope growing unbounded | Continuous | SPLIT: one task per session |
35 
36## Protocol
37 
38### Green Zone (0-40 tool calls)
39Normal operation. No intervention needed.
40 
41### Yellow Zone (40-60 tool calls)
421. CHECKPOINT - summarize progress in one paragraph
432. RECITE - state the 3-5 most critical active rules aloud: "Active rules: [naming convention], [file structure], [error handling pattern], [testing requirement]"
443. ASSESS - almost done? Push through. Not done? Prepare split.
454. REDUCE - no exploratory reads. Only targeted operations.
46 
47### Red Zone (60+ tool calls OR drift signal)
481. STOP - do not make more tool calls
492. VERIFY - re-read project rules (don't trust memory)
503. CHECKPOINT - write state to handoff document
514. SPLIT - create handoff, suggest fresh session
52 
53## Context Anchoring (anti-compaction)
54 
55When compaction has occurred (sudden loss of earlier context, or after /compact):
56 
571. RE-READ the project's rules file immediately
582. RECITE the 3-5 critical rules aloud in your response
593. VERIFY your planned next action matches those rules before executing
604. If uncertain about ANY prior decision, RE-READ the source file - don't guess
61 
62### What survives compaction:
63- Most recent user messages (high priority)
64- Currently-invoked skill body (capped at 5K tokens, oldest dropped first)
65- Git status and project structure
66- File contents read AFTER compaction
67 
68### What gets LOST in compaction:
69- Decisions made early in conversation
70- Architectural rules stated only verbally (not in files)
71- Context from tool outputs (file reads, command outputs)
72 
73### Compaction-Safe Pattern
74Keep 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.
75 
76## Common Mistakes
77 
78- Trusting that you remember the rules after 50+ tool calls (you don't - re-read)
79- Re-reading EVERYTHING to be safe (wastes tool calls - be targeted)
80- Feeling fine therefore assuming context is fine (compaction is SILENT)
81- Splitting AFTER noticing problems (split BEFORE - prevention, not recovery)
82 
83## Why This Matters
84 
85Context 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.
86 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Data & AI