Project Memory Files for AI Coding Tools: A Practical Design Guide
Learn how to structure, maintain, and validate project memory files for AI coding tools. This guide covers layered instructions, tool-specific loading behavior, reusable templates, token costs, and security checks to keep project guidance actionable and up to date.
1. What Is a Project Memory File?
A project memory file is a Markdown file stored in a code repository. An AI coding tool provides its contents to the model as project instructions when a session starts or when relevant files are accessed.
It addresses a specific problem: every new session begins without knowledge of the project’s frameworks, prohibited coding patterns, or test commands. Writing this information once makes it reusable across sessions.
Loading behavior varies by tool. Some tools include the contents in the system prompt, others inject them as rules on demand, and some read them only when files match a particular path. Before writing a memory file, consult the tool’s official documentation to confirm where it belongs and when it takes effect.
2. Organize Instructions in Three Layers
A memory file can be organized into three layers.
The top layer explains what the project is: its name, current stage—development, testing, or release—and business objective. Keep this section brief so the model understands the business context when proposing solutions.
The middle layer records technical facts and constraints: precise language and framework versions, build and test commands, directory structure, and prohibited APIs or libraries. These details directly affect whether generated code runs, so commands should be ready to execute.
The bottom layer contains examples and past mistakes. Include one or two examples of approved coding patterns, along with mistakes the model has made and their corrections. Be specific: “Querying the database once per item inside a loop caused API timeouts; use a batch query instead.”
| Section | Purpose | What to write | Common mistake |
|---|---|---|---|
| Project identity | Align work with business goals | Name, stage, and a one-sentence objective | Using promotional language that offers no basis for decisions |
| Technology stack | Specify dependency versions | “Node.js 20.x, Express 4.18” | Saying only “Use Express,” without a version |
| Common commands | Enable the model to verify its work | npm run test |
Keeping an old command after it has been renamed |
| Coding standards | Define measurable output requirements | “Keep each function to 50 lines or fewer” | Using vague instructions such as “Keep it concise” |
| Prohibited practices | Prevent known mistakes | “Do not call the database inside loops; use batch queries instead” | Listing prohibitions without alternatives |
| Past mistakes | Prevent recurring problems | Three entries: problem, cause, and correct approach | Recording issues too vaguely to identify the relevant scenario |
3. Writing Principles
Put critical rules first. Models often give more attention to the beginning and end of the context, although the effect depends on the model and context length. Place non-negotiable rules near the top, then check actual generated results to see whether they are followed.
Use measurable limits. “Keep functions short” cannot be evaluated consistently. “Keep function bodies to 50 lines or fewer” can be checked directly.
Pair prohibitions with alternatives. When writing “Do not use X,” add “Use Y instead.” This makes the instruction easier to follow and avoids leaving the model to guess.
Split files when they become too long. As a practical guideline, once a file exceeds roughly 200 lines, key rules can become diluted and per-session token usage increases. Move domain-specific guidance into subdirectories or separate rule files that the tool can load as needed.
4. Multiple Instruction Files and Merge Rules
Instruction files commonly live in three places: the user directory, the project root, and subdirectories. Tools handle merging differently. Some load all matching files; others apply precedence rules.
When instructions conflict, do not rely on implicit behavior. State explicitly which guidance should take precedence, and verify that this matches the tool’s documented behavior.
The following are common conventions at the time of writing. They may change with tool updates, so consult the official documentation.
| Tool | Common files | Location | Loading behavior |
|---|---|---|---|
| Claude Code | CLAUDE.md |
User directory ~/.claude/, project root, and subdirectories |
User-level and root files load at session start; subdirectory files load when files in those directories are read |
| Cursor | .cursor/rules/*.mdc, AGENTS.md |
Within the project | Rules can use glob patterns to target specific file paths |
| GitHub Copilot | .github/copilot-instructions.md |
Within the project | Path-specific instructions can be placed under .github/instructions/ |
As a general convention, instructions with a narrower scope and closer to the current file usually take precedence over broader guidance. The exact behavior remains tool-specific.
Do not commit personal preference files to the repository. Add them to .gitignore so they do not affect other team members.
5. An Adaptable Template
All values below are examples. Replace them with the actual details of your project before use.
# Project Memory: Order Service## Project Identity- Name: order-service- Stage: Pre-release testing- Objective: Support concurrent cross-border order placement,with a load-testing target of 50,000 orders per day## Technology Stack- Java 17, Spring Boot 3.2.4- MySQL 8.0, HikariCP connection pool, maximum pool size: 20## Common Commands- Build: `./mvnw -q package -DskipTests`- Unit tests: `./mvnw test`- Start local dependencies: `docker compose up -d`## Coding Standards- Keep each method to 50 lines or fewer- Set a timeout for every external API call; default: 2 seconds- Add corresponding unit tests for every new endpoint## Prohibited Practices- Do not run database queries inside loops; use batch queries instead- Do not use the legacy java.util.Date API; use java.time instead## Past Mistakes- Problem: Querying inventory separately for each order inside a loopcaused API timeouts during peak traffic- Cause: Each order triggered a separate inventory query- Correct approach: Fetch inventory for all SKUs in one query,then match records by SKU in memory
6. Validation Checklist
After creating or editing a memory file, check each item:
- Every rule has a clear pass-or-fail criterion.
- Versions, commands, and paths are valid in the current repository.
- Every prohibition includes an alternative.
- Every past-mistake entry includes the problem, cause, and correct approach.
- The file contains no secrets, internal domains, account details, or nonpublic architectural information.
- Dependency upgrades and command changes are reflected in the file.
- Personal preference files are listed in
.gitignore.
7. Token Usage and Model Selection
Token usage is directly related to file length, but there is no universal conversion ratio. To measure the impact, start separate sessions for the same task using the full file and a shortened version. Compare the input token counts or costs reported by the tool.
Some teams divide work between models: a more capable model handles complex architectural questions, while a lower-cost model handles routine code generation with only the relevant file excerpts. Whether this saves money should be measured in your own project rather than assumed.
8. Security Risks
Memory files often contain internal details and should be included in code review.
A common risk is accidentally packaging internal configuration into release artifacts. Add CI checks that scan these files for secrets, and verify that build and packaging rules exclude AI configuration directories unless publishing them is intentional.
