CLAUDE.md and context engineering
CLAUDE.md is an instruction file loaded automatically at the start of every session. Everything you write there enters the context on every request — it is a token cost. So what you leave out matters as much as what you put in.
The file can exist at several levels, all of which are concatenated (broad → narrow):
- Organisation level — a policy file managed by IT.
- User level —
~/.claude/CLAUDE.md, personal preferences across all projects. - Project level —
./CLAUDE.mdor./.claude/CLAUDE.md, shared with the team through git. - Local —
./CLAUDE.local.md, personal project notes, added to.gitignore.
| PUT in CLAUDE.md | DON'T put in CLAUDE.md |
|---|---|
| Build and test commands (exact, at module level) | A listing of the directory tree — the agent can see it |
| Conventions: naming, package structure, DI rules | The dependency list — it is in `libs.versions.toml` |
| Pitfalls: "X doesn't work in this module because…" | General Kotlin/Android tutorials |
| Prohibitions: "don't touch this folder", "don't use this library" | Multi-step procedures — those belong in a skill |
| Architectural decisions and their rationale | Anything derivable from git history |
Target: under 200 lines. A long file eats context and reduces adherence — the model loses a specific rule inside a long list. If it grows, split parts into .claude/rules/, where a paths: frontmatter makes a rule load only when matching files are in play.
# CLAUDE.md — MyApp (Android)
## Build
- Module compile: `./gradlew :feature:orders:compileDebugKotlin`
- Unit tests: `./gradlew :feature:orders:testDebugUnitTest`
- A full build takes 6-8 minutes — run the command for the module you changed.
## Architecture
- MVVM + Clean: `data/` → `domain/` → `ui/`. `ui/` never depends on
`data/` directly.
- DI: Hilt. Every new ViewModel is `@HiltViewModel`.
- UI state: a separate `XxxUiState` data class per screen.
## Conventions
- All user-facing text lives in `strings.xml` — hardcoded strings are rejected.
- New screens are always Compose. Do not add new XML layouts.
## Do not touch
- The `legacy/` folder — it has its own migration plan.
- `libs.versions.toml` — do not change versions without asking.A realistic Android CLAUDE.md: short, concrete, checkable rules. Each line answers a question so the agent doesn't have to ask it again.
📚 Sources and documentation
- Memory and CLAUDE.mdofficialcode.claude.com
File locations, load order, `.claude/rules/` and the `paths:` frontmatter.
- Monorepos and large reposofficialcode.claude.com