Home › Agent workflows › Context management for long agent sessions CLAUDE.md

Context management for long agent sessions CLAUDE.md

CLAUDE.md practices for keeping Claude Code effective in long sessions: lean memory, notes files, subagents, and resets.

Claude Code (CLAUDE.md)Agent workflows

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

CLAUDE.mdDownload  
# CLAUDE.md: Working in long sessions

## Keep this file lean
- This file loads every session. Keep it under ~100 lines: commands, architecture map, conventions, and gotchas. Move topic-specific rules into `.claude/rules/*.md` with `paths:` so they load only when relevant, or link docs with `@docs/architecture.md` imports.
- When you learn a durable fact about the project (a command, a pitfall), propose a one-line addition here rather than relying on chat history.

## Manage context
- Before big tasks, read only the files you need; use search (Grep/Glob) instead of opening whole directories.
- Delegate broad exploration ("find all callers", "how does auth work") to a subagent and keep its summary, not the raw output.
- Keep a working notes file for multi-step work: `notes/<task>.md` with the goal, decisions, done/next checklist, and commands that worked. Update it at milestones.
- When switching to an unrelated task, suggest `/clear`. Before compaction or a reset, make sure the notes file is current so work can resume.
- Prefer small diffs and frequent test runs over long chains of unverified edits.

## When context is getting stale
- Re-read files before editing them if they may have changed (don't edit from memory).
- If you're unsure what was already done, check `git status`/`git diff` and the notes file instead of guessing.

## Project
- Commands: `npm test`, `npm run lint` (edit me)
- Architecture notes: `@docs/architecture.md` (edit me)

More: all Agent workflows rules · all Claude Code (CLAUDE.md) rules

Related rules

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

Code review prompt file (Copilot)

A Copilot prompt file (/review-changes) that reviews the current changes and reports issues by severity without editing.

GitHub CopilotAgent workflows

Code reviewer subagent (Claude Code)

A Claude Code subagent definition that reviews the current diff for bugs, security, and tests, reporting by severity.

Claude Code (CLAUDE.md)Agent workflows

/commit slash command (Claude Code)

A Claude Code /commit slash command that reviews staged changes and writes a Conventional Commits message.

Claude Code (CLAUDE.md)Agent workflows

Git commits & PRs AGENTS.md

AGENTS.md rules for how agents commit: Conventional Commits, atomic changes, safe git commands, and PR descriptions.

AGENTS.mdAgent workflows

Create README prompt file (Copilot)

A Copilot prompt file (/create-readme) that writes or updates a README from the actual repo contents and verified commands.

GitHub CopilotAgent workflows

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.