Skip to content

OpenSpec and Claude Code: Write the Plan Before the Code

Insights•
October 19, 2026

Introduction

The plan for the social broadcasting feature in the Codyssey backend opens with its goal:

The goal is that publishing content is the only action a human takes, and the social fan-out happens on its own.

The Codyssey backend is a Laravel 13 and Statamic v6 app, and this feature turns a published lesson or article into posts on X, LinkedIn and other platforms. The plan was written on 2026-06-04. It made two calls that did not last. It put the new module under Codyssey/, the member-facing application, and it chose to be "fully automated with no human approval gate". On 2026-09-03 and 2026-09-04, two decision records reversed both.

Reversing them was cheap, because each decision sat in a file in the repo next to the alternatives it had beaten, where the next session could read it. A plan that lives in a chat is gone when the session ends, and a plan buried in a long prompt gets half-read. This piece shows where the plan lives instead: OpenSpec for the change itself, a config file that puts the architecture questions into the agent's prompt, a domain design step for placement, and ADRs for the decisions that outlive the change. It is part 2 of the series that starts with My Claude Code Workflow for Laravel, From Idea to Merged PR.

Explore before you propose

OpenSpec is a set of commands that stores a feature's plan as markdown files in the repo, one folder per change. Its first command, /openspec-explore, is "a thinking partner for exploring ideas, investigating problems, and clarifying requirements." It writes no files.

I start by stating the goal in a sentence or two. Claude reads the codebase and the docs before it suggests anything, because a plan that ignores the existing modules describes a different app. For the social feature we compared four social media APIs (Zernio, Postiz, Mixpost and Ayrshare), and I cut scope before anything was written: AI-generated copy and YouTube were both deferred.

Very little of that conversation reaches the repo. The design records the vendor decision and its risk in one sentence: "The user accepted Zernio knowingly; this design contains that risk behind a gateway contract." The scope cut is one line in the task list: "YouTube excluded from the v1 platform map." The comparison itself was never written down. Exploring is where being wrong costs nothing, so only its conclusions get kept.

One change, one folder

/openspec-propose turns the explored idea into a change in one step. It writes a proposal (what and why), a design (how, with each decision and its alternatives), a spec (what the system must keep doing), and a task list. This is the social broadcasting change after it was archived, with a README.md that Codyssey adds:

TEXT
openspec/changes/archive/2026-09-03-broadcast-content-to-social/ ├── README.md ├── proposal.md ├── design.md ├── specs/social-publishing/spec.md └── tasks.md

Each file answers one question, so a later session opens only the one it needs. The proposal starts from the problem: "When content goes live on Codyssey, sharing it across social platforms is fully manual." The task list is what implementation works through: 54 tasks in 12 groups, from the data model to the admin dashboard. Several groups each build one vertical slice, the folder that holds everything for one action.

Two habits in this change are worth copying. The first task group is "Phase 0 - Verify open questions (do before coding)", and every task in it was answered from a source before any code was written: "1.1 Confirm Zernio sends status webhooks. RESOLVED against the docs". The second is in the design. Its open questions stay in the file, struck through, with the answer beside them:

Does Zernio send status webhooks? RESOLVED against the Zernio docs. Yes

The next session sees that the question was asked and what settled it, so it does not ask again or quietly assume the opposite.

Make the plan answer the architecture questions

openspec/config.yaml holds rules every new artifact must follow. OpenSpec hands them to the agent while it writes each file, as "constraints for YOU, not content for the file". This is the rules block in Codyssey's config:

YAML
rules: proposal: - Under Impact, name the owning bounded context and the top-level namespace kind (Codyssey module, AdminPanel presentation, Framework infrastructure, root editorial context, root vendor SDK) - List the ubiquitous-language delta, or state "no new terms" design: - Required sections, Bounded context placement, Integration patterns, Ubiquitous language delta, Event-model slices, Enforcement, ADR test - Include alternatives considered for each decision tasks: - An extraction or move of a bounded context is three commits, git mv, namespace, tooling - Updating docs/DOMAIN.md, the relevant rule files, and the vault note are tasks, not afterthoughts specs: - One capability per bounded context touched - A capability never spans two bounded contexts

