Cache identical fork prefix construction

From ychampion/cskill-agents · View interactive version

Cache identical fork prefix construction is an AI agent skill from the GitHub repository ychampion/cskill-agents. Build forked conversation prefixes that stay identical across turns so prompt caching keeps working.

How to use this skill

Skill file

SKILL: Cache Identical Fork Prefix Construction

Domain: caching

Trigger: Use this when a forked agent must reuse the parent prompt cache and needs byte-identical prefixes for each invocation.

Source Pattern: Distilled from reviewed subagent orchestration, isolation, and lifecycle implementations.

Core Method

Duplicate the parent assistant message wholesale, then generate a single user message containing standardized tool_result placeholders (all with the same text) followed by the directive text. Keeping every byte of the assistant message and placeholder deterministic ensures that identical tool_use sequences map to the same cache key. Build a child-specific directive message by wrapping it in <fork-boilerplate> and appending fork directive prefix before the per-worker instructions.

Key Rules

Example Application

When the model triggers a fork from an inline agent, reuse this method to build the fork prompt so the fork shares the cache of the parent — future identical tasks reuse the same cached prefix and avoid redundant API calls.

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.