Spec-Driven Development in Practice: A Guide to AI-Assisted Programming on the Command Line
This article explains how spec-driven development turns informal AI conversations into reliable engineering deliverables. It introduces a four-layer model (intent, specification, context, execution) and shows how to store specifications in version-controlled files, manage context quality, enforce least-privilege permissions and sandboxing, and build an automated verification loop. It also covers team review practices, useful metrics, and common pitfalls to avoid.
1. The Starting Problem: Why “Conversational Coding by Feel” Cannot Support Engineering Delivery
AI coding tools have evolved rapidly over the past year or two: from code completion, to conversational editing, to agent-based forms that extend capabilities through skill packages and context protocols. New concepts appear almost every month. The tools keep changing, but the engineering goals do not: deliverables must be correct, maintainable, and auditable.
The typical path of traditional interactive coding looks like this: the developer describes a vague intent, the model returns a code snippet, the developer runs it, hits an error, and goes back to the conversation. This path is highly efficient during exploration, but once the work moves into multi-person collaboration and long-term maintenance, three problems surface:
- Implicit requirements. Key constraints stay in the chat history and are never captured as versioned artifacts. When people rotate off the project, that knowledge is lost.
- Non-reproducible changes. The same prompt produces different results at different times, making defects hard to trace back.
- Delayed verification. Verification happens after coding, and the later an error is found, the more expensive it is to fix.
The core claim of spec-driven development is to move “intent” out of chat logs and turn it into an engineering asset, so the model works within explicit boundaries.
2. The Abstraction Model of Spec-Driven Development
It can be understood as a four-layer structure that converges from top to bottom:
- Intent layer: the business problem to solve and the acceptance criteria. It answers “what counts as done.”
- Specification layer: requirements, design, task breakdown, plus interface contracts and data constraints. It answers “how to build it.”
- Context layer: codebase structure, dependencies, existing conventions, and relevant historical decisions. It answers “where to build it.”
- Execution layer: file reads and writes, command execution, testing, and builds. It answers “how to implement and prove it.”
In the traditional approach, the two middle layers are almost entirely missing, so the model has to fill the gap by guessing. The value of spec-driven development is precisely to make these two layers explicit, file-based, and reviewable.
3. Putting It into Practice
3.1 Carry Specifications in Files, Not in Memory
A practical recommendation is one specification directory per requirement, containing at least three types of documents: a requirements description (including non-functional targets), a technical design (module boundaries, data flow, failure handling), and a task list (atomic tasks that are checkable and verifiable). Task granularity should be “completable within half a day and independently verifiable.”
specs/user-auth/requirement.md # goals, scope, acceptance criteriadesign.md # interface contracts, data model, exception strategytasks.md # atomic tasks and verification methods
The key constraint: specification files must go into version control and participate in code review. Otherwise they degrade into one-off drafts.
3.2 Context Engineering Determines Output Quality
The floor of model performance is set by context quality. Practical measures include: maintaining a concise project conventions file that describes directory responsibilities, naming style, and logging and error-handling conventions; providing a minimal runnable example; and for very large codebases, loading content on demand via retrieval instead of stuffing the entire repository in. Information density matters more than total information volume—noise directly induces fabricated interfaces.
3.3 Least Privilege and Sandbox Isolation
Once the execution layer can read and write files and run commands, risk control must come first:
- Default to read-only; grant write operations and command execution explicitly per task.
- Keep high-risk actions (deleting data, changing production configuration, pushing to remotes) behind human confirmation.
- Run inside a container or a separate workspace, with network and credential scope restricted.
- Perform provenance review on generated code and newly introduced dependencies to guard against supply chain risk.
3.4 A Closed Verification Loop Is a Hard Requirement
Spec-driven development does not reduce testing; it makes testing the automated carrier of acceptance. The recommended order is: derive acceptance cases from the specification and turn them into tests first, then generate the implementation, then let the toolchain automatically run build, static checks, and tests—if anything fails, go back and revise the specification. A sketch of the flow:
# pseudo-flow: spec -> cases -> implementation -> automated checksrun linter && run unit-tests && run build
When a check fails, first determine whether the specification is ambiguous or the implementation deviates from the contract. Avoid falling into the inefficient loop of “repeated conversational patching.”
3.5 Team Collaboration and Metrics
Specification files naturally become review artifacts, and the focus of review shifts from code style to whether boundaries and contracts are clear. For metrics, you can track first-pass rate, number of rework rounds, defect escape rate, and change lead time. These indicators reflect real gains far better than “how many lines of code were generated.”
4. Common Pitfalls
- Writing specifications as long documents that nobody maintains. Specifications should be short, precise, and executable.
- Skipping design and letting the model code directly, so rework costs more than writing it by hand.
- Over-granting permissions and letting the tool operate freely in production.
- Only checking results without revising the specification, so the same problems keep recurring.
5. Conclusion
The value of the command-line form lies in composability: specification files, retrieval, execution, and verification can be chained into a stable pipeline that plugs easily into a CI system. If you want to run this kind of workflow in a Baidu AI Cloud environment, you can typically use a container platform for sandbox isolation, object storage to hold specifications and artifacts, and log and monitoring services to keep an execution trail and surface anomalies—upgrading “conversational coding” into an auditable engineering process. Spec-driven development does not reject fast exploration; it provides a convergence path that makes exploration results deliverable and maintainable.
