Free 15-minute callFree 15-minute call →
艾维禾砺Vibe Coding LabIvheli · 1:1 coaching
Practical path

How to write a rules file that actually works

A rules file is not better the longer it is: global for habits, project root for conventions, subdirectories for exceptions; the closer to the concrete work, the higher the priority.

Updated 2026-11-112 min readFree guides · 78/96

Why a rules file is needed

Every new session means repeating: “run the tests first”, “do not add new dependencies”, “run lint before committing”. Said too often, it gets missed, and AI forgets too.

The point of a rules file: read automatically before work starts, so the conventions are always there.

Layers and priority

A typical three-layer structure:

  1. Global: personal working habits that apply to every project
  2. Project root: this repository’s conventions
  3. Subdirectories: rules for particular modules

Reading usually goes from global to project, and from the root to the current directory; rules closer to the current directory appear later and have higher priority. Override files with the same name take precedence over ordinary files.

What goes in the global file

  • Common commands: how to run tests, how to format
  • Dependency preferences: which package manager, whether to confirm before adding dependencies
  • Personal habits: comment language, commit message format

What goes in the project root

  • Where the project structure and entry points are
  • Checks that must be done before committing
  • Code conventions: naming, error handling, logging
  • What must not be touched: legacy interfaces, generated files

What goes in a subdirectory

  • Module-specific commands (such as make test-payments)
  • Special processes (such as who must be notified before changing the config)
  • Exceptions when conflicting with the global rules

Example:

# services/payments/AGENTS.override.md

## Payment module rules
- Use make test-payments, not npm test
- Do not change field names in the clearing file
- Changes involving amount calculations must have human review

Writing suggestions

  • Short: keep the main file to a few dozen lines; link to documents for details
  • Checkable: make each rule verifiable with a command or check item where possible
  • State exceptions: explain when it is acceptable to break the rule
  • Do not pile on formatting rules: leave formatting to automated tools

How to confirm it takes effect

Have AI answer “which instruction sources have you read, and what are they”. Check:

  • Whether global, project and subdirectory files were all read
  • Whether subdirectory rules override the upper layers
  • Whether anything was truncated or ignored

Common problems

  • The file is empty → it is ignored outright
  • An override file exists above → ordinary files are overridden
  • Changes do not take effect → restart the session or the tool
  • Too long and truncated → split into subdirectories, or adjust the size limit

Checklist

  • The global file holds general habits
  • The project root holds repository conventions and check commands
  • Special modules have their own rules files
  • Every rule is as verifiable as possible
  • Have had AI restate which instruction sources it read
  • Rule updates are shared with the team

Reference: key points adapted from OpenAI’s official documentation “Custom instructions with AGENTS.md”, rewritten for general tools and practical use.

Questions

Are AGENTS.md and CLAUDE.md the same thing?

They serve the same purpose: both are instruction files for AI coding tools. Different tools use different file names, and many tools also support custom names or reading several files; the content and layering approach are the same.

Which layer should a rule go in?

Global holds personal habits (such as test commands and dependency preferences), the project root holds repository conventions (structure, pre-commit checks), and subdirectories hold special rules (the payment module uses its own tests). Rules closer to the current directory have higher priority.

Why do the rules I wrote not take effect?

Common causes: the file is empty and ignored, an override file above it overrides it, the tool was not restarted to reread the files, or the rules are too long and get truncated. First have AI restate which instruction sources it has read.

Want to apply this to your own work?

Read next

Share this article

Where should your idea start?

Bring an idea or a question to a free 15-minute call. Confirm the conversation language and time when booking.

Book a free 15-minute call

Where should your idea start?

Free 15-minute call →Free guides

Book a free 15-minute call

Contact

Booking formEnterprise AI implementation & system developmentSee enterprise services (official site)
Add us on WeChat, mention Vibe Coding and tell us what you want to do
Add us on WeChat, mention Vibe Coding and tell us what you want to do