CClaude Code Catalog
All Patterns

Context Window Management

WorkflowIntermediate

Large codebases easily exceed Claude's context window. This pattern provides strategies to keep sessions productive: use /compact to summarize history, structure CLAUDE.md to front-load critical information, split tasks into focused sessions, and use file-level summaries instead of loading entire modules. Includes a decision tree for when to start a new session vs. compact the current one.

contextmemorylarge-codebasesession-management

Pattern Code

# Context Window Management Pattern ## Strategy 1: CLAUDE.md as Persistent Memory ```markdown # CLAUDE.md — Context Anchors ## Architecture Overview (always loaded first) - Monorepo: apps/ (3 apps), packages/ (7 shared packages) - Entry points: apps/{web,api,admin}/src/index.ts - Shared types: packages/types/src/index.ts ## Key Files (read these before making changes) - Database schema: packages/db/schema.ts - API routes map: apps/api/src/routes/index.ts - Environment config: packages/config/src/env.ts ## Recent Decisions (prevents re-discussion) - 2024-03-01: Switched from REST to tRPC for internal APIs - 2024-02-15: Adopted Drizzle ORM, removed Prisma - 2024-02-10: All new components use Radix UI primitives ``` ## Strategy 2: Session Splitting ```bash # Session 1: Analysis only — output to file claude -p "Analyze src/services/ and list all functions that need error handling improvements. Output to docs/error-audit.md" --output-file error-audit.md # Session 2: Fix based on analysis (fresh context) claude -p "Read docs/error-audit.md and fix each listed issue. Work through files one at a time." ``` ## Strategy 3: Compact Triggers ```markdown # CLAUDE.md — Compact Rules ## When to /compact - After completing a distinct subtask - Before switching to a different module - When you notice repeated file reads ## Compact Summary Format Always include in compact summary: 1. What was accomplished 2. Current file being worked on 3. Remaining items from the task list 4. Any blockers or decisions made ``` ## Strategy 4: Focused File Loading ```bash # Instead of "read the entire src/ directory" # Ask Claude to read specific files claude -p "Read only src/services/auth.ts and src/middleware/validate.ts. Fix the token refresh bug described in issue #234." ```

Copy this pattern into your project configuration to implement.

Terminal Preview

Context Window Management

About Context Window Management

Claude Code patterns are proven architectural designs and workflow structures that help you tackle complex development scenarios. Context Window Management is a Workflow pattern at the Intermediate level that provides a tested, repeatable approach you can adapt to your projects for more efficient and consistent results.

Related Patterns