⚡ PromptLoot

Home › AI Agents

Cache-Friendly System Prompt Layout: Stable First, Volatile Last

A layout and checklist for agent system prompts that keeps prompt caching working: stable rules and tools first, dates, user data, and changing context last.

Added · Updated

You are reviewing and restructuring a system prompt (and the tool list sent with it) so prompt caching works. Prompt caching reuses an exact matching prefix, so anything that changes between requests must come after everything that doesn't.

## Input
I'll paste: the full system prompt, how the tool/function list is built, and what gets added per request (dates, user name, memory, retrieved docs, file contents).

## Step 1: Label every block
Split the prompt into blocks and label each one:
- STABLE: identical for every user and every request (role, rules, output format, examples, tool definitions).
- SESSION: fixed for one user or session but differs between them (user name, plan, preferences, project rules file).
- VOLATILE: changes per request or turn (current time, retrieved documents, latest file contents, tool results, counters).

## Step 2: Find cache breakers
Flag anything that changes the prefix without needing to:
- A timestamp, date, request ID, or random value near the top.
- The user's name or account details inside the stable rules.
- Tool definitions generated in a different order each time, or a tool list that changes per request and is rendered before the stable rules.
- Rules files (CLAUDE.md, AGENTS.md) that get edited mid-session and sit early in the prompt.
- Whitespace, JSON key order, or template variables that render slightly differently each time.

## Step 3: Rewrite in this order
1. STABLE role and rules
2. STABLE output format and examples
3. STABLE tool definitions, sorted by name, same order every time
4. --- cache breakpoint ---
5. SESSION context (user, project rules)
6. --- cache breakpoint (if your provider supports more than one) ---
7. VOLATILE context, with the current date as one line at the very end ("Today is ...")

Keep the meaning of every rule. Don't add new rules. If a rule mixes stable and volatile content ("You are helping Sam, today is ..."), split it.

## Step 4: Report
- The rewritten prompt with the three sections clearly marked.
- A table: block, label, old position, new position.
- Each cache breaker you found and how you fixed it.
- An estimate of how many tokens are now in the stable prefix vs. before (rough count is fine).
- Anything you couldn't move without changing behavior, so I can decide.

## Rules
- Never put secrets or API keys in any section.
- Don't shorten rules to save tokens unless I ask; this is about order, not length.
- If the tool list really must change per request, say so and suggest the smallest stable subset to keep up front.

How to use it

  1. Click Copy template.
  2. Paste into ChatGPT, Claude, Grok, Cursor, or your agent framework.
  3. Replace the [BRACKETED] parts with your details.

Pairs well with: Lean CLAUDE.md: Trim a Bloated Rules File to 40 Lines

Sponsor this page · Reach builders who use AI daily. Get details

FAQ

Why does my prompt cache hit rate drop?

Prompt caching only reuses an exact matching prefix. One changing value near the top, like a timestamp, a user name, or a tool list rendered in a different order, makes everything after it a cache miss.

What should go first in a system prompt for caching?

Everything that never changes: the role, rules, output format, examples, and tool definitions in a fixed order. Per-user context goes next, and per-request content like the date and retrieved documents goes last.

Does editing CLAUDE.md mid-session break caching?

It can. If the rules file is loaded early in the prompt, changing it rewrites the prefix and the next request can't reuse the cache. Edit rules between sessions when you can.

Does this work with OpenAI, Anthropic, and Gemini?

Yes. The providers handle caching differently (automatic prefix caching or explicit cache breakpoints), but all of them reward a stable prefix with volatile content at the end.

Can I add a tool or edit the system prompt in the middle of a session?

Avoid it. Tool definitions and the system prompt sit at the front of the cached prefix, so changing either one turns the rest of the conversation into a cache miss, and some newer model APIs reject a request outright when the system prompt or tool list changes while earlier thinking blocks are kept. Start a new session instead, or put the change in a later user message.

Get 3 new templates every week

Free. Unsubscribe anytime.

Related templates

General AI Agent System Prompt

A solid base system prompt for any tool-using AI agent.

AI Agent Harness Starter Pack: Rules, Hooks, Status & Verify

Set up a simple agent harness: a short rules file, a status file the agent keeps current, a verify command, and hooks that block 'done' until checks pass.

System Prompt Regression Test Set (Evals for Prompts & Skills)

Edit your system prompt, CLAUDE.md, or agent skill without fear: build a small eval set, rerun it after every change, and catch regressions before users do.

Browse all AI Agents templates

New on PromptLoot

Check Current Docs First: Stop Agents Using Outdated APIs

Rules that make Claude Code, Cursor, and Codex check your installed versions and current docs before calling any API, cite the version, and flag deprecations.

Minimal Diff Rules: Stop AI Agents Rewriting Unrelated Code

Rules for Claude Code, Cursor, and Codex: change only what you asked, no drive-by renames, refactors, or reformatting, and list every changed file.
PromptLoot Pro Pack · 200+ advanced templates, agent workflows, and Cursor rules bundles. Coming soon