A bounded context is the part of the domain a piece of code belongs to, with its own vocabulary and its own data. Social publishing is one, and subscriptions is another. The namespace kind is where that context lives in the repo: inside one of the two applications (Codyssey/ for members, AdminPanel/ for staff), in shared infrastructure under Framework/, or at the top level of its own. The ubiquitous language is the project's glossary, kept in docs/DOMAIN.md.

These rules were added on 2026-09-04, three months after the broadcast plan. The plan's Impact section says the module goes "under Codyssey/SocialPublishing/" and never asks whether that is the right home. It was the wrong one. ADR-025, dated the same day the rules arrived, moved the module to the top level: "Two modules inside Codyssey/, the member-facing application, had no member actor at all." Broadcasts start when staff publish content, and members never trigger one. The Impact rule goes into the prompt the agent writes the next proposal from, so it is told to name the home and defend it.

Run /domain-design before you scaffold

The config rules say what a plan must answer. /domain-design is the procedure for answering it, and CLAUDE.md says when it runs: "Run /domain-design before /new-module, /new-slice or /admin when a change adds a context, an aggregate, a cross-context interaction, or moves a capability". An aggregate is a group of records that change together under one set of rules, like a broadcast and its per-platform targets.

The skill has ten steps, and most of them write into a named section of the OpenSpec design:

#

Step

Writes into

1

Read the model

nothing, context only

2

Vocabulary pass

Ubiquitous language delta

3

Classify the subdomain

feeds Bounded context placement

4

Place it

Bounded context placement

5

Aggregates and invariants

Event-model slices

6

Event-model slices

Event-model slices

7

Map the contexts

Integration patterns

8

Design it twice

Alternatives considered

9

ADR test

ADR test

10

Hand off

the proposal, design, specs and tasks, plus the DOMAIN.md and MODULES.md (the module index) changes

Three of the steps do most of the work. The vocabulary pass compares the plan's words with the glossary and treats a clash as information: "A word that appears in two rows with different meanings is a boundary signal, not a naming problem." Design it twice asks for a rival placement on purpose, from read-only planning subagents: "Launch two Plan-type subagents in parallel, each producing an alternative placement with its own dependency table and vocabulary". The ADR test decides whether the plan needs a decision record, which the next sections cover.

The skill also carries its own test case. Run against the extract-editorial-contexts change, the plan that moved the social module out of Codyssey/, it "must reach the same four decisions that change recorded". A design procedure that cannot reproduce a decision the team already made carefully is not ready to make new ones.

Once a plan exists, I read and edit it by hand, ask Claude to revise it, and then run /domain-design review <change>. Review mode runs the same ten steps against the finished plan and "interviews one question at a time, each with a recommended answer". The agent argues with the plan, using the project's glossary and decision log, before any code depends on it.

A small change skips all of this. A bug fix, or one slice inside an existing context with no new terms, goes straight to implementation.

Specs say what must stay true

A spec lists requirements written with SHALL, each followed by scenarios written as WHEN and THEN. The first requirement in the broadcast spec, with its first scenario:

MARKDOWN
### Requirement: Broadcast only when newly, publicly, first-time visible in production The system SHALL create exactly one broadcast for an entry, and SHALL do so only when all of the following hold: the entry is in a socially-publishable collection, it is published, no broadcast record already exists for it, the application is running in the production environment, and the entry was first published after the configured go-live cutoff. [...] #### Scenario: First publish in production creates a broadcast - **WHEN** an entry in a socially-publishable collection is published for the first time in production, after the go-live cutoff, with suppression off - **THEN** a broadcast is created for the entry with one target per platform in the type's configured map

