Here is a complete guide on how to manage CLAUDE.md and optimize your context.
CLAUDE.md is your best friendWhen you start a session, Claude Code automatically reads CLAUDE.md. Instead of having to paste your project rules, tech stack, and file structure into the chat every single time, Claude just knows it. This saves massive amounts of context space for your actual task.
CLAUDE.mdYou have two ways to edit it:
CLAUDE.md in your text editor (VS Code, Vim, etc.) and write it like standard Markdown.CLAUDE.md to reflect this new architecture." Claude will propose the edits, you approve them, and the memory is updated.CLAUDE.md (and what to leave out)A good CLAUDE.md is concise and directive. Think of it as a cheat sheet for a new developer.
Include:
npm run dev, pytest, npm run lint).legacy_auth/ folder."Do NOT include:
CLAUDE.md:# Project: Web Scraper API
## Tech Stack
- Python 3.11, FastAPI, BeautifulSoup4, Uvicorn
- Database: SQLite (for now)
## Commands
- Run server: `uvicorn main:app --reload`
- Install deps: `pip install -r requirements.txt`
- Run tests: `pytest`
## Project Structure
- `/routers` - API route definitions
- `/scrapers` - BeautifulSoup logic
- `/models` - Pydantic models
## Coding Conventions
- Use `async/await` for all routes.
- Always add type hints to function signatures.
- Do not create new requirements files; update `requirements.txt` directly.
Aside from CLAUDE.md, here are the golden rules for context management inside the Claude Code CLI:
/clear religiouslyClaude Code keeps a running history of your conversation. If you have spent 30 minutes fixing a CSS bug, and you now want to write a new database migration, all that CSS history is still in Claude's context, slowing it down and distracting it.
/clear in the Claude prompt. This wipes the conversation history. Don't worry, Claude will re-read CLAUDE.md and your files, so it won't forget the project rules—only the irrelevant chat history.A common beginner mistake is copying a file's code from the editor and pasting it into the Claude Code prompt.
src/components/Header.tsx and fix the bug where the logo isn't loading." Claude will use its tools to open the file, read it, and fix it. This is much more context-efficient than pasting raw text.Instead of saying: "Build a user authentication system with login, signup, password reset, and profile editing." Say: "Let's build the user auth system. First, let's just set up the database model and the signup endpoint." Smaller, scoped tasks keep the context focused on one file or module at a time, resulting in fewer errors.
.gitignoreClaude Code respects .gitignore. If you have massive folders of logs, build artifacts, or dependencies (like node_modules or venv), make sure they are in .gitignore. Claude won't try to read them, which saves context and prevents it from hallucinating based on third-party library code.
CLAUDE.md and update it as the project evolves./clear between distinct tasks.ai