Session Guard skill for Claude

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.

Session Guard SKILL.md

The full skill file from wshobson/agents (MIT).

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

SignalThresholdAction
Tool call count>40YELLOW: checkpoint + recite critical rules
Tool call count>60RED: split or compact with anchor
Agent contradicts earlier decisionAnyVERIFY: re-read source of truth
Style/naming driftAnyRECITE: state the active rules aloud
File read returns unexpected contentAnyRE-READ: don't trust cached state
Task scope growing unboundedContinuousSPLIT: 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.

How to install Session Guard

Claude Code

Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):

npx degit wshobson/agents/plugins/skill-forge-essentials/skills/session-guard#main ~/.claude/skills/session-guard

Codex

npx degit wshobson/agents/plugins/skill-forge-essentials/skills/session-guard#main ~/.codex/skills/session-guard

Claude.ai and Claude Desktop

Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.

Frequently asked questions

+What does the Session Guard skill do?

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.

+How do I install Session Guard in Claude Code?

Copy the skill folder into ~/.claude/skills/session-guard, for example with "npx degit wshobson/agents/plugins/skill-forge-essentials/skills/session-guard#main ~/.claude/skills/session-guard". Claude Code loads it automatically and uses it when a task matches.

+Does Session Guard work with ChatGPT or Codex?

Yes. Session Guard uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/session-guard. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.

+Is Session Guard free?

Session Guard is published on GitHub by wshobson under the MIT license, which allows free use.

Related productivity skills

  1. Handoff

    Compact the current conversation into a handoff document for another agent to pick up.

    mattpocock/skills★ 327k
  2. Notebooklm

    Use for anything in Google NotebookLM: querying notebooks, adding sources, generating Audio or Video Overviews, reports, flashcards or…

    alirezarezvani/claude-skills★ 30k
  3. Teach

    Teach the user a new skill or concept, within this workspace.

    mattpocock/skills★ 327k
  4. Task Coordination Strategies

    Decompose complex tasks, design dependency graphs, and coordinate multi-agent work with proper task descriptions and workload balancing.

    wshobson/agents★ 43k
  5. Agent Harness

    Use when an agent should drive a goal in one of this repo's domains to a verified close, before starting the work.

    alirezarezvani/claude-skills★ 30k
  6. Andreessen

    Blunt market-first verdict on an idea, venture or career bet, leading with the strongest counterargument, or a 3x5-card daily plan.

    alirezarezvani/claude-skills★ 30k
  7. Capture

    Use whenever the user unloads a messy brain dump of ideas, tasks and plans ('capture this', 'brain dump', a long unstructured paste) and…

    alirezarezvani/claude-skills★ 30k
  8. Deep Work

    Use when someone wants to plan a deep work day, time-block their calendar or task list, budget or cut shallow work, protect focus hours,…

    alirezarezvani/claude-skills★ 30k
  9. Dossier

    Use for diligence or meeting prep on a specific company, person or organization ('prep me for a meeting with X', 'due diligence on Y').

    alirezarezvani/claude-skills★ 30k

See all productivity skills →

More skills from wshobson

  1. Shellcheck Configuration

    Master ShellCheck static analysis configuration and usage for shell script quality.

    wshobson/agents★ 43k
  2. Signed Audit Trails Recipe

    Step-by-step cookbook for setting up cryptographically signed audit trails on Claude Code tool calls.

    wshobson/agents★ 43k
  3. Similarity Search Patterns

    Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or…

    wshobson/agents★ 43k

All skills by wshobson →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.