AI Coding Rules: The Four Commandments for Taming Code Assistants

    This article explores behavioral engineering, an approach that shifts optimization from raw model capability to how a model acts within a specific engineering context. It examines three common failure patterns of code assistants—guessing instead of clarifying, over-engineering, and uncontrolled change scope—and presents four actionable rules: align before coding, prefer minimal changes, stay focused without opportunistic refactoring, and require verifiable delivery. It also covers how to embed these rules into the engineering workflow, which metrics indicate whether they work, and the limits of what behavioral constraints can achieve.

    A peculiar project has appeared on open-source trending lists: its repository contains no executable code at all. Its core asset is a single behavior specification file written for AI coding tools. It held the top spot for several consecutive days and was starred and shared by a large number of developers.

    What makes this worth examining is that it delivers constraints, not capabilities. It does not change the parameter scale of the underlying model, nor does it introduce a new inference framework. Instead, it uses natural language to state what to do first, what not to do, and when to stop. Such files are typically named project-level context instructions, and their role is to make a code assistant load a unified way of working as soon as it reads the repository.

    The industry shift this reflects can be summarized as behavioral engineering: the optimization target moves from “how strong the model is” to “how the model behaves in a specific engineering context.” As base model capability enters a plateau, the highest marginal return often comes not from switching to a larger model, but from encoding the collective experience of human software engineering into machine-executable rules.

    2. Root Causes: Three Frequent Failures and Their Common Source

    2.1 Substituting Guesses for Clarification When Requirements Are Vague

    When a requirement description has gaps, a code assistant tends to fill in the missing settings itself and produce an implementation directly. This looks efficient on the surface, but it actually transfers uncertainty into the code. Directional deviations are only discovered during review, and rework costs rise exponentially.

    2.2 Over-Engineering in the Name of “Completeness”

    You ask for a change to a button’s color, and it also introduces an abstraction layer, configuration switches, and new dependencies. Models are encouraged during training to generate structurally complete, well-considered content. Carried into an engineering context, this tendency shows up as unnecessary indirection and bloated directory structures.

    2.3 Loss of Control Over Change Scope

    You ask for a change to one piece of logic, and comments, formatting, import order, and even unrelated branches across multiple files get adjusted along with it. Review degrades into line-by-line comparison, and the actual logic change is drowned out by noise.

    The common root of all three is a misaligned objective function: the default orientation of a generative model is to “produce more and cover more broadly,” while engineering delivery requires output that is accurate, minimal in scope, and verifiable. The value of behavioral engineering is to realign the objective function using external rules.

    3. The Method: Four Actionable Behavioral Constraints

    Commandment 1: Align on Understanding Before Writing Code

    Require the tool to output three things before editing any file: its understanding of the requirement, its current explicit assumptions, and its remaining questions. This effectively hard-codes the instinctive reaction of a senior engineer when handed a vague requirement.

    1. Before modifying code, please output:
    2. 1) The goal as I understand it (no more than 5 lines)
    3. 2) The assumptions I am making (list each one and note whether it can be verified)
    4. 3) Questions that need your confirmation (ordered by how blocking they are)
    5. Proceed to implementation only after confirmation is received.

    The key to this rule is not the wording but the ordering: making clarification a mandatory prerequisite stage intercepts most directional errors.

    Commandment 2: Prefer the Minimal Change

    If a conditional check can solve it, do not introduce a design pattern; if a one-line change can do it, do not refactor the whole file; if there is no reproducible performance or security issue, do not add dependencies or configuration options.

    1. Constraints:
    2. - Modify only the files and lines necessary to complete the task
    3. - Do not add abstraction layers, introduce new dependencies, or perform unrelated formatting
    4. - If a broader change seems necessary, explain the reason first and wait for confirmation

    Commandment 3: Focus on the Current Problem; No Opportunistic Refactoring

    Explicitly prohibit “optimization while I’m here” and “unifying the style while I’m here” behaviors, and require that problems found but not addressed be written to a to-do list rather than implemented directly.

    Commandment 4: Delivery Must Be Verifiable

    Any implementation must come with a verification method: a runnable test case, reproducible input and output, or a clear static-check conclusion. A change that cannot be verified counts as incomplete.

    1. Definition of done:
    2. - Explain what was changed and why it was changed that way
    3. - Provide the verification command and the expected result
    4. - If verification is not possible, state the missing environment or information

    4. Implementation: Put the Rules in the Engineering Pipeline, Not the Chat Box

    Rules only take effect reliably once they enter the development process. Three placement layers are recommended:

    • Repository level: maintain a context instruction file in the project root, put it under version control, and review and evolve it along with the code;
    • Task level: reference the relevant constraint items in the ticket or task description so rules do not drift apart from the task;
    • Pipeline level: use static checks, formatting validation, test coverage gates, and change-scope checks to turn “minimal change” and “verifiable” from proposals into hard checkpoints.

    In cloud practice, this mechanism is typically combined with several general-purpose capabilities: a code hosting service to carry the rule files and review records, a pipeline service to run build and test gates, a logging service with monitoring and alerting to track defect density and rework counts in generated code, and a message queue with object storage to handle asynchronous tasks and artifact archiving. If you use the relevant general-purpose capabilities of Baidu AI Cloud, the rule files and gate configurations can be brought into environment isolation management, achieving consistent constraints across development, staging, and production.

    5. Measurement: Using Data to Judge Whether the Rules Actually Work

    Four metrics are recommended for tracking: the number of requirement-clarification rounds (whether upfront questions reduce rework), the number of files changed per task (whether scope is converging), the proportion of formatting-related items in review comments (whether noise is decreasing), and the number of regression defects in generated code (whether quality is improving). Only when all four improve at the same time can you conclude the rules are genuinely effective, rather than merely postponing problems to a later stage.

    6. Boundaries: What Rules Cannot Replace

    Behavioral constraints solve the problem of action consistency. They cannot fill gaps in domain knowledge, nor can they replace architecture decisions and business judgment. The rules themselves require maintenance; too many items will conflict with one another, so follow the principle of “few but hard, verifiable, measurable” and keep trimming them according to the team’s actual pain points. Managing rules as code and evolving them together with the code is the key to keeping this approach effective in the long run.