Use Mid-Conversation System Messages to Save Cache
Inject new instructions mid-chat without losing the speed of cached history.
Add a 'system' role message within the conversation flow to update instructions while preserving the existing prompt cache.
The Scenario
Halfway through a long technical brainstorming session, you realize you need Claude to adopt a specific persona or follow a new formatting constraint. You want to apply this instruction without the latency of re-processing the last 20 messages.
Before & after
To change instructions, you had to edit the top-level system prompt. This invalidated the cache for everything following it, costing more and taking 2–3 minutes to re-process.
Inserting a mid-conversation system message keeps the previous cache intact. This update takes seconds and maintains the speed and cost-efficiency of the session.
The Prompt
// Append this to your message list instead of editing the top-level 'system' field
{
"role": "system",
"content": "From now on, provide all code snippets in TypeScript only and include JSDoc comments."
}Instead of changing the initial system prompt to add a new rule (which invalidates the cache), append a message with {"role": "system"} at the current turn. Claude will follow the instruction from that point forward without re-reading the whole conversation from scratch.
Source
Claude Platform release notes - Claude Platform Docs"The cached prefix stays the same... and the new instruction is still applied as a system instruction."
