The Four Commandments of AI Coding: Using Behavioral Constraints to Reshape Agent Workflows

    This article explains why a code-free rule file can trend in open source, and how behavioral engineering shifts the AI coding bottleneck from whether a model can write code to whether it writes the way a team expects. It covers three common failure modes and their root causes, the four rules (think before coding, simplicity first, stay focused, deliver verifiable changes) with concrete rule-file examples, how to embed those rules into version control and CI pipelines, and a review checklist with common anti-patterns.

    Introduction: Why a Rule File With No Code Attracted Attention

    In the open source community, a project containing no executable code has stayed near the top of trending lists. Its core content is a collaboration rule file for AI coding tools. It ships no new model, framework, or runtime. Instead, it uses natural language to define what must be done first and what must not be done at all. This suggests that the bottleneck in AI coding is shifting from “can the model write code” to “does the model write the way the team expects.”

    The industry often classifies this practice as behavior engineering: using context and rules to shape a model’s decision order and the boundaries of its changes during coding tasks. It is worth stressing that a rule file is not a pile of prompt tricks. It translates the collective experience of human software engineering — clarify requirements, make minimal changes, stay focused on the problem, deliver something verifiable — into process constraints a machine can execute.

    Part 1: Three Frequent Failure Modes and Their Root Causes

    1. Coding Before Requirements Are Clear

    When a requirement is ambiguous, the model tends to fill in its own assumptions and produce an implementation directly, so the result drifts from the real intent. The rework cost comes mostly not from writing code but from realigning context and repeating review.

    2. Over-Engineering and Scope Creep

    When asked to change a single style rule or a piece of copy, the model may also introduce an abstraction layer, generic configuration, and new dependencies, and codebase complexity rises quickly. The root cause is that generative models are optimized to “give a complete answer,” while engineering practice values “the smallest change that is sufficient.”

    3. Out-of-Scope Edits and Noisy Commits

    When only file A is supposed to change, the model also adjusts comments, formatting, and logic in files B and C, and review degrades into a spot-the-difference exercise. Noisy commits pollute version history and make rollbacks and fault localization harder.

    These three problems are unrelated to model size or version; they are behavioral inertia. The answer is not to wait for a stronger model but to move constraints earlier in the workflow.

    Part 2: Generalized Statements of the Four Commandments and How to Apply Them

    Commandment 1: Think First, Then Code

    The model must output three things before editing files: its understanding of the requirement, an explicit list of assumptions, and questions that need user confirmation. Example convention:

    1. Before modifying code, provide the following in order:
    2. 1) Restatement of the requirement (no more than 5 items)
    3. 2) List of assumptions (mark uncertain ones)
    4. 3) Questions to confirm (write "none" if there are none)
    5. Proceed to implementation only after confirmation.

    This step makes implicit ambiguity explicit and significantly reduces directional rework.

    Commandment 2: Simplicity Above All

    State clearly that if a conditional check can solve it, no design pattern should be introduced, and if one line can be changed, the whole file should not be refactored. Quantifiable constraints include: no new dependencies, no new directory levels, and no changes to public interface signatures unless the user explicitly asks.

    Commandment 3: Stay Focused on the Problem

    Limit the scope of changes with a file allowlist, and forbid incidental formatting and bulk renaming. Recommended convention:

    1. Only the following may be modified: src/module-a/file1
    2. Forbidden: formatting untouched files, adjusting unrelated comments, upgrading dependency versions
    3. If an out-of-scope change is truly necessary, explain why first and wait for confirmation.

    Commandment 4: Deliver Verifiable Changes

    Every change must come with a verification plan: unit tests, static checks, minimal reproduction steps, or a manual acceptance checklist. Example:

    1. Before committing, provide:
    2. - Change summary (per file)
    3. - Verification commands and expected results
    4. - Uncovered risks and rollback approach

    Part 3: Embedding the Rules Into the Engineering Process

    The rule file should be under version control and reviewed alongside the code. Keep a unified convention at the repository root and add local rules in key directories to form layered “global + local” constraints. Combined with a branch strategy and commit templates, out-of-scope changes can surface during review.

    On the pipeline side, general-purpose capabilities can carry the verification stage: branch protection on the code hosting platform, continuous integration running builds and tests, log services and monitoring alerts tracking anomalies, and an artifact repository managing dependency versions. If build tasks run on a cloud container platform, the checks can be fixed as pipeline stages, reducing manual inspection.

    Part 4: Review Checklist and Common Anti-Patterns

    The review checklist should cover: whether changes stay within the allowlist; whether dependencies were added; whether unrelated formatting exists; whether verification evidence is complete; whether the rollback plan is clear.

    Common anti-patterns include: rules written so long that the model ignores the key points; listing only “what not to do” with no alternative action; and omitting verification requirements, which makes the constraints ineffective. Rules should be short, decidable, and verifiable.

    Conclusion

    The value of the four commandments is encoding engineering consensus as executable constraints, moving AI coding tools from “generate more” to “generate more accurately.” In engineering practice on cloud platforms such as Baidu AI Cloud, combining rule files, pipeline checks, and observability can produce a stable, repeatable AI collaboration workflow in which every change is explainable, verifiable, and maintainable.