Spec-Driven Programming with Claude Code: /spec Command + Plan Mode in Practice

Spec-driven development: write the spec in plain language first, then make a technical plan, and finally let AI write code according to the plan.
The article introduces a Claude Code spec-driven development workflow shared by a Bilibili creator. The core idea is to split development into three steps — writing the spec, making the plan, and implementing — to avoid repeated revisions caused by AI guessing intent. The author explains in detail how to use a custom /spec slash command to automatically generate a feature title, branch name, and switch Git branches, as well as the structural design of the spec template — describing only user-facing behavior, edge cases, and acceptance criteria without technical implementation details. Compared with GitHub SpecKit, this approach is lighter and emphasizes developer control and version control discipline, and it works with any agentic coding tool.
The most frustrating thing about AI writing code isn't that it can't write — it's that it keeps guessing your intent. It guesses wrong, you correct it, it guesses again, and after a few rounds of back-and-forth, the codebase is unrecognizable. In the Claude Code masterclass by Night Ninja Dev on Bilibili, the creator shares a spec-driven development workflow. The core idea: write the spec in plain language first, then make a technical plan, and only then let the AI start writing code. This workflow borrows from GitHub's SpecKit tool but has been greatly simplified, keeping developers firmly in the loop.
Why a Spec-Driven Workflow Is Needed
If you directly tell Claude Code "help me implement a user login feature," the model will fill in tons of details on its own — which encryption method to use, how to design the database fields, what the error messages should look like. These guesses may not match your expectations, and correcting them after the code is written costs far more than aligning upfront.
The spec-driven workflow splits the entire development process into three clear steps:
- Write the spec: Describe, in high-level, non-technical language, how the feature should behave from the user's perspective, including edge cases.
- Make the plan: Based on the spec, create a detailed technical implementation plan.
- Implement the plan: Use Extended Thinking mode together with the Opus model to code according to the plan.
The creator emphasizes that this approach works with any agentic coding tool, not just Claude Code. Its value lies in keeping the model focused — each stage does only one thing, and guesswork and false assumptions are minimized.
Compared with SpecKit, this approach differs in being "lightweight." SpecKit emphasizes putting high-level specs at the center of AI-driven development collaboration, but the creator believes developers who like to edit code themselves would find SpecKit "too disconnected" — the process is too heavy and leaves too little room for their own ideas. The simplified version is easier to control and hands the initiative back to the developer.
What Is "Extended Thinking Mode"?
Extended Thinking is a capability of Claude models that allows the model to perform longer internal reasoning before giving a final answer. Unlike ordinary conversation, with Extended Thinking enabled, the model first generates a "thinking process" that isn't shown directly to the user — breaking down the problem, weighing options, checking edge conditions — and then outputs code or conclusions. This resembles a human engineer drafting notes or drawing flowcharts before starting work. In this workflow, the third implementation stage enables this mode, and combined with the more capable Opus model, it lets the model handle more complex logic branches while coding according to the plan, reducing cases of "discovering halfway through that the approach doesn't work."
Step 1: Generate a Feature Spec with the /spec Command
The starting point of the entire workflow is a custom slash command. Create a spec.md file in the Commands folder of the Claude directory, and afterwards you can invoke it by typing /spec.

