Claudemd Deep Dive
Description
Research into how Claude Code loads subdirectory CLAUDE.md files — what triggers injection, where content lands in the API payload, deduplication, session resume, and token cost, traced via intercepting proxy.
Installation
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open the source below and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
README
How Claude Code Reads CLAUDE.md Files — Experiment
Claude Code supports `CLAUDE.md` files at multiple levels. Global and project-root files are simple — loaded once at session start, always in context. Subdirectory files are different: the docs say they load *"on demand as Claude navigates your codebase"* but explain nothing about the actual mechanism.
We had questions that mattered for building agents:
- What exactly triggers the load — any tool, or a specific one?
- Does it re-inject on every file read, or is there deduplication?
- Where does the content go — system prompt or messages?
- What survives a session resume?
- Does repeated injection blow up token costs?
To answer these we put an intercepting HTTP proxy between Claude Code and the Anthropic API and traced every `/v1/messages` call. Full write-up: **[REPORT.md](./REPORT.md)**
Key Findings
| Question | Answer |
|---|---|
| What triggers subdir CLAUDE.md? | Read tool only — not Bash, Glob, or Write |
| Where does it appear? | Concatenated into the tool result text — not the system prompt, not a separate message |
| Does system prompt grow? | Never — stays constant regardless of how many subdirs load |
| Re-injected on every Read? | No — once per subprocess per directory (readFileState Map) |
| Visible after injection? | Yes — sticky in message history for all subsequent turns |
| Parallel reads, same dir? | One injection total for the whole batch |
| Persisted to disk? | Stripped before writing — disk session is always clean |
| Session resume? | readFileState resets → fresh injection on first Read |
| Token cost? | Near-zero — prompt caching absorbs it |
Repository Structure
Experiment scripts
| File | Description |
|---|---|
src/experiment.ts |
Experiment 1 — 9 scenarios covering first Read, same-session re-read, new session, multiple subdirs, Write-only, Glob-only, Bash-only, and resumed session. Outputs results.json. |
| `src/exper |
Related Skills
Awesome Go
A curated list of awesome Go frameworks, libraries and software
Development next.js
| The React Framework | 138360 | 1503 | 1 |
Development sharing-skills
skill for guidance.
Development root-cause-tracing
Use when errors occur deep in execution and you need to trace back to find the original trigger.
Development Template Skill
Minimal skeleton for a new skill project structure.
Development Third-party Notices
THE FOLLOWING SETS FORTH ATTRIBUTION NOTICES FOR THIRD PARTY SOFTWARE THAT MAY BE CONTAINED IN PORTIONS OF THI
Development