Writing Specs That Produce Reviewable Agent Pull Requests
Structure specs in phases with explicit criteria so agents produce reviewable pull requests.

Writing specs for coding agents is a pull request design problem. A spec built for human interpretation leaves decisions that an agent will fill with plausible defaults. Explicit behaviors, bounded phases, and testable acceptance criteria make those decisions visible before implementation, so the resulting PR can be understood, checked, and trusted.
Why a spec written for human readers reliably produces an unreadable pull request
Human-readable product requirements documents depend on judgment outside the document. An engineer can infer intent, ask about an omission, and distinguish a product requirement from an illustrative suggestion. An agent cannot safely rely on that shared understanding when it runs. When instructions leave gaps, the agent fills them with plausible defaults, turning unspecified choices into implementation decisions.
Those decisions become part of the diff. An ambiguous login requirement can leave the agent to choose session strategies, error shapes, edge-case handling, and refactoring targets that nobody approved. Even a more capable model cannot tell whether a decision was left for later on purpose or left out by mistake. Both look like missing information. The reviewer then has to reconstruct which changes express the intended feature and which express the agent’s interpretation, even when the code itself is correct.
What makes a pull request reviewable in the first place
A reviewable PR lets its reviewer reconstruct intent, verify behavior without reading every line, and make a confident merge decision. That is the spec author’s target. A small, bounded diff helps because the reviewer can hold one coherent change in mind rather than infer a common purpose across unrelated edits. Even when the code is correct, a sprawling diff can hide why it changed.
Behavior also needs to be checkable against a prior decision. Compilation alone cannot establish that a feature does what was requested, and criteria written after implementation risk describing what the agent happened to build. Provenance completes the standard by distinguishing specified outputs from agent-generated judgment calls. The reviewer needs to check those calls more closely than choices already settled in the spec. The author therefore works backward from the eventual review, defining scope, observable outcomes, and decisions before execution begins.
Planning before executing with read-only mode
Plan Mode creates a read-only interval in which the agent can explore the existing codebase and draft a structured spec without changing code. The recommended workflow starts with a high-level goal, followed by that exploration and a human review of the draft. Execution waits for approval.
People have the most chance to catch and correct mistakes during that review. Smuggled assumptions, smoothed-over edge cases, and quietly dropped requirements appear as spec text that can be corrected before implementation. Once corrected, the approved document can be saved as SPEC.md to anchor later sessions and reduce context loss as conversation history grows. Planning does take time before code generation starts. Its value is avoiding the much harder work of untangling a 500-line PR that has drifted from intent.
Structuring the spec so the agent can sequence its own work
A unified feature description explains the whole product change but leaves its construction order implicit. An executable spec instead divides work into sequential phases with explicit dependencies and bounded scope. For example, a monolithic login description can combine valid credentials, session creation, invalid attempts, and account lockout in one assignment. A phased version can separate successful login and session behavior from failure handling and lockout, stating what the later phase depends on. Each phase ends with working code that can be checked on its own.
The document’s organization should reinforce those boundaries. Anthropic engineers recommend separate sections for background information, instructions, tool guidance, and output description because the sections tell the model how to use each kind of information. The spec also needs direct references to the existing codebase, including files to touch, conventions to honor, and patterns already in use. Repository context narrows the implementation choices still open. Without it, an agent can write clever code that works on its own but clashes with the rest of the system.
Writing acceptance criteria the agent can verify itself
“Users can log in” states an aspiration without defining success. A contract makes the behavior explicit. The stronger version is “a valid email and password returns a session cookie; an invalid pair returns a 401 with no user enumeration; five failures locks the account for a fixed period”. To remove the remaining ambiguity, the spec must also decide what that fixed period is.
The authoring test is whether a CI gate, test suite, or human tester can confirm a criterion without further interpretation. “Handle errors gracefully” fails that test because it supplies no ground truth against which to compare the implementation. Criteria should come first, letting the definition of done bring the rest of the task into focus. They then serve as the test specification, making alignment between requirements and tests visible in the PR. At each unresolved choice, the useful question is whether an agent’s guess would be acceptable. If not, the decision belongs in the spec.
Telling the agent what not to touch
Acceptance criteria say what the result must do, but they do not protect everything else. An agent can satisfy a login contract while also refactoring stable code that was never part of the assignment. The file alone may not explain its constraints. API contracts, regulatory requirements, and downstream dependencies can all make apparently improvable code unsuitable for incidental change.
A “DO NOT CHANGE” section makes those boundaries explicit. In a login spec, it can protect existing API contracts and name unrelated refactoring as out of scope, rather than relying on their absence from the task description. Where a change might be justified but needs approval, an “ask first” instruction distinguishes it from a hard prohibition. The broader always, ask first, and never tiers separate defaults, decisions requiring confirmation, and hard stops. These protections narrow the diff to intended work and give the reviewer a clearer basis for questioning changes beyond that boundary.
Sizing phases so the resulting PR can actually be reviewed
As a reviewability heuristic, a phase should contain work that can be built and verified in an afternoon. The practical test is whether the PM or engineer can manually verify the completed unit when the agent reports it ready. That checkpoint prevents unresolved scope drift from passing into the next phase, where it becomes harder to isolate.
An 800-line diff can therefore indicate a scoping failure. Splitting it after implementation leaves the reviewer to recover boundaries that the spec should have established beforehand. The operating rule is one task, one PR, with each executable task spec scoped to that reviewable unit even when a broader plan contains several phases. Dependencies still govern the order of execution. When components do not depend on one another, their task boundaries also let agents run in parallel without doing the same work or forcing dependent changes to happen at the same time.
What the AGENTS.md file does for every agent that runs against the repo
AGENTS.md holds the project context that stays in place across task specs. It records build, test, and lint commands, no-go areas, naming conventions, and the always, ask first, and never tiers that apply throughout the repository. Keeping them in one persistent artifact lets phase specs concentrate on their particular behaviors and acceptance criteria, reducing repetition of team conventions.
The file also houses the repository-level pre-launch checklist, including CI gates for tests, types, static analysis, and secret scanning. A PR size limit, a prohibition on agents merging their own work, and a network-restricted sandbox requirement belong there too. Like code, the file should be versioned and updated when incidents reveal what is missing. A project-wide lesson then becomes part of the starting context for future work instead of remaining with the people who handled the incident.
How CI gates and labeled agent commits close the review loop
CI gates turn verifiable requirements into merge conditions. Tests should check the behavior criteria, while type checks, static analysis, and secret scanning check that the other project requirements are met. A CI-enforced size limit preserves the review boundary, and the rule against agents merging their own work reserves the final decision for human review.
The agent should also supply evidence with the PR, including test output, screenshots, and a log of skipped work. Reviewers can inspect that evidence, saving the work of reconstructing every check from scratch. Labeled agent commits or an “agent-generated” PR tag establish provenance, while fuller attribution to the source, harness, model, and credential allows teams to compare runs and measure what actually shipped. Ramp built Inspect on Linear’s API for agents, and Coinbase built Forge on Linear’s Agent SDK. These integrations connect specs, customer feedback, and code through the ticketing system, making the PR the artifact through which the team judges whether the spec was honored.
Running agent tasks from where work already lives with Slack, Linear, and GitHub
Work based on a spec fits the cloud-agent workflow, where a task is handed off and its pull request is reviewed later. That differs from using an IDE for active coding or a CLI for local control. The handoff can begin where work already lives. A spec in a Linear issue or Slack thread can therefore carry the task to the agent without a separate process for assigning the work.
In Slack, mentioning @GitHub with a prompt puts Copilot to work in the background, with a reply when the PR is ready for review. A workflow using Linear, Cursor, GitHub, and Slack extends that handoff across the task lifecycle. The cloud agent picks up the ticket, marks it In Progress, creates a feature branch in the linked repository, reads the codebase, writes the code, opens a PR, and sends an automated Slack notification. Linear’s CEO characterized the role directly as “Linear is where agents get their bearings before starting work”. The integration changes where execution starts while preserving the requirement for explicit scope and verifiable outcomes.
Keeping the spec alive as the codebase evolves
A stale spec creates a new mismatch between written instructions and the system receiving the change. An agent following out-of-date requirements can produce a PR that clashes with production code while still seeming to do what it was asked. The document is an execution input. Versioning it in the same repository and under the same review process as code keeps changes to that input visible to the team.
When an incident exposes a missing constraint or an overlooked edge case, the durable correction includes both the implementation and the spec. Lessons that apply to the whole project also belong in AGENTS.md. This gives future runs access to accumulated decisions without depending on conversational memory or on someone remembering to repeat a warning. Each update leaves one less choice for an agent to guess at. Over time, that accumulated precision makes future agent runs cheaper and their PRs easier to review, because the team’s instructions improve with every completed task.


