How to Write a Project Memory File That Helps AI Coding Assistants Avoid Wasted Effort

    This guide explains what a project memory file is and how to set up the environment needed to create one. It covers three principles for writing an effective file: keep it concise, use imperative instructions, and record known pitfalls. It also describes a three-layer memory structure, a reusable Markdown template, ways to check that the rules take effect, common mistakes, and how to maintain the file over time.

    1. Why a Project Memory File Is Needed

    A project memory file is the main way AI coding tools understand the context of a project. It is usually a Markdown file placed in the project root directory. Naming conventions differ between tools. For example, Claude Code reads CLAUDE.md, while some other tools use AGENTS.md or their own rules directories. Choose the file name according to the official documentation for the tool you use.

    Each time an AI assistant starts a session, it does not know your project. It does not know the versions in your tech stack, how the directories are organized, or your code style. Without this information, the generated code often does not match team conventions, and people have to revise it repeatedly.

    A memory file writes this implicit knowledge down. The tool reads it automatically at the start of each session, so the model has background context to work from. The result depends on the quality of the file and on how well the tool supports it. In team practice, a memory file usually reduces the number of times the same corrections are needed, but it cannot guarantee that every output fully follows the standards.

    2. Preparation

    First, confirm that the basic environment is ready.

    1. Version control: Install Git and make sure the project is inside a Git repository. This lets you review the changes the AI makes and roll them back if needed.
    2. Runtime: If the project depends on Node.js, install the LTS version. Not every AI coding tool requires Node.js. Check the installation documentation for your tool to see whether you need it.
    3. Tool installation: Get the installation command from the tool’s official documentation. Do not run scripts from unknown sources. Before running a script, confirm that its URL comes from the official domain.
    4. Network: Some tools need internet access during installation and use. If your corporate network requires a proxy, configure the proxy environment variables before you install.

    After installation, run the tool’s built-in version command, such as <tool command> --version, to confirm the installation succeeded. Use the exact command from the official documentation. During installation, the tool usually creates a configuration directory in the user’s home directory. This directory may contain a global configuration file, a global memory file, and session history. The exact path varies by tool and operating system.

    3. Three Principles for Writing a Good Memory File

    3.1 Concise beats exhaustive

    The memory file is loaded into the context every time. Long content takes up available space, and the important information gets diluted. Keep the file within a few hundred lines. Include only information the AI would get wrong without, such as exact build, test, and lint commands, tech stack versions, the responsibilities of core directories, and naming and indentation rules.

    3.2 Use imperative instructions

    The memory file’s job is to give the AI rules. Compare these two styles:

    • Descriptive: “This project uses TypeScript, and the code is in the src directory.”
    • Imperative: “Write all new code in TypeScript. Place business logic under src/services. Route files should only receive requests and call services.”

    The imperative style tells the AI what to do and where the boundaries are.

    3.3 Record the pitfalls you have hit

    A team’s most valuable lessons are often a list of things to avoid. For example:

    • Do not modify files under the legacy/ directory. It is frozen.
    • Generate database schema changes through migration scripts. Do not write SQL changes by hand.
    • Run lint and unit tests before committing.

    Rules like these cannot be inferred from the code. Writing them down reduces rework.

    4. Layered Memory: Global, Project, and Subdirectory

    A mature approach divides memory into three layers.

    1. Global layer: Stored in the configuration directory under the user’s home directory. It records personal preferences, such as the response language and preferred coding patterns. It applies to all projects.
    2. Project layer: Stored in the project root. It records the tech stack, common commands, and team conventions. The file can be committed to Git and shared with the team. This layer is the most important.
    3. Subdirectory layer: In large repositories, place local memory files in subdirectories. Some tools automatically load the matching rules when you work on files in that directory. For example, a frontend directory can state that components are written with the Composition API.

    With this structure, personal preferences stay out of the team repository, project conventions are written once, and local rules stay close to the code they govern. Not every tool supports all three layers. Before you rely on this structure, check how the tool loads memory files. If a tool does not load subdirectory files, merge the key rules into the project layer, or describe them manually in the task prompt.

    5. A Reusable Template

    The template below can serve as a starting point. Replace the content in square brackets with your project’s actual information.

    1. # Project Overview
    2. - Tech stack: [language and version] + [framework and version]
    3. - Package manager: [for example, pnpm]. Do not mix in other package managers.
    4. # Common Commands
    5. - Install dependencies: [actual command]
    6. - Build: [actual command]
    7. - Test: [actual command, and whether only affected tests run]
    8. - Lint: [actual command]
    9. # Directory Conventions (example, fill in with the project's real directories)
    10. - src/services: business logic
    11. - src/routes: request handling and parameter validation only
    12. # Code Standards
    13. - [module standard, for example, use ES Modules consistently]
    14. - [error handling approach, for example, always throw custom error types]
    15. - [comment or documentation requirements]
    16. # Prohibited Actions
    17. - Do not modify files under [directory].
    18. - Do not add new third-party dependencies without a stated reason.

    When you fill in the template, keep two points in mind. First, every command must run in the project. A wrong command makes the AI fail repeatedly. Second, make the rules specific. A vague requirement such as “keep the code clean” does not guide the AI’s behavior.

    6. How to Check That the Rules Take Effect

    After you write the file, test it with small tasks.

    1. Ask the AI to restate the key rules in the memory file. If the restatement leaves things out or contains errors, the file may not be loaded. Check the file name and path.
    2. Give the AI a small task, such as adding a simple API endpoint. Check whether it uses the correct directory, naming, and error handling.
    3. Ask whether the AI would modify files in the legacy directory. Check whether its answer follows the prohibited actions.
    4. Record each failure. Use these cases as the basis for the next revision.

    7. Common Mistakes

    • Files that are too long: Thousands of lines of rules bury the key instructions.
    • Conflicting rules: The project layer and the global layer give different requirements for the same issue, which makes the AI’s behavior unstable.
    • Outdated rules: The tech stack has been upgraded, but the file still refers to the old version.
    • Descriptive writing: The file explains the project background at length but contains no actionable instructions.
    • Broken commands: A build command has been renamed, but the file was not updated. The AI fails every time it runs the command.

    8. Ongoing Maintenance

    Whenever the AI makes a mistake and you have to correct it verbally, turn the correction into a rule and add it to the memory file. During periodic reviews, delete outdated rules and merge duplicates. Check the file after each major version upgrade, and include memory file updates in the team’s code review process.

    The value of a memory file lies in making team knowledge visible and shareable. Write a first version, use it for a while, and then revise it based on the failure cases. Over time, it will fit the project’s actual conditions.