---
name: "context-caching-cost-optimizer"
description: "Structure system prompts and reference context to maximize LLM prompt caching discounts."
metadata:
  author: "Anthropic"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "optimize prompt caching"
  - "structure prompt for prefix cache"
  - "reduce cost with context caching"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Prompt Context Caching & Prefix Optimization

Organizes prompts to leverage Anthropic Prompt Caching and OpenAI Context Caching: placing static instructions, schemas, and documents at the prefix to achieve 90% cost and latency reductions.

## When to Invoke
Invoke this skill whenever you need to:
- optimize prompt caching
- structure prompt for prefix cache
- reduce cost with context caching

## Execution SOP & Rules
1. Place static, immutable content (system instructions, tool schemas, reference docs) at the prompt start.
2. Place dynamic, frequently changing variables (current turn query, timestamps) strictly at the end.
3. Ensure prefix blocks exceed the minimum token threshold required for caching (e.g. 1024 tokens on Anthropic).
4. Avoid injecting fluctuating timestamps or random seeds into the static prefix segment.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
