Repository Rules: Can Two Lines Guide AI Tasks?
In this article
Yes, two lines can be enough, provided they are the right two lines and the task is narrow. A short, well-formed repository rule can steer an AI coding agent to follow a specific convention, but it cannot replace a comprehensive specification for complex or ambiguous work.
The Rise of AI Coding Agents and Repo Rules
AI coding assistants have moved from autocomplete suggestions to autonomous agents that can read files, make changes, and even open pull requests. Tools like GitHub Copilot Workspace, Cursor, and various CLI agents increasingly rely on the context within a repository to understand project conventions. A common way to provide this context is through a special file, often named AGENTS.md or CLAUDE.md, that contains instructions for the AI. These files are the modern successor to README.md documentation, but they are specifically designed to be read by an AI before it starts working on a task.
What Two Lines Can and Cannot Do
Two lines of instruction are sufficient for a single, clear constraint. For example, a rule like "Use the `requests` library for all HTTP calls" or "Write all new tests with pytest" is unambiguous and actionable. The AI can parse this and apply it consistently, reducing the need for follow-up corrections. However, two lines are not enough for defining architectural patterns, error-handling strategies, or multi-step workflows. A rule that says "follow the existing code style" is too vague—the AI needs to infer what that style is, which can lead to inconsistencies if the codebase is large or has evolved over time.
How Agents Read and Apply Repository Rules
Most AI agents follow a similar process: they first scan the repository root for instruction files, then load the content into their context window. The instructions are treated as system-level prompts, meaning they take precedence over the AI's default behavior. The key is that the rules are loaded at the start of the session, so they influence every subsequent action. This is why the placement and wording of the rules matter. A rule placed in a nested directory might only apply when the agent is working on files in that directory, while a root-level rule applies globally.
Writing Effective Two-Line Rules
To make two lines work, they must be specific, actionable, and testable. Here are the criteria:
- Specific: Name the exact library, function, or pattern to use.
- Actionable: Use imperative verbs like "use", "prefer", or "avoid".
- Testable: The AI should be able to check if it followed the rule. For example, "Use `f-strings` for all string formatting" is testable via a linter.
A good example of a two-line rule might be:
Use `pathlib` for all file path operations. Never use `os.path` functions.
This is clear and easy for the agent to follow. A bad rule would be "Write clean code"—it's subjective and provides no concrete guidance.
Common Problems and Misconceptions
A frequent misconception is that repository rules are a substitute for a detailed task description. If the task is "refactor the authentication module," two lines of rules won't tell the AI what the desired end state is. Another issue is rule conflicts. If one line says "use `requests`" and another says "use `httpx`", the agent may pick one at random or get stuck. It's also important to remember that rules are not enforced—they are advisory. The AI might ignore them if it thinks the task requires otherwise, especially if the rule is phrased as a suggestion rather than a hard constraint.
Comparing Rule Files, Linters, and CI
Repository rules for AI are not the same as linters or CI checks. Linters (like ESLint or Ruff) enforce style and basic correctness automatically. CI pipelines run tests and build checks. AI rules are a softer layer—they guide the agent before code is written, while linters and CI catch issues after. The best approach is to use all three: AI rules to prevent mistakes, linters to enforce style, and CI to verify behavior. A two-line rule can reduce the number of linting errors the AI produces, but it won't eliminate them.
Frequently Asked Questions
Do I need a separate rule file for each AI tool?
Not necessarily. Many tools recognize a common file like AGENTS.md or CLAUDE.md. However, some tools have their own preferred file names. Check the documentation for your specific AI tool. If you use multiple tools, you can often reference a single file from each tool's config, or you can duplicate the rules into each tool's preferred file.
Can two lines of rules handle a large legacy codebase?
No. A legacy codebase has many inconsistencies and unwritten conventions. Two lines can only cover the most critical, broad rules. For a large project, you'll need a more comprehensive file that outlines the architecture, common patterns, and known pitfalls. Consider starting with two lines and expanding as you see the agent make mistakes.
What if the AI ignores my two-line rule?
First, check the wording. Is it too vague? Try making it more specific. Second, check if the rule conflicts with something else in the repository, like a README or existing code. Third, some agents have a "temperature" or "creativity" setting—lowering it can make the AI follow instructions more literally. Finally, you can add the rule to your task prompt as well, so it appears twice.
Should I put rules in a README or a separate file?
A separate file is better. READMEs are for humans and often contain setup instructions, badges, and links. Mixing AI instructions into a README can confuse both humans and AI. A dedicated file like AGENTS.md is cleaner and can be easily referenced by multiple tools.
Can a rule file be too long?
Yes. AI models have a limited context window. If the rule file is longer than a few hundred lines, it might consume too much context, leaving less room for the actual task description and code. Keep it concise. If you have many rules, prioritize the most important ones and consider splitting them by directory or module.