04 / 10Builder18 min lesson + 45 min lab

Make Project Context Durable

Use CLAUDE.md, rules, skills, and memory deliberately so each session begins with useful truth instead of an ever-growing instruction dump.

By the end

A concise, source-controlled project instruction system whose scopes, imports, local overrides, and debugging path are understood.

01

Different context has different lifecycles

Some knowledge should affect every task in a repository: the build command, architectural boundaries, naming conventions, and a rule never to publish without approval. Other knowledge matters only when working in a particular directory or performing a specific workflow. Mixing everything into one always-loaded file consumes context and weakens attention to the rules that matter.

Claude Code provides several mechanisms with different loading behavior. CLAUDE.md holds durable instructions that should be present across sessions. `.claude/rules/` can scope guidance to parts of a project. Skills provide reference material or repeatable workflows that load when relevant or invoked. Auto memory records machine-local learnings across sessions. Choose by lifecycle and audience, not by which file you discovered first.

02

Choose the correct instruction scope

User instructions in `~/.claude/CLAUDE.md` apply across your projects. A repository's `./CLAUDE.md` or `./.claude/CLAUDE.md` is shared through version control and should describe project facts. `CLAUDE.local.md` is for personal project-specific notes and belongs in `.gitignore`. Managed instructions may be supplied by an organization and cannot be treated as editable project content.

Directory hierarchy matters. Instructions above the working directory load at launch, while instructions in child directories can load when Claude enters those parts of the project. This supports monorepos, but it also means two sessions started from different directories may receive different context. Use `/context` when behavior suggests the wrong instructions loaded rather than adding the same rule in several places.

03

Write a high-signal CLAUDE.md

Include facts Claude cannot reliably infer: exact setup and verification commands, unusual architecture decisions, repository etiquette, environment quirks, and safety boundaries. Exclude generic advice, tutorials, file-by-file descriptions, and volatile status. Anthropic's guidance recommends keeping the file concise; the extension overview offers a practical rule of thumb of fewer than 200 lines.

Treat the file like code. When Claude repeats a mistake, first ask whether a precise durable rule would prevent it. Add the smallest useful instruction, observe whether behavior improves, and prune duplicates or stale entries. A long document full of emphatic rules is not stronger; it creates competition for limited context.

  • Commands: setup, targeted tests, typecheck, lint, build, and safe preview.
  • Architecture: canonical packages, ownership boundaries, and sources of truth.
  • Conventions: project-specific patterns that differ from common defaults.
  • Safety: secrets, destructive actions, publishing, data, and approval rules.
  • Proof: what evidence is required before claiming a change is complete.
04

Import, do not duplicate

CLAUDE.md supports `@path/to/import` references. Use imports to point at authoritative project documents such as a short architecture decision, test runbook, or shared agent instructions. Relative imports resolve from the file containing the import, and external imports require approval. Keep the imported material focused because it joins the session context.

Claude Code reads CLAUDE.md rather than AGENTS.md directly. If a multi-agent repository already uses AGENTS.md, Anthropic documents a simple bridge: create CLAUDE.md and import `@AGENTS.md`, then add only Claude-specific notes below it. This avoids two instruction files drifting apart while preserving tool-specific extensions.

05

Audit memory and loaded configuration

Use `/memory` to inspect instruction and memory locations, and `/context` to see what actually entered the current session. Auto memory is stored locally by project and can record recurring learnings, but it is not a team source of truth and is not automatically shared to another computer or cloud environment. Review it like notes, not policy.

When a rule, skill, hook, or MCP server seems absent, diagnose the effective configuration instead of rewriting it blindly. Anthropic's configuration debugging guide points to `/context`, `/doctor`, `/hooks`, and `/mcp` for different layers. Record where the setting lives, which scope wins, and whether the current session needs to be restarted or reloaded before testing again.

Working reference

Commands and patterns

Generate a starting project file

/init

Inside Claude Code, `/init` analyzes the project and proposes a starter CLAUDE.md. Review and shorten it before treating it as team guidance.

Inspect effective context and memory

/context
/memory

These interactive commands show what loaded and let you inspect the project's instruction and auto-memory locations.

Bridge shared agent instructions

# CLAUDE.md
@AGENTS.md

## Claude Code
- Use plan mode before changes under src/billing/.
- Run the targeted test and typecheck before reporting completion.

Import an existing AGENTS.md rather than maintaining duplicate shared policy, then add only Claude-specific behavior.

When the happy path breaks

Failure modes

01

Symptom

Claude overlooks a critical project rule even though it appears somewhere in CLAUDE.md.

Likely cause

The file is bloated, ambiguous, contradictory, or filled with information Claude can infer elsewhere.

Recovery

Use `/context` to confirm loading, rewrite the rule as a short testable instruction, and move occasional reference material into rules or skills.

02

Symptom

A teammate or cloud session behaves differently from the local session.

Likely cause

The required context lives in user instructions, CLAUDE.local.md, or machine-local auto memory rather than source-controlled project instructions.

Recovery

Promote only the durable team-relevant fact into the repository's CLAUDE.md, rule, or project skill and verify it from a clean environment.

03

Symptom

Several instruction files contain similar but inconsistent commands.

Likely cause

Guidance was copied instead of importing or pointing to one authoritative source.

Recovery

Choose an owner document, replace duplicates with an import or short pointer, and delete stale variants through a reviewed diff.

04

Symptom

A configuration edit appears to have no effect in the current conversation.

Likely cause

The wrong scope was edited, a more authoritative setting overrides it, or the relevant feature did not reload in the existing session.

Recovery

Inspect `/context` and the feature-specific diagnostic command, confirm settings precedence, then retest in a fresh session when required.

Hands-on lab

Build a durable context system for one repository

Create or repair the minimum project instructions needed for a fresh Claude Code session to build and verify a change safely.

  1. 01Run `/context` and `/memory`; record every instruction or memory source loaded for the repository.
  2. 02Collect the project's real setup, targeted test, typecheck, lint, build, and preview commands from source files or successful runs.
  3. 03Draft a CLAUDE.md containing only durable commands, architecture facts, conventions, safety boundaries, and proof requirements.
  4. 04Move any long optional procedure into a project skill or a focused document referenced by an import.
  5. 05If AGENTS.md exists, import it instead of duplicating shared instructions.
  6. 06Start a fresh session and ask Claude to state the commands and boundaries without opening the file manually.
  7. 07Run one harmless task and observe whether the project instructions change behavior as intended.

Deliverable: A source-controlled CLAUDE.md plus a context audit showing which guidance is shared, local, managed, path-scoped, or loaded on demand.

Reusable artifact

High-signal CLAUDE.md template

A compact project instruction file that emphasizes non-obvious facts, operating commands, and proof.

# Project purpose
- [One sentence describing the system and primary user outcome.]

# Canonical locations
- Repository root: [path or ownership rule]
- Main entry point: [path]
- Source of truth: [data or project record]

# Commands
- Install: `[command]`
- Develop: `[command]`
- Targeted test: `[command + selection pattern]`
- Typecheck/lint: `[commands]`
- Build: `[command]`

# Architecture and conventions
- [Non-obvious boundary or decision.]
- [Existing pattern to reuse.]

# Safety
- Never expose secret values or commit environment files.
- Preserve unrelated user changes in dirty worktrees.
- Pause before deletion, publishing, production changes, external messages, payments, or permission changes.

# Completion
- Report changed files, commands run, observed outputs, and remaining risk.
- Do not equate source or local proof with deployed proof.

Before you move on

Receipt checklist

  • `/context` confirms the expected project instructions load in a fresh session.
  • The CLAUDE.md contains verified commands and no secret values, volatile status, or generic filler.
  • Shared, local, managed, path-scoped, skill, and auto-memory context have distinct owners.
  • A clean session can state the project boundaries and verification commands correctly.
  • The instruction file remains concise enough for a human teammate to review in one sitting.

Primary sources

Continue with the source

Home
Book
Blog
Calugaru Labs
GitHub
LinkedIn
Email
Theme