Main thread only cache editing

From ychampion/cskill-agents · View interactive version

Main thread only cache editing is an AI agent skill from the GitHub repository ychampion/cskill-agents. Gate cached microcompact cache edits to the main thread so background forks cannot alter the shared cache state.

How to use this skill

Skill file

SKILL: Main Thread Only Cache Editing

Domain: context-management

Trigger: Use when cached microcompact runs and you must prevent subagents or forks from writing cache edits that the main thread shares.

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

Core Method

Only perform cache-editing microcompactions when the executing query source is the main thread (repl_main_thread or unspecified). This avoids contaminating shared cachedMCState with tool results that belong to background runs like session-memory compact, prompt suggestion, or other forks. The guard also ensures the cached MC path is never triggered in non-ANT builds that disable the feature altogether.

Key Rules

Example Application

When a main-thread REPL session hits the cached microcompact trigger, the guard passes, allowing registerToolResult and createCacheEditsBlock to run. Forked agents such as session memory or prompt suggestion skip this block entirely, leaving the global cache untouched.

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.