The spec inside a change is a delta: it lists what this change adds or modifies. When the work is done, /openspec-archive-change moves the folder to openspec/changes/archive/ with the date in front, and offers "Sync now (recommended)" to merge the delta into openspec/specs/, the description of what the system does today. A separate command, /openspec-sync-specs, merges without archiving. The review gate change used it: its social-broadcast-review spec is already in openspec/specs/, while the change itself is still open with 22 of its 32 tasks ticked.

Why a module was built that way is the job of the ADRs.

When a decision gets an ADR

An ADR, or architecture decision record, is a short markdown file about one decision: its context, the decision, the alternatives considered, and the consequences. Codyssey numbers them in docs/decisions/. CLAUDE.md sets the test:

A change that settles an architectural question gets an ADR in docs/decisions/ in the same change: a choice made between real alternatives, a new pattern other code must follow, or an accepted trade-off likely to be questioned later. The test is whether "why not the obvious alternative" needed explaining during planning or review; if it did, that rationale goes in the ADR, not just the PR description. Features that follow existing patterns need no ADR.

Claude writes the ADR in full during the change, and I read and approve it in the pull request with the code.

The alternatives section is the part that pays off later. ADR-023 considered "An AdminPanel-owned Zernio gateway", a second wrapper around the vendor's API owned by the admin panel, and rejected it: "Building a second anti-corruption layer for the same vendor would drift from the first one over time." The next time an agent proposes that design, the answer and its reason are already in the repo.

Change a decision without rewriting it

CLAUDE.md describes docs/decisions/ as "ADRs (rationale; never edited retroactively)". In practice that means the reasoning is never rewritten. When a decision changes, a new ADR carries the new argument, and the old ADR gets one pointer line.

The original plan had seen the risk. Its risks section lists "Fully automated copy hits platforms unreviewed", and its answer was a delay: posts were scheduled ahead rather than sent at once, because "A short scheduled delay gives a window to catch and cancel a bad post in the vendor UI before it publishes."

ADR-023, dated 2026-09-03, replaced the delay with a review. Its consequences say the delay settings and BroadcastScheduleCalculator "are gone", and it reversed one of the plan's non-goals: "A human approval/review gate (explicitly fully automated; the admin UI is tracking + retry, not approval)." Its context names what went wrong: "No one saw the generated copy or the rendered card and carousel before they reached a platform." Every broadcast now opens as a draft that an admin reviews and publishes. ADR-025 came the next day, moved the module, and replaced one part of ADR-023 along the way. ADR-023's header now reads:

MARKDOWN
# ADR-023: Social broadcast review gate **Status:** Accepted **Date:** 2026-09-03 Superseded in part by ADR-025: decision (b), the vendor call reached through `Framework\Events\SocialBroadcastPublishRequested` / `SocialBroadcastRegenerationRequested`, is replaced by commands dispatched directly against the context's own write model.

Everything below that line is the decision as it was made on 2026-09-03. A reader, human or agent, gets the original reasoning and the exact part that no longer holds. ADR-025 records the same link from its side: its Consequences list what it supersedes in ADR-013, ADR-015 and ADR-023.

Rules carry the ADR that justifies them

Decisions only steer the agent if the code-level rules point back at them, so Codyssey's rules end with the ADR that explains them:

  • CLAUDE.md: "Scaffold with /new-slice, /new-module, /admin; never php artisan make:* (ADR-021)"

  • .ai/rules/migrations-factories-tests.md: "Tests\TestCase calls Model::preventLazyLoading() in setUp() and Model::preventLazyLoading(false) in tearDown() (ADR-031) so the whole suite runs strict regardless of environment"

  • .ai/rules/routes-http-serialization.md: "give every signed route one test that appends &viewer=member (ADR-020). high."

A rule with no reason attached reads like a preference, and the next agent that finds it inconvenient will argue it away. With the ADR number beside it, the reason is one file away. Part 4 of the series covers how the rule files themselves are written.

Where to start

Add one rule to your OpenSpec config, or to whatever template your plans start from: every proposal names the module it belongs to and says why it belongs there. That is the question the social broadcasting plan never asked. The next stage, implementation, is in part 5.