fix: cache-friendly system prompt order; drop blog-ideas from prompt #42

Merged
joshtronic merged 1 commit from fix/cache-friendly-prompt-order into master 2026-05-20 00:44:08 +00:00
Owner

Touchdown Labs piece on KV cache memory hierarchy got me thinking
about what we control on the prompt side. Two changes that should
reduce "pay for turn 1 again" tax across consecutive ticks:

(a) Reorder system prompt for cache stability.

Prompt caching keys on shared PREFIX. If volatile content sits
upstream of stable content, every change to the volatile bit
invalidates the cache for everything downstream too. Previous
order put AGENTS.md LAST -- so any MEMORY.md or blog-ideas.md
change invalidated AGENTS.md too.

New order, most-stable-first:
AGENTS.md -- PR-only changes
identity.md -- PR-only changes
index.md -- PR-only changes
memories/MEMORY.md -- Claude edits occasionally

That gives us a stable upstream prefix that survives MEMORY.md
edits, and a stable AGENTS.md + identity prefix that survives
even MEMORY.md churn.

(b) Drop blog-ideas.md from the system prompt entirely.

blog-ideas.md is the highest-churn file in brain -- Claude
appends ideas regularly during reading and journaling ticks.
Loading it in-prompt guaranteed cache invalidation on every
write. AGENTS.md updated to say it's Read-on-demand instead --
Claude opens it via the Read tool when shipping a post or
considering one, and Edits it to append new ideas (harness
picks up the edit alongside the journal commit).

Also collapsed the four redundant identity.md/index.md fallback
conditionals -- brain_system_prompt now handles missing files
gracefully (skips them, always includes AGENTS.md), so the
guard is just a single warning log if the required brain files
are missing.

What this does NOT do: longer cache TTL (still 5min default).
Verifying that gap requires checking Anthropic Console for
cache_creation vs cache_read token counts on consecutive ticks
~10-15 min apart. If the cache is dying between ticks, 1h TTL
would help -- but Claude Code doesn't expose the flag, would
require dropping the CLI and hitting /v1/messages directly.
Worth measuring before deciding.

Touchdown Labs piece on KV cache memory hierarchy got me thinking about what we control on the prompt side. Two changes that should reduce "pay for turn 1 again" tax across consecutive ticks: (a) Reorder system prompt for cache stability. Prompt caching keys on shared PREFIX. If volatile content sits upstream of stable content, every change to the volatile bit invalidates the cache for everything downstream too. Previous order put AGENTS.md LAST -- so any MEMORY.md or blog-ideas.md change invalidated AGENTS.md too. New order, most-stable-first: AGENTS.md -- PR-only changes identity.md -- PR-only changes index.md -- PR-only changes memories/MEMORY.md -- Claude edits occasionally That gives us a stable upstream prefix that survives MEMORY.md edits, and a stable AGENTS.md + identity prefix that survives even MEMORY.md churn. (b) Drop blog-ideas.md from the system prompt entirely. blog-ideas.md is the highest-churn file in brain -- Claude appends ideas regularly during reading and journaling ticks. Loading it in-prompt guaranteed cache invalidation on every write. AGENTS.md updated to say it's Read-on-demand instead -- Claude opens it via the Read tool when shipping a post or considering one, and Edits it to append new ideas (harness picks up the edit alongside the journal commit). Also collapsed the four redundant identity.md/index.md fallback conditionals -- brain_system_prompt now handles missing files gracefully (skips them, always includes AGENTS.md), so the guard is just a single warning log if the required brain files are missing. What this does NOT do: longer cache TTL (still 5min default). Verifying that gap requires checking Anthropic Console for cache_creation vs cache_read token counts on consecutive ticks ~10-15 min apart. If the cache is dying between ticks, 1h TTL would help -- but Claude Code doesn't expose the flag, would require dropping the CLI and hitting /v1/messages directly. Worth measuring before deciding.
fix: cache-friendly system prompt order; drop blog-ideas from prompt
All checks were successful
Lint / check-sync (push) Successful in 5s
Lint / check-sync (pull_request) Successful in 4s
b83d6beb61
Touchdown Labs piece on KV cache memory hierarchy got me thinking
about what we control on the prompt side. Two changes that should
reduce "pay for turn 1 again" tax across consecutive ticks:

(a) Reorder system prompt for cache stability.

Prompt caching keys on shared PREFIX. If volatile content sits
upstream of stable content, every change to the volatile bit
invalidates the cache for everything downstream too. Previous
order put AGENTS.md LAST -- so any MEMORY.md or blog-ideas.md
change invalidated AGENTS.md too.

New order, most-stable-first:
  AGENTS.md           -- PR-only changes
  identity.md         -- PR-only changes
  index.md            -- PR-only changes
  memories/MEMORY.md  -- Claude edits occasionally

That gives us a stable upstream prefix that survives MEMORY.md
edits, and a stable AGENTS.md + identity prefix that survives
even MEMORY.md churn.

(b) Drop blog-ideas.md from the system prompt entirely.

blog-ideas.md is the highest-churn file in brain -- Claude
appends ideas regularly during reading and journaling ticks.
Loading it in-prompt guaranteed cache invalidation on every
write. AGENTS.md updated to say it's Read-on-demand instead --
Claude opens it via the Read tool when shipping a post or
considering one, and Edits it to append new ideas (harness
picks up the edit alongside the journal commit).

Also collapsed the four redundant identity.md/index.md fallback
conditionals -- brain_system_prompt now handles missing files
gracefully (skips them, always includes AGENTS.md), so the
guard is just a single warning log if the required brain files
are missing.

What this does NOT do: longer cache TTL (still 5min default).
Verifying that gap requires checking Anthropic Console for
cache_creation vs cache_read token counts on consecutive ticks
~10-15 min apart. If the cache is dying between ticks, 1h TTL
would help -- but Claude Code doesn't expose the flag, would
require dropping the CLI and hitting /v1/messages directly.
Worth measuring before deciding.
joshtronic deleted branch fix/cache-friendly-prompt-order 2026-05-20 00:44:08 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
joshtronic/igor!42
No description provided.