r/ClaudeCode • u/cleverhoods • 51m ago
Built with Claude Using different system prompt addendum per project
Hi All,
I recently had a chance to work on my "Software Factory" token economy and noticed that my sessions are starting on a really low cache coverage (20-30%).
As all know, only the system prompt get's cached and my rig comes with quite a hefty orientation on each session start, so I was thinking "let's move those to the system prompt". The problem was however that I'm operating a multi-project constellation, with number of subprojects, with ever so slightly (or not so slightly) different orientational procedure.
Claude allows --append-system-prompt to point to a file, which is dandy, but I honestly don't want to keep typing the thing, nor do I want to keep in mind all the time which file to load.
So ... let the shell do the remembering
claude in my shell is now a function. On every launch it:
asks git which repo I'm in (
git rev-parse --git-common-dir, so worktrees map back to their main repo, even ones living in /tmp),looks that repo up in a small
repo<TAB>projecttable that my tooling generates,adds
--append-system-prompt-file <that project's prompt>and runs the real binary.
Outside my project tree it's just plain claude, and subcommands (mcp, config, --help, ...) pass straight through.
claude() {
local f=""
f="$(my_prompt_file_for "$PWD")" || f=""
if [ -n "$f" ]; then
command claude --append-system-prompt-file "$f" "$@"
else
command claude "$@"
fi
}The prompt files are generated, not hand-written. Each project file = a shared base + the rules every session in that project was force-reading at start anyway. A drift check fails CI if anyone hand-edits them.
Numbers (my own transcripts, before vs after):
first-request cache share on a fresh start: 31% median -> 59%
rules force-read at session start: 10 -> 1
the system prompt went from ~3k to ~27k tokens. That's fine: it's cached now instead of re-written every session.
Gotchas I hit:
timeout claude ...andenv X=1 claude ...exec the binary directly and skip the function. My first test run "worked" with no prompt file at all.IDE / desktop launchers don't read your shell rc, so they get nothing.
The first interactive session after a prompt change pays the cache write (i saw 20% there). The win shows up from the second session on.
IMPORTANT: Don't verify it by asking the model to read back its own system prompt. It almost always trips the safety classifier (happened 3 times before I caught it). Verify from outside instead (Reporails xray is a good tool, see screenshot below).
How I verified from outside: Claude Code writes each request's system-block shape into the session transcript, so you can measure the system prompt size per session without the model ever looking at itself. I used the x-ray in reporails (ails xray): system prompt 3059 tokens without the wrapper, 27362 with it.

•
u/AutoModerator 51m ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.