Best Practices for AI Coding Assistant Project Convention Files

    A well-crafted project convention file can dramatically improve how AI coding assistants understand your codebase. This guide explains what to include, why it saves tokens and context, and how to avoid common pitfalls when writing your own.

    Best Practices for AI Coding Assistant Project Convention Files

    Why Your AI Coding Assistant “Doesn’t Understand” Your Project

    Over the past year, AI coding assistants have evolved from novelty tools into daily companions for many developers. Yet a common complaint persists: the AI is capable, but it keeps producing code that doesn’t fit the project — naming conventions don’t match, layering structures are wrong, and it insists on reinventing utility classes that already exist in the codebase.

    The problem isn’t the AI’s ability — it’s an information gap. Imagine hiring a technically strong new colleague but giving them no onboarding documentation, then verbally explaining the project background, tech stack, coding standards, and historical pitfalls every time you assign a task. The communication cost would be enormous. AI coding assistants face exactly the same situation: they handle anything within their capabilities with ease, but they know nothing about your project.

    The industry-standard solution is to place a project convention file in the project root directory (commonly a Markdown file that the tool automatically reads at startup). This file acts as the project’s “team charter”: the rules you write down are treated as default conventions to be followed throughout the collaboration.

    What a Good Convention File Should Contain

    Without a convention file, the tool still works; with one, collaboration efficiency improves dramatically. A practical convention file typically includes four sections:

    1. # Project Convention File
    2. ## Project Overview
    3. User order system. Tech stack: Java backend framework + persistence framework + relational database
    4. ## Common Commands
    5. - Local run: use the build tool's run command
    6. - Unit tests: use the build tool's test command
    7. - Package build: use the build tool's package command (skip tests)
    8. ## Coding Standards
    9. - Naming: classes and methods use camelCase; database table names use snake_case
    10. - Layering: the controller layer only handles parameter validation and routing; business logic belongs in the service layer
    11. - Data access: hardcoding SQL is forbidden; manage all queries through mapping configuration files
    12. ## Known Pitfalls
    13. - The order table's creation-time field is stored in UTC; the frontend must convert it to the local timezone
    14. - Third-party payment callback URLs must use HTTPS; local debugging requires a tunneling solution

    Each of the four sections plays an irreplaceable role:

    • Project Overview gives the AI a holistic understanding of the tech stack and domain, preventing it from solving problems using assumptions from a different stack;
    • Common Commands saves the AI from trial-and-error guessing about build and test procedures, especially in projects with non-standard scripts;
    • Coding Standards directly guarantees output quality. AI models default to “generic best practices,” but generic practices aren’t necessarily your team’s practices;
    • Known Pitfalls is the highest-value section — these are often lessons learned from production incidents. Writing them down means the AI directly inherits the team’s collective memory.

    Why Convention Files Save Tokens: Understanding the Context Mechanism

    To appreciate the value of convention files, you need to understand how AI coding assistants work. These tools have a limited context window: the total amount of information “visible” in each conversation has an upper bound, including your prompts, the code it reads, conversation history, and automatically loaded project files.

    Without a convention file, the AI can only understand your project in two ways: actively reading many source files, or asking you questions during the conversation. Both paths consume precious context space and are inefficient — in a codebase with hundreds of thousands of lines, building an understanding purely by reading code often takes multiple rounds.

    The essence of a convention file is injecting high-density human knowledge at minimal context cost. A concise convention file typically costs only a few hundred to a thousand tokens, yet it can replace multiple rounds of Q&A and extensive file scanning. The difference in real projects is obvious: without a convention file, getting the AI to modify a feature averages three to four rounds of conversation just to explain the background; with one, the very first response usually conforms to project standards, and both token consumption and interaction rounds drop significantly.

    This also explains why “context engineering” is becoming a core skill in AI-assisted development: whoever uses the limited context window more efficiently gets higher output quality from the same tools.

    Writing Principles and Common Pitfalls

    1. Longer Is Not Better

    This is the most common mistake. Some developers write convention files hundreds of lines long, stuffing in architecture documents, API inventories, and database schemas. The result: since the convention file is loaded into context on every conversation, the longer it is, the less context remains for the actual task — diluting the key information. The right approach is to write only what the AI doesn’t know but must know, keeping it to a reasonable length, typically a few dozen to one or two hundred lines. Anything the AI can discover by reading the code once doesn’t need to be written down.

    2. Write “Rules,” Not “Wishes”

    Statements like “write elegant code” or “add clear comments” have almost no binding effect on AI. Effective rules should be actionable and verifiable:

    • Bad: “Pay attention to database operation standards”
    • Better: “All database queries must be defined through persistence-layer mapping files; concatenating SQL strings in code is forbidden”

    3. Maintain It Continuously as the Project Evolves

    A convention file isn’t a one-time task. When the tech stack is upgraded, standards change, or new pitfalls are discovered, the file should be updated accordingly. Consider putting the convention file under version control and reviewing and evolving it alongside the code. When new team members join, they read it; when collaborating with AI, it’s loaded automatically. One file serves two scenarios — maintenance cost is halved while the benefits double.

    4. Organize in Layers: Global and Module-Level Conventions

    For large monorepos or multi-module projects, use a layered strategy: place global conventions in the root directory and module-specific supplementary conventions in key subdirectories. When the AI works in a given directory, it prioritizes the local rules — ensuring relevance while keeping the global file lean.

    5. Control What Gets Auto-Loaded

    Keep in mind that anything automatically loaded continuously occupies context. Beyond keeping the convention file itself concise, review other configurations loaded by default and regularly clean up outdated content. Treating the context window as a scarce resource is a fundamental skill for using AI coding tools effectively.

    A Collaboration Upgrade That Starts with One File

    Looking back, the value of a convention file goes far beyond “saving tokens.” It pushes teams to do something they should have done long ago: making tacit knowledge explicit. In many teams, standards live in senior members’ heads or are scattered across chat logs and documentation platforms — invisible to newcomers and AI alike. Writing a convention file is itself an exercise in consolidating engineering practice.

    If you’re using or planning to adopt AI coding tools, start today by adding this “team charter” to your project: begin with the Project Overview, Common Commands, and Coding Standards sections, keep it within one screen, and each time the AI produces unexpected output, ask yourself “is there a rule I forgot to write down?” — then iterate. Within a few weeks, you’ll find the AI is no longer the new colleague who needs constant briefing, but a partner that truly understands your project.