Claude Code Intro Lesson 3 of 3

Context Design

Overview

Output quality in Claude Code is a function of context quality, not context volume. This lesson examines the composition of context, the role of CLAUDE.md and memory as persistence mechanisms, and strategies for optimizing the signal-to-noise ratio of inputs.

Context Composition

Context comprises all information available to the model during a conversation:

  • Files read during the session
  • Prior messages in the conversation
  • Project configuration (CLAUDE.md)
  • Persistent memory (user-scoped, cross-session)
  • Tool outputs and command results

Each of these sources consumes context window capacity. Irrelevant information dilutes the model's attention and degrades output quality.

CLAUDE.md: Project-Scoped Configuration

A CLAUDE.md file in the project root is loaded automatically at session initialization. It should contain project-specific knowledge that cannot be inferred from the codebase.

Recommended content:

  • Tech stack and non-default conventions
  • Build, test, and deploy commands
  • Architectural patterns and their rationale
  • Explicit prohibitions with context

Example:

# My Project

## Stack
- Next.js 14 with App Router
- TypeScript strict mode
- Prisma + PostgreSQL

## Commands
- `npm run dev` - Start development
- `npm test` - Run tests
- `npm run lint` - Check code style

## Conventions
- Use server components by default
- API routes in /app/api/
- Keep components under 100 lines

Sizing constraint: CLAUDE.md is loaded on every session. Excessive length imposes a recurring token cost and reduces available context capacity for task-specific work.

Memory: User-Scoped Persistence

Claude Code's memory system stores user preferences, feedback, and project knowledge across sessions. Unlike CLAUDE.md, memory is user-scoped (not shared via version control) and accumulates automatically from conversation interactions. Memory and CLAUDE.md serve complementary roles: shared project rules belong in CLAUDE.md; individual workflow preferences belong in memory.

Signal-to-Noise Optimization

Specify targets precisely

Rather than "help with auth", specify "add JWT validation to the /api/users endpoint". Precision reduces search scope and eliminates assumption-driven errors.

Provide file references

Directing Claude to "the user model in src/models/user.ts" is more efficient than allowing the model to search. Explicit references reduce both token consumption and latency.

State constraints at the outset

"Use only existing dependencies" or "preserve the current API structure" bounds the solution space before generation begins.

Reset context at task boundaries

Residual context from a prior task can mislead the model on a new task. Executing /clear at task transitions prevents cross-contamination.

Anti-pattern: Including entire files when only a single function is relevant. The additional content increases noise without contributing signal, reducing output quality.

Key Takeaways

  • Context quality determines output quality; volume alone does not
  • CLAUDE.md provides project-scoped persistence; memory provides user-scoped persistence
  • Precise file references and constraints reduce noise and improve results
  • Context resets at task boundaries prevent cross-contamination