Summary
Optimize prompt caching by moving dynamic information (time, runtime) from system prompt to conversation messages, following Claude Code team's best practices.
Problem to solve
Current system prompt contains dynamic info that changes every request:
## Current Date & Time - changes every minute
## Runtime - contains model, channel that may vary
This breaks Anthropic's prefix caching, causing:
- Lower cache hit rate (~50-60% vs potential >85%)
- Higher token costs
- Slower response times
Proposed solution
- Move time info to user messages via
<system-reminder> tag:
const userMessage = `<system-reminder>Time: ${now}</system-reminder>\n\n${originalMessage}`;
- Separate Runtime info:
- Keep stable info (agent, host, repo, os) in system prompt
- Move dynamic info (model, channel) to messages
-
Fix tool definition order - ensure consistent ordering across sessions
-
Implement Cache-Safe Compaction - keep same prefix during compaction
Alternatives considered
- Remove time completely: Not viable as agents need current time awareness
- Cache per-minute: Inefficient, still breaks on minute boundaries
- User-level caching only: Misses opportunity for cross-session optimization
Impact
Affected: All Clawdbot users using Anthropic models
Severity: Medium - impacts cost and latency
Frequency: Every API call
Consequence:
- Estimated 30-50% higher token costs than necessary
- 20-30% slower first-token latency
- Reduced efficiency for long conversations
Evidence/examples
References:
Additional information
Claude Code team treats cache hit rate as a critical metric - drops trigger SEV incidents. This optimization aligns with their production-proven patterns.
Summary
Optimize prompt caching by moving dynamic information (time, runtime) from system prompt to conversation messages, following Claude Code team's best practices.
Problem to solve
Current system prompt contains dynamic info that changes every request:
## Current Date & Time- changes every minute## Runtime- contains model, channel that may varyThis breaks Anthropic's prefix caching, causing:
Proposed solution
<system-reminder>tag:Fix tool definition order - ensure consistent ordering across sessions
Implement Cache-Safe Compaction - keep same prefix during compaction
Alternatives considered
Impact
Affected: All Clawdbot users using Anthropic models
Severity: Medium - impacts cost and latency
Frequency: Every API call
Consequence:
Evidence/examples
References:
Additional information
Claude Code team treats cache hit rate as a critical metric - drops trigger SEV incidents. This optimization aligns with their production-proven patterns.