This command handles four things:
- Generate a feature title and branch name from the passed-in argument
- Automatically switch to a new Git branch
- Write a high-level feature spec based on the input
- Save the spec to a markdown file in the specs folder
The command file structure has two parts. At the top is YAML frontmatter containing three configuration items: description (describes the command's purpose), argument-hint (hints at the argument format, i.e., a short feature description), and allowed-tools (restricts the available tools to Read, Write, Glob, and Bash, with Bash used for switching branches).
Below the metadata are the command's specific instructions. The creator recommends copying the complete command directly from the Claude Snippets branch of the course's GitHub repository rather than typing it by hand. The core logic of the instructions is:
Pre-check: First confirm the current branch has no uncommitted or unstaged changes. If there are any, terminate the process and prompt the user to commit or stash first. This step prevents spec generation and code changes from getting mixed together.
Extract variables: Parse the feature title, short feature identifier (lowercase letters plus hyphens, only letters and digits allowed, spaces replaced with hyphens), and safe branch name (format: claude-feature- plus the short identifier) from the user input.

Switch branches: Create and switch to a new branch with the generated branch name. The creator reiterates the necessity of Git integration here — one branch per new feature, and if you mess up, just delete the branch and the main codebase remains untouched. Using AI to change code without version control means "things will get messy very quickly."
Write the spec file: Create a markdown spec in the specs directory, following the structure of the template file. The key constraint: don't include any technical implementation details, such as code examples. Those are left for the plan stage in the next step. After the spec is created, the model replies with a brief summary of the branch name, file location, and feature title.
YAML Frontmatter and the Slash Command Mechanism
A custom slash command in Claude Code is essentially a Markdown file stored in a specific directory, with the filename serving as the command name. The YAML frontmatter at the top of the file, wrapped in ---, declares the command's metadata: description tells users what the command does, argument-hint hints at the argument format when typing, and allowed-tools restricts the set of tools the model can call during that command's execution (such as Read, Write, Glob, Bash). This design separates "what the command can do" from "what the command is allowed to touch," which both facilitates reuse and enforces permission constraints — for example, restricting it to only reading files and switching branches, preventing the command from accidentally performing dangerous operations.
Structure Design of the Spec Template
The specs folder is named with a leading underscore (_specs), purely so it sorts at the top of the directory tree. Inside the folder, you need a template.md that defines the skeleton of each spec.

The template contains these sections:
- Feature name and branch name: Identifying information
- Overview: What problem this feature solves
- Functional requirements: List of feature behaviors from the user's perspective
- Figma design reference: A reserved placeholder area; the course will cover Figma integration later, so it can be skipped for now
- Edge cases: Various exceptional and extreme scenarios
- Acceptance criteria: How to determine it's done
- Open questions: Open questions that need a human decision
- Testing guidelines: Require creating test files in the test folder for each new feature, writing meaningful tests for the listed cases, but without over-engineering
The template explicitly states "don't make it too heavy" — specific test cases are judged by Claude Code when writing the spec. The creator also explicitly says to ignore the Figma part for now and come back to it in later chapters.
A detail worth noting about the spec template is its "non-technical" positioning. It describes "what the user sees, what situations they encounter, and what counts as done," rather than "what algorithm to use or what tables to create." This layering makes the spec an anchor for aligning intent between humans and AI, while technical decisions are left for the planning stage.
Git Branching Strategy and Rollback Granularity
The workflow requires opening a new branch for each feature (format: claude-feature- plus the short feature identifier). Behind this is the basic principle of the Git branching model: a branch is a lightweight pointer to commit history, and creating and deleting branches costs almost nothing. When AI generates specs and code on an isolated branch, if the result isn't good, simply deleting that branch leaves the main branch completely unaffected — the rollback granularity is "the entire feature" rather than "a few lines of code." This echoes the requirement in the pre-check that "the working tree must be clean": only when uncommitted changes don't affect branch switching can you ensure every feature development starts from a defined baseline, making every step independently reversible.
Next Steps and the Toolchain
This is the first half of the workflow: the /spec command plus the spec template. The next lesson will use this toolkit to actually write a spec for a brand-new feature.
The full loop has two more steps. Plan Mode is a built-in Claude Code feature that creates a detailed technical implementation plan based on the spec file — code structure, dependencies, and implementation order are all determined at this step. Extended Thinking mode together with the Opus model is responsible for implementing according to the plan; during the execution stage, the model has enough reasoning depth to handle complex logic.
A review step can also be added at the end of the loop, checking code quality after the feature is implemented, but the creator saves this for later chapters.
An easily overlooked detail is the pre-check design of the /spec command. It requires a clean working tree before continuing — this isn't just a hygiene habit: when spec generation and code changes are mixed together, rollback granularity becomes ambiguous. Commit or stash first, then switch branches, then write the spec — every step is independently reversible. This kind of engineering discipline matters more in AI-assisted development than in traditional development, because AI operates quickly and broadly, and when something goes wrong, the blast radius is larger.
The core philosophy of the whole workflow is actually quite simple: separate "thinking clearly about what to do" from "doing it," letting humans handle the former and AI the latter. The spec file is the contract for this division of labor. The creator borrowed this idea from SpecKit, then cut the heavy parts they didn't need, ultimately leaving a lightweight solution that fits into daily development rhythms. For developers already using Claude Code or other agentic tools to write code, this workflow is worth running through completely before deciding whether to adjust it.
Related articles

CLI-Anything: The Open-Source Tool That Lets AI Control Every App
CLI-Anything is a free open-source project that generates clean command-line interfaces for almost any software, letting AI Agents like CloudCode and Cursor drive Blender, GIMP, and LibreOffice. Install the hub with one pip command and browse community CLIs—18 demo apps, over 2,000 tests passing, 68,000 stars. Note: some CLIs wrap real apps, so you still need to install the software itself.

Does AI Get Dumber the Longer You Chat? Three Solutions for Vibe Coding Context Management
AI coding getting dumber in long chats? We break down context bloat from Cloud Code docs and Lost in the Middle research, plus three actionable fixes: split sessions by task, cut losses after two failed corrections, and have AI summarize before migrating—keeping your vibe coding efficient.

Claude Code vs Codex vs Cursor vs Copilot: How to Choose Among the Four Major AI Coding Tools
A side-by-side comparison of Claude Code, OpenAI Codex, Cursor, and GitHub Copilot: how the three tool families differ, where the free entry points are, the real limits of each subscription tier, and four questions to find the right fit.