Skip to main content

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:
  • Expert — 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.
When to use this: Any feature that touches multiple components, needs to follow established patterns, or involves integration with existing services. Especially valuable for cross-cutting features, complex domain logic, unfamiliar codebases, and onboarding new team members who need to build things that fit the existing system. When to skip this: Trivial changes, documentation-only updates, dependency bumps, or isolated utility functions with no integration requirements. If the feature can be fully specified in a single sentence and doesn’t touch other components, direct implementation is faster. How this relates to other playbooks: The Implementation phase (Phase 5) deliberately stays lightweight because the Bug Resolution and Feature Implementation playbooks cover test-driven implementation in depth. This playbook’s unique contribution is Phases 1–4 (Ground, Specify, Validate, Plan) — the specification workflow that precedes implementation. Cross-reference the other playbooks when you reach Phase 5.

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. CoreStory MCP tools used: Optional (if ticketing MCP is connected): the agent also uses the ticketing system’s tools to fetch ticket details and post implementation summaries.

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:
  1. 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).
  2. Duplication. The spec designs services, utilities, and abstractions that already exist. The agent builds from the spec, creating parallel implementations of existing functionality.
  3. 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.
Delta specification solves all three. By grounding in the real architecture first, the spec only describes what changes — new components, modified behaviors, extended interfaces. Everything that stays the same is referenced, not re-specified.

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:
Extract the user story, acceptance criteria, constraints, and any existing design notes. If no ticketing MCP is available, provide these details in the prompt. The agent needs to know what is being built before it can query how it fits. 1.2 — Select CoreStory project and create conversation.
This conversation persists across the entire specification lifecycle. It captures not just what was decided, but the architectural reasoning behind every decision — institutional knowledge that outlasts any static spec document. 1.3 — Query architectural patterns.
This query establishes the architectural vocabulary. If the system uses an event bus, the spec should use the event bus. If there’s a NotificationService base class, the spec should extend it. If async operations use a specific queue pattern, the spec should follow that pattern. 1.4 — Query existing services and reusable components.
This is the reuse-first query. Before designing anything new, find out what already exists. Teams are often surprised to discover that 40% of a feature’s spec describes functionality that’s already implemented. 1.5 — Query invariants and constraints. If a Business Rules Inventory exists for this codebase, start by pulling the Invariants field from BR-IDs adjacent to the change scope — those are already categorized and code-cited, and using them avoids re-extracting what’s already been extracted. Then issue the architectural query below to fill any gaps.
This is the invariant-first query. Before specifying what to build, establish what must NOT break. These invariants become the guardrails that constrain the spec in Phase 2, the assertion source for the test suite in Phase 5, and the validation criteria in Phase 3 and 6. 1.6 — Query design history.
Past attempts often contain valuable context about why certain approaches were rejected. Repeating a known-failed approach wastes everyone’s time. Phase 1 produces: A CoreStory conversation containing architectural patterns, existing services to reuse, invariants to preserve, and design history — the grounded context that constrains everything that follows.

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.
2.1 — Define invariants (what must NOT change). Write the invariant section of the spec before writing requirements. These come directly from Phase 1 findings:
2.2 — Define reuse (what already exists). List the existing components that the feature will use rather than recreate:
2.3 — Define the delta (what changes). Now — and only now — specify the new components, modified interfaces, and new behaviors:
2.4 — Define acceptance criteria. Write testable acceptance criteria that reference the architecture:
Notice what’s different about this spec: every requirement references specific existing components. The agent implementing this spec knows exactly what to reuse, what to extend, and what to create. There’s no ambiguity about whether to build a new HTTP client or use the existing one.
Sourcing ACs in a modernization context. When SDD is being used as Phase 5 of the Code Modernization workflow, ACs come from three sources, in priority order:
  1. The Phase 4 work-package’s behavioral equivalence requirements
  2. The Acceptance Criteria field on each in-scope BR-ID from the Business Rules Inventory (Phase 2 of modernization)
  3. Net-new ACs only for behaviors tagged [NEW] or [CHANGE] per the work package’s behavior tags
Do not invent ACs for [PRESERVE] behaviors — pull them verbatim from the BR Inventory so the legacy contract is preserved as written. New ACs for [CHANGE] behaviors should explicitly state both the legacy behavior being replaced and the new desired behavior.

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.
CoreStory might surface that /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.
3.3 — Run a failure mode analysis.
This is a pre-mortem — identifying failure modes before they become production incidents. CoreStory’s answers are grounded in the actual system’s failure handling patterns, queue implementations, and security model. 3.4 — Revise the spec. Update the specification based on validation findings. This might mean:
  • 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
Capture the revision in the CoreStory conversation. The diff between the original spec and the validated spec is itself valuable institutional knowledge — it shows what the architecture constrained.

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.
4.2 — Identify extension points.
4.3 — Determine implementation order.
CoreStory provides dependency ordering based on actual import relationships, not guesswork:
  1. Database migration and model (no dependencies)
  2. Repository layer (depends on model)
  3. Delivery service (depends on repository, HttpClient, EventSubscriber)
  4. API endpoints (depends on repository, delivery service)
  5. EventBus registration (depends on delivery service)
  6. Integration tests (depends on everything)
Phase 4 produces: A file-level implementation plan with exact paths, base classes, extension points, and dependency-ordered task list — ready for Phase 5.

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 BOTH the acceptance criteria AND the invariants in Phase 2, following patterns identified in Phase 1. ACs and invariants generate two complementary kinds of test:
  • AC tests assert outcomes for specific inputs. Format: “given X, when Y, then Z.”
  • Invariant tests assert post-conditions that must hold after any operation that could plausibly violate them. Format: “after any [operation], [invariant] still holds.” Often written as property-based tests, or as a teardown assertion that runs after every test in a suite.
Skipping the invariant tests is the most common reason post-refactor regressions slip past a passing AC suite. The AC suite catches “what should happen for input X”; the invariant suite catches “what must never happen, regardless of input.” 5.2 — Implement following the plan from Phase 4, in dependency order:
5.3 — Validate each component against the spec and architecture:
5.4 — Run the full test suite after each component. Regressions mean the implementation violated an invariant — go back to the CoreStory conversation and check which constraint was broken. For detailed implementation guidance, see the Feature Implementation playbook.

Phase 6: Verify & Capture

Objective: Confirm the implementation matches the spec AND preserves the invariants from Phase 1. 6.1 — Verify acceptance criteria compliance. Walk the AC list from Phase 2 explicitly — one verification per AC. The numbered items below should map 1:1 to the numbered ACs in the spec:
6.2 — Verify invariant preservation. Walk the invariant list from Phase 2 explicitly — one verification per invariant. Categorize the verification approach by invariant category (data-integrity invariants verify against persisted state, security invariants verify access scoping, temporal invariants verify ordering, etc.):
If 6.1 and 6.2 both walk their lists exhaustively, the spec is functionally what the implementation guarantees — no AC or invariant is implicitly trusted. 6.3 — Commit with context.
6.4 — Rename the CoreStory conversation to mark it as completed:
This conversation is now searchable institutional knowledge. Future engineers working on the webhook system — or any related notification feature — can reference the full chain of architectural reasoning, specification decisions, and validation results. This is the living record that static spec documents can’t provide. 6.5 — Update the ticket with a summary linking to the CoreStory conversation:

Agent Implementation Guides

The skill file shown below is plain markdown. The workflow it encodes works in any agentic harness — only the install location differs. Common conventions:
Want a single install that works across the most harnesses? Append the content to AGENTS.md at your repository root. The AGENTS.md spec is read by Codex, Aider, Cursor, Factory, Jules, Gemini CLI, Windsurf, GitHub Copilot’s coding agent, JetBrains Junie, Warp, and others — so a single file covers most users without harness-specific setup.
If your harness isn’t listed, the SKILL.md content itself is portable — install it wherever your harness loads workflow context and adapt the activation step (auto-trigger, slash command, explicit invocation) to your harness’s conventions. The sections below walk through end-to-end setup (skill file, usage, tips, agent-specific configuration) for the four most common harnesses. If you’re on a different harness, copy the SKILL.md content from any section and install it per the conventions above.

Claude Code

Setup

  1. Configure the CoreStory MCP server. Add to your MCP configuration (global ~/.claude/config.json or project .claude/config.json). Verify by asking Claude Code: “List my CoreStory projects.”
  2. Add the skill file. Claude Code uses skills stored in .claude/skills/:
Create .claude/skills/spec-driven-dev/SKILL.md with the content from the skill file below.
  1. 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:
Or reference the skill directly:

Tips

  • Keep the skill file under 500 lines. The file below is optimized for this limit.
  • Claude Code’s YAML frontmatter requires name and description fields. 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

  1. Configure the CoreStory MCP server. Add to your VS Code MCP settings (.vscode/mcp.json or user settings). Verify by asking Copilot Chat: “List my CoreStory projects.”
  2. Add project-level custom instructions. Create or update .github/copilot-instructions.md with the content from the instructions file below.
  3. Optionally add a reusable prompt file. Create .github/prompts/spec-driven-dev.prompt.md with mode: agent frontmatter for on-demand invocation.
  4. Commit to version control:

Usage

With custom instructions active, Copilot Chat applies the workflow automatically when you ask about specifications or feature design:
If using a prompt file:

Tips

  • .github/copilot-instructions.md is always active — it’s global custom instructions for the project. Keep it focused on principles.
  • Prompt files (.github/prompts/) are invoked on demand and support mode: agent for 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

  1. Configure the CoreStory MCP server. Add to your Cursor MCP configuration (.cursor/mcp.json or user settings). Verify by asking Cursor Chat: “List my CoreStory projects.”
  2. Add the project rule. Cursor uses rules stored in .cursor/rules/:
Create .cursor/rules/spec-driven-dev.mdc with the content from the rule file below.
  1. Commit to version control:

Usage

With alwaysApply: true, the rule activates automatically when Cursor detects specification-related context. Or trigger it explicitly:

Tips

  • Cursor rules use .mdc extension with YAML frontmatter containing description, globs, and alwaysApply.
  • Set alwaysApply: true for rules that should always be active, or use globs to 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

  1. Configure the CoreStory MCP server in your Factory.ai environment. Verify with the /mcp command that CoreStory tools are accessible.
  2. Add the custom droid. Factory.ai uses droids stored in .factory/droids/ (project-level) or ~/.factory/droids/ (personal):
Create .factory/droids/spec-driven-dev.md with the content from the droid file below.
  1. Commit to version control (for project-level droids):

Usage

Invoke the droid via the Task tool:
Or describe the work and Factory.ai routes to the droid based on its activation triggers.

Tips

  • Use model: inherit in the YAML frontmatter to use whatever model the session is configured with.
  • The tools field 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. Run CoreStory: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.