Overview
A specification that isn’t grounded in the real architecture is a wish list. Code generated from a wish list is technical debt. Spec-driven development (SDD) is gaining traction as teams realize that handing an AI agent a vague ticket and hoping for the best doesn’t scale. Tools like GitHub’s Spec Kit, Kiro, and Tessl have emerged to impose structure — write a spec first, then generate code from it. The structure is valuable. But every one of these tools shares a fundamental blind spot: they don’t actually know how your system works. They scan files, infer patterns, and guess. The specs they produce are architecturally ungrounded — and ungrounded specs produce code that reinvents existing services, violates established patterns, and breaks invariants the spec author didn’t know existed. This playbook is CoreStory’s answer to the grounding problem. It’s a six-phase workflow where your AI agent queries CoreStory’s code intelligence to understand the real architecture before writing a single line of specification — then validates the spec against that architecture before implementation begins. The result is a delta specification — only what changes, constrained by what exists — rather than an aspirational document that may contradict reality. CoreStory serves two roles in this workflow:- Oracle — answers questions about architectural patterns, naming conventions, business rules, invariants, and design decisions. This is context synthesized from PRDs, tech specs, user stories, and code history. It’s the institutional knowledge that normally lives only in the heads of long-tenured engineers.
- Navigator — points to specific files, services, base classes, extension points, and data structures. Instead of guessing where new code should go or what already exists, the agent gets directed guidance grounded in the actual codebase.
Prerequisites
- CoreStory account with at least one project that has completed ingestion
- CoreStory MCP server connected to your AI coding agent (see the CoreStory MCP Server Setup Guide)
- AI coding agent — this playbook includes implementation guides for Claude Code, GitHub Copilot, Cursor, and Factory.ai. The generic workflow applies to any MCP-capable agent.
- Optional: Ticketing system MCP (GitHub Issues, Jira, Linear, Azure DevOps) for automatic ticket intake
- Optional: A companion SDD framework (Spec Kit, Kiro, etc.) — this playbook works standalone, but companion integrations are covered in separate guides
How It Works
The Six-Phase Workflow
The workflow has six phases. The first four produce and validate the specification; the last two implement and verify it. Phases 1 and 3 — Ground and Validate — are what distinguish this from generic SDD. They can’t exist without architectural knowledge, which is why no standalone SDD tool offers them.| Phase | Name | Purpose | CoreStory Role |
|---|---|---|---|
| 1 | Ground | Establish architectural truth before writing any spec | Oracle |
| 2 | Specify | Write requirements constrained by what exists | Oracle + Navigator |
| 3 | Validate | Architectural pre-mortem — submit spec for conflict detection | Oracle |
| 4 | Plan | Map validated spec to files, patterns, and extension points | Navigator |
| 5 | Implement | TDD with continuous architectural validation | Validation |
| 6 | Verify & Capture | Confirm implementation matches spec AND preserves invariants | Knowledge capture |
| Tool | When Used |
|---|---|
list_projects | Phase 1 — select the right project |
create_conversation | Phase 1 — create a persistent specification thread |
send_message | Phases 1–6 — all queries to CoreStory |
get_project_prd | Phase 1 — access product requirements for grounding |
get_project_techspec | Phase 1 — access technical specifications |
rename_conversation | Phase 6 — mark conversation as completed |
Why Delta Specification Matters
Traditional SDD produces greenfield specifications — documents that describe the entire feature from scratch as if no codebase existed. This creates three problems:- Contradiction. The spec describes patterns that conflict with the actual architecture. The agent either follows the spec (introducing inconsistency) or follows the code (making the spec misleading).
- Duplication. The spec designs services, utilities, and abstractions that already exist. The agent builds from the spec, creating parallel implementations of existing functionality.
- Bloat. Without knowing what already exists, specs over-specify. A date formatting feature that should be “use the existing DateFormatter service with locale X” becomes 40 lines of formatting logic specification.
Step-by-Step Walkthrough
This section is agent-agnostic. The prompts work with any MCP-connected agent. Agent-specific configuration is in the Implementation Guides below.Phase 1: Ground
Objective: Establish architectural truth before writing any specification. This phase is the foundation. Without it, every subsequent phase operates on assumptions — and assumptions are where specs go wrong. The output is a grounded understanding captured in a CoreStory conversation thread, not a static constitution document that drifts out of sync with the code. 1.1 — Gather requirements. If a ticketing MCP is connected, fetch the ticket:Phase 2: Specify
Objective: Write a delta specification — requirements constrained by what exists. Two principles make this different from generic SDD:- Reuse-first. Before designing anything new, specify what existing components will be reused and how. This prevents the most common SDD failure mode: specs that design new services when existing ones would work.
- Invariant-first. Before specifying what will change, specify what must NOT change. This encodes the architectural constraints that experienced engineers carry in their heads but rarely write down.
Phase 3: Validate
Objective: Submit the spec back to CoreStory for architectural pre-mortem. This is the phase that no standalone SDD tool can replicate. Generic SDD produces a spec and moves to implementation. Architecture-grounded SDD submits the spec for validation — asking “what could go wrong?” with access to the full architectural context. 3.1 — Check for architectural conflicts./api/v2/ endpoints follow a different authentication pattern than what the spec assumes, that EventSubscriber has been deprecated in favor of EventHandler, or that SerializerFactory doesn’t support the webhook payload format. These are the kinds of issues that normally surface during code review — weeks after the spec was written.
3.2 — Check for missing dependencies.
- Adjusting component names to match conventions
- Adding missing error handling based on existing patterns
- Removing features that duplicate existing functionality you missed
- Adding integration requirements you hadn’t considered
Phase 4: Plan
Objective: Map the validated spec to specific files, patterns, and extension points. Where Phase 3 asked “is this spec valid?”, Phase 4 asks “where exactly does this go?” The difference from generic planning is precision: CoreStory provides exact file paths, class hierarchies, and integration points based on the actual codebase — not inferred from file proximity or naming conventions. 4.1 — Map components to files.- Database migration and model (no dependencies)
- Repository layer (depends on model)
- Delivery service (depends on repository, HttpClient, EventSubscriber)
- API endpoints (depends on repository, delivery service)
- EventBus registration (depends on delivery service)
- Integration tests (depends on everything)
Phase 5: Implement
Objective: TDD implementation with continuous CoreStory validation. This phase follows the same test-first methodology as the Feature Implementation playbook. The spec from Phases 1–4 gives the agent precise implementation guidance; this phase executes it. 5.1 — Write failing tests from the acceptance criteria in Phase 2, following patterns identified in Phase 1:Phase 6: Verify & Capture
Objective: Confirm the implementation matches the spec AND preserves the invariants from Phase 1. 6.1 — Verify spec compliance.Agent Implementation Guides
Each guide covers: setup, usage, tips, and an agent-specific configuration file that encodes the six-phase workflow.Claude Code
Setup
-
Configure the CoreStory MCP server. Add to your MCP configuration (global
~/.claude/config.jsonor project.claude/config.json). Verify by asking Claude Code: “List my CoreStory projects.” -
Add the skill file. Claude Code uses skills stored in
.claude/skills/:
.claude/skills/spec-driven-dev/SKILL.md with the content from the skill file below.
- Commit to version control:
Usage
Claude Code auto-loads skills based on description matching. When you mention specifications, specs, architecture-grounded development, or SDD, the skill activates:Tips
- Keep the skill file under 500 lines. The file below is optimized for this limit.
- Claude Code’s YAML frontmatter requires
nameanddescriptionfields. The description drives auto-activation — make it specific. - The skill works with other skills. If you have a testing skill, Claude Code will combine them during Phase 5.
Skill File
Save as.claude/skills/spec-driven-dev/SKILL.md:
GitHub Copilot
Setup
-
Configure the CoreStory MCP server. Add to your VS Code MCP settings (
.vscode/mcp.jsonor user settings). Verify by asking Copilot Chat: “List my CoreStory projects.” -
Add project-level custom instructions. Create or update
.github/copilot-instructions.mdwith the content from the instructions file below. -
Optionally add a reusable prompt file. Create
.github/prompts/spec-driven-dev.prompt.mdwithmode: agentfrontmatter for on-demand invocation. - Commit to version control:
Usage
With custom instructions active, Copilot Chat applies the workflow automatically when you ask about specifications or feature design:Tips
.github/copilot-instructions.mdis always active — it’s global custom instructions for the project. Keep it focused on principles.- Prompt files (
.github/prompts/) are invoked on demand and supportmode: agentfor agentic execution. - Copilot Chat accesses MCP tools through the VS Code MCP configuration. Ensure CoreStory tools appear in the available tools list.
Custom Instructions File
Save as.github/copilot-instructions.md (append to existing content if the file already exists):
Cursor
Setup
-
Configure the CoreStory MCP server. Add to your Cursor MCP configuration (
.cursor/mcp.jsonor user settings). Verify by asking Cursor Chat: “List my CoreStory projects.” -
Add the project rule. Cursor uses rules stored in
.cursor/rules/:
.cursor/rules/spec-driven-dev.mdc with the content from the rule file below.
- Commit to version control:
Usage
WithalwaysApply: true, the rule activates automatically when Cursor detects specification-related context. Or trigger it explicitly:
Tips
- Cursor rules use
.mdcextension with YAML frontmatter containingdescription,globs, andalwaysApply. - Set
alwaysApply: truefor rules that should always be active, or useglobsto restrict to specific files. - Rules apply in both Composer and Chat modes.
Project Rule
Save as.cursor/rules/spec-driven-dev.mdc:
Factory.ai
Setup
-
Configure the CoreStory MCP server in your Factory.ai environment. Verify with the
/mcpcommand that CoreStory tools are accessible. -
Add the custom droid. Factory.ai uses droids stored in
.factory/droids/(project-level) or~/.factory/droids/(personal):
.factory/droids/spec-driven-dev.md with the content from the droid file below.
- Commit to version control (for project-level droids):
Usage
Invoke the droid via the Task tool:Tips
- Use
model: inheritin the YAML frontmatter to use whatever model the session is configured with. - The
toolsfield in frontmatter can explicitly list required MCP tools if you want to restrict the droid’s capabilities. - The Task tool that invokes droids requires experimental features to be enabled.
- For complex specs, the droid’s CoreStory queries may produce long streaming responses — this is expected.
Custom Droid
Save as.factory/droids/spec-driven-dev.md:
Tips & Best Practices
Ground before you specify. The most common SDD failure is writing a spec based on assumptions about the architecture. Spend the time in Phase 1. The 10 minutes of CoreStory queries saves hours of rework when the spec contradicts reality. Invariants are the spec’s immune system. The invariant section is the most valuable part of a delta specification. It tells implementers — human or AI — what they’re not allowed to break. When a test fails in Phase 5, check invariants first. Reuse is the spec’s economics. Every existing component you reuse is a component you don’t have to specify, implement, test, and maintain. The reuse-first query in Phase 1 often eliminates 30–50% of the specification work. Delta specs age better than greenfield specs. A greenfield spec for “webhook notifications” becomes misleading the moment someone changes the EventBus interface. A delta spec that says “implements EventSubscriber interface” automatically adapts because the implementation follows the interface, not the spec’s description of the interface. Use the CoreStory conversation as a review artifact. Before the spec goes through design review, share the CoreStory conversation link. Reviewers see the full chain: what architectural constraints were discovered, what alternatives were considered, what the pre-mortem found. This is dramatically more useful than a spec document alone. Name conversations for searchability. “Spec: #412 — Webhook notification system” is findable six months later. “Feature spec” is not. After completion, the “COMPLETED” prefix makes it easy to distinguish finished work from in-progress investigations. Don’t skip Phase 3. It’s tempting to go from Specify straight to Plan — the spec feels done. The validation phase exists because specs always contain assumptions that don’t survive contact with the real architecture. Phase 3 is where you catch conflicts before they become code review rejections or production bugs. Companion tools are complements, not replacements. If you’re using Spec Kit, Kiro, or another SDD framework, this workflow wraps around it. Run Phase 1 (Ground) before the companion tool’s specification phase. Run Phase 3 (Validate) after it. The companion tool provides structure; CoreStory provides grounding.Troubleshooting
CoreStory returns generic architectural answers. Your queries are too broad. Instead of “Tell me about the notification system,” try “What classes implement NotifierBase? What events does EventBus currently handle? What retry patterns does HttpClient use?” Include specific interface names, method names, or code snippets. Project not found or ingestion incomplete. RunCoreStory:get_project_stats to check status. If ingestion is still running, wait for completion — queries against partially-ingested projects miss components and return incomplete invariants. Verify the project name matches exactly.
The spec feels like it’s re-specifying everything.
You’re writing a greenfield spec, not a delta spec. Go back to Phase 1 and query for existing components more aggressively. If the reuse section is empty, you haven’t asked the right questions.
Validation phase finds major conflicts.
This is the workflow working correctly. Major conflicts in Phase 3 are dramatically cheaper than major conflicts in Phase 5 (code) or production. Revise the spec. If the conflicts require fundamental redesign, that’s valuable information you wouldn’t have had without grounding.
Implementation diverges from the spec.
Don’t drift — go back to the spec. If the divergence is necessary (the spec missed something), update the spec in the CoreStory conversation before continuing. The spec is a living document within the conversation, not a frozen artifact.
CoreStory response is too long or gets cut off.
Break your query into smaller, more specific questions. Phase 1 in particular should be 4–6 targeted queries, not one mega-query.
Agent doesn’t follow the six-phase workflow.
If you’re using the agent configuration files (skill/instructions/rules/droid) and the agent still doesn’t follow the workflow, check that the configuration file is in the correct location and format. See the Agent Implementation Guides above for exact paths and filenames.