Cache safe stop hook snapshotting

From ychampion/cskill-agents · View interactive version

Cache safe stop hook snapshotting is an AI agent skill from the GitHub repository ychampion/cskill-agents. Persist a cache-safe stop-hook context snapshot only for main session queries so later helpers can resume from stable state without fork pollution.

How to use this skill

Skill file

SKILL: Cache-Safe Stop-Hook Snapshotting

Domain: context-management

Trigger: Apply when end-of-turn hooks need to persist enough state for follow-up helpers, but background forks must not overwrite the main session snapshot.

Source Pattern: Distilled from reviewed context, compaction, and memory-governance patterns.

Core Method

Build one structured hook context at turn end, then persist a cache-safe snapshot only when the query source belongs to the main interactive session or the SDK control path. This gives downstream helpers a stable resume surface while preventing side agents and background forks from clobbering shared state with their own narrower contexts. The snapshot gate lives outside optional prompt-suggestion features so every consumer that depends on the shared state still gets it.

Key Rules

Example Application

If a REPL turn finishes and /btw or another side-question helper may run next, save a cache-safe snapshot from the main turn’s hook context. If a background memory extractor reaches the same stop-hook code, skip the snapshot so the main session state remains authoritative.

Anti-Patterns (What NOT to do)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.