Project rules file

Also known as: .cursorrules · CLAUDE.md · AI rules file

On this page 7

A project rules file is a plain-text or Markdown file stored in a code repository that gives an AI coding assistant standing instructions about the project: its conventions, commands, architecture and constraints. In AI for coding, an area of artificial intelligence focused on assistants that write and review code, the file is loaded automatically into the model’s context at the start of each session, so the assistant does not need to be told the same facts repeatedly.

Common examples include CLAUDE.md for Claude Code, .cursorrules and the newer .cursor/rules directory for Cursor, and .github/copilot-instructions.md for GitHub Copilot. The cross-tool convention AGENTS.md pursues the same goal with a vendor-neutral filename. All of them work as persistent project memory that travels with the code under version control.

How a project rules file shapes assistant behavior

A project rules file works by context injection. When a session starts, the tool reads the file and prepends its content to the system prompt or the first message, so every later request is interpreted in light of those rules. The model is not retrained; the file simply becomes part of the prompt for every turn.

Because the content occupies part of the context window, every line has a cost in tokens and attention. A long, unfocused file dilutes the instructions that matter, while a short file with precise commands and constraints tends to be followed more reliably. Many tools also support hierarchical loading: a global user file, a repository-level file and files in subdirectories that apply only when the assistant works in that part of the tree.

The table below shows the typical levels at which rules files are loaded and what each level is used for.

ScopeTypical locationUsed for
User levelHome directory configurationPersonal preferences across all projects
Repository levelRepository rootShared team conventions and commands
Directory levelSubfolder of the repositoryRules for one package or service
Local overrideUntracked file next to the shared oneMachine-specific paths or secrets policy
Scopes of rules files

What a good rules file contains

An effective project rules file answers the questions a new senior developer would ask on the first day. It records facts the assistant cannot reliably infer from code alone, and it avoids restating what is already obvious from the file tree.

Content typeExample instructionWhy it helps
Build and test commandsRun unit tests with the project test scriptPrevents guessing wrong commands
Code style rulesUse named exports; no default exportsKeeps output consistent with the codebase
Architecture notesBusiness logic lives in the service layerDirects edits to the right files
Forbidden actionsNever edit generated migration filesProtects fragile or generated code
Workflow conventionsBranch from main; write conventional commitsAligns with team process
Domain vocabularyAn account is a customer, a user is a loginAvoids semantic confusion
Recommended content of a project rules file

Instructions work best when they are concrete and checkable. A rule such as “write clean code” gives the model nothing to act on, whereas “functions longer than 50 lines must be split” is specific enough to follow and to verify in review.

Rules files in different coding tools

Each AI coding tool reads its own filename and format, although the underlying idea is identical. Teams that use several assistants often keep one canonical file and reference or copy it into the others.

FileToolFormat notes
CLAUDE.mdClaude CodeMarkdown; loaded hierarchically from user and project folders
.cursorrulesCursor (legacy)Single plain-text file at the repository root
.cursor/rulesCursorSeveral rule files with metadata for when each applies
copilot-instructions.mdGitHub CopilotMarkdown in the .github folder
AGENTS.mdSeveral agentsVendor-neutral Markdown convention
Common rules file conventions

The main difference between formats is activation logic. A single root file is always loaded, while newer rule systems let each rule declare file patterns or descriptions, so that frontend rules apply only to frontend files. Selective activation saves context but makes it harder to see which rules were actually active for a given answer.

Relation to prompts, specifications and documentation

A project rules file differs from an ordinary prompt in its persistence and scope. A prompt describes one task; the rules file describes the environment in which every task happens.

  • Chat prompt: a single request that disappears after the session.
  • Project rules file: standing, versioned context for all sessions in the repository.
  • Specification: a description of what one feature must do, central to spec-driven development.
  • README: documentation written for humans, often longer and less directive.
  • Linter configuration: rules enforced mechanically, which the model cannot bypass.

A useful principle is to keep mechanically checkable rules in tooling, such as formatters, linters and type checkers, and to reserve the rules file for knowledge that only a language model can apply, such as architectural intent and naming conventions.

Limitations and common mistakes

A project rules file is guidance, not enforcement. The model may still ignore an instruction, especially when the file is long or when the instruction conflicts with the immediate request. Rules files can also become a security concern, because hidden or malicious instructions in a cloned repository are loaded with the same authority as legitimate ones.

  • Overlong files that consume context and bury the essential rules.
  • Stale instructions that describe commands or folders that no longer exist.
  • Contradictory rules across user, project and directory levels.
  • Vague wording that cannot be followed or verified.
  • Unreviewed changes, since edits to the file alter assistant behavior for the whole team.

Teams that rely on these files typically review them like code, keep them under a few hundred lines and update them whenever the build process or architecture changes.

The simple explanation

A project rules file is a note for an AI helper. It sits inside a software project. It tells the AI how this project works and what it must avoid.

Imagine a new colleague who forgets everything each morning. You would leave a note on the desk with the key rules. The AI reads this note at the start of every session. It then follows the house rules without being reminded.

How it is used in practice

A team of six developers maintains a web application with a Python backend and a TypeScript frontend. Their AI assistant kept running the wrong test command, adding default exports and editing generated database files, which then failed in review.

The team adds a CLAUDE.md of about 80 lines to the repository root. It lists the exact test and lint commands, states that generated migration files must never be edited, describes the folder layout and gives three naming conventions. A second, shorter file in the frontend folder covers component patterns.

Over the next month, reviewers report far fewer convention violations in assistant-generated pull requests, and new team members use the same file as a quick orientation guide. The file is reviewed in pull requests like any other code change, so the rules stay accurate as the project evolves.