Generate OpenSpec main specifications by analyzing the current project's code, documentation, issues, and pull requests.
Unlike openspec-propose (which creates a change with proposal/design/tasks artifacts for future work), this skill writes finished specs directly to openspec/specs/ based on what already exists in the project.
Input: Optionally specify which capabilities or areas to generate specs for. If omitted, analyze the full project and determine capabilities automatically.
Steps
Gather project context
Collect information from all available sources. Prioritize breadth over depth — skim first, then deep-dive into relevant areas.
a. Project documentation:
- Read
AGENTS.md (or CONTRIBUTING.md, README.md) for architecture overview, conventions, and design decisions
- Read
docs/ directory for feature specs, design docs, BDD features (.feature files)
- Read
openspec/config.yaml for project context and rules
b. Codebase structure:
- Scan
src/ directory tree to understand module organization
- Read key files (entry points, type definitions, core modules) to understand capabilities
- Identify the main functional areas / capabilities the system provides
c. GitHub issues and PRs (if available):
- Use GitHub MCP tools to fetch recent open/closed issues for requirements context
- Use GitHub MCP tools to fetch recent merged PRs for implemented features
- Extract requirement-like information (feature requests, bug fixes, design decisions)
d. Existing specs (if any):
- Read
openspec/specs/ to understand what's already documented
- Identify gaps between existing specs and actual implementation
Identify capabilities
Based on the gathered context, determine the project's main capability areas. Each capability becomes a spec file at openspec/specs/<capability>/spec.md.
Use the AskUserQuestion tool to confirm the identified capabilities before proceeding:
"I've identified these capabilities from the project. Which should I generate specs for?"
Present the list with brief descriptions. Let the user select all or a subset.
Naming convention: Use kebab-case for capability names (e.g., memory-system, platform-abstraction, acp-integration).
Check existing specs
For each selected capability:
- If
openspec/specs/<capability>/spec.md already exists, read it
- Use AskUserQuestion tool to ask: "Spec for
<capability> already exists. Overwrite, merge, or skip?"
- Overwrite: Replace entirely with newly generated spec
- Merge: Add missing requirements/scenarios to existing spec, preserve existing content
- Skip: Leave as-is
Generate specs
For each capability, create a spec file following the OpenSpec spec format.
Use the TodoWrite tool to track progress through capabilities.
Spec file structure (openspec/specs/<capability>/spec.md):
# <Capability Name>
## Purpose
<Brief description of what this capability does and why it exists.>
## Requirements
### Requirement: <Requirement Name>
<The system SHALL/SHOULD/MAY description using RFC 2119 language.>
#### Scenario: <Scenario Name>
- **GIVEN** <precondition>
- **WHEN** <action>
- **THEN** <expected outcome>
#### Scenario: <Another Scenario>
- **GIVEN** <precondition>
- **WHEN** <action>
- **THEN** <expected outcome>
Writing guidelines:
- Use RFC 2119 keywords (SHALL, SHOULD, MAY) for requirement strength
- Derive requirements from actual code behavior, not aspirational features
- Include scenarios that reflect real code paths (check tests for scenario ideas)
- Reference source files in requirement descriptions when helpful (e.g., "Implemented in
src/core/workspace-manager.ts")
- Keep requirements atomic — one concern per requirement
- Group related scenarios under their parent requirement
Write spec files
For each capability:
mkdir -p openspec/specs/<capability>
Write the spec content to openspec/specs/<capability>/spec.md.
After writing each file, verify it exists and show brief progress.
Validate output
Run validation if available:
openspec validate --specs --json
If validation fails, fix issues and re-validate.
Show summary
Display what was generated:
## Specs Generated
| Capability | Requirements | Scenarios | Status |
|------------|-------------|-----------|--------|
| <name> | N | M | New/Merged/Overwritten |
Total: X capabilities, Y requirements, Z scenarios
Files written to `openspec/specs/`.
Source Priority
When information conflicts across sources, prefer in this order:
- Actual code behavior (ground truth)
- Test assertions (verified behavior)
- BDD feature files / design docs (intended behavior)
- GitHub issues/PRs (discussed behavior)
- README / AGENTS.md (described behavior)
Guardrails
- Always confirm capability list with user before generating
- Never fabricate requirements not supported by code or documentation
- If a capability area is ambiguous, ask for clarification
- Preserve existing spec content when merging (only add, don't remove unless user confirms)
- Each spec file must have at least a Purpose section and one requirement
- Use consistent formatting across all generated spec files
1---
2name: openspec-generate-specs
3description: Generate comprehensive OpenSpec specifications directly from the current project state. Use when the user wants to create or populate main specs by analyzing existing code, documentation, AGENTS.md, GitHub issues, and pull requests — without going through the change/proposal workflow. Ideal for bootstrapping specs on a project that already has working code but no specs yet, or for refreshing specs to match the current implementation.
4license: GFDL-1.3-or-later
5metadata:
6 author: Jim@ChenJ.im
7---
8
9Generate OpenSpec main specifications by analyzing the current project's code, documentation, issues, and pull requests.
10
11Unlike `openspec-propose` (which creates a change with proposal/design/tasks artifacts for **future** work), this skill writes finished specs directly to `openspec/specs/` based on **what already exists** in the project.
12
13**Input**: Optionally specify which capabilities or areas to generate specs for. If omitted, analyze the full project and determine capabilities automatically.
14
15**Steps**
16
171. **Gather project context**
18
19 Collect information from all available sources. Prioritize breadth over depth — skim first, then deep-dive into relevant areas.
20
21 a. **Project documentation**:
22 - Read `AGENTS.md` (or `CONTRIBUTING.md`, `README.md`) for architecture overview, conventions, and design decisions
23 - Read `docs/` directory for feature specs, design docs, BDD features (`.feature` files)
24 - Read `openspec/config.yaml` for project context and rules
25
26 b. **Codebase structure**:
27 - Scan `src/` directory tree to understand module organization
28 - Read key files (entry points, type definitions, core modules) to understand capabilities
29 - Identify the main functional areas / capabilities the system provides
30
31 c. **GitHub issues and PRs** (if available):
32 - Use GitHub MCP tools to fetch recent open/closed issues for requirements context
33 - Use GitHub MCP tools to fetch recent merged PRs for implemented features
34 - Extract requirement-like information (feature requests, bug fixes, design decisions)
35
36 d. **Existing specs** (if any):
37 - Read `openspec/specs/` to understand what's already documented
38 - Identify gaps between existing specs and actual implementation
39
402. **Identify capabilities**
41
42 Based on the gathered context, determine the project's main capability areas. Each capability becomes a spec file at `openspec/specs/<capability>/spec.md`.
43
44 Use the **AskUserQuestion tool** to confirm the identified capabilities before proceeding:
45 > "I've identified these capabilities from the project. Which should I generate specs for?"
46
47 Present the list with brief descriptions. Let the user select all or a subset.
48
49 **Naming convention**: Use kebab-case for capability names (e.g., `memory-system`, `platform-abstraction`, `acp-integration`).
50
513. **Check existing specs**
52
53 For each selected capability:
54 - If `openspec/specs/<capability>/spec.md` already exists, read it
55 - Use **AskUserQuestion tool** to ask: "Spec for `<capability>` already exists. Overwrite, merge, or skip?"
56 - **Overwrite**: Replace entirely with newly generated spec
57 - **Merge**: Add missing requirements/scenarios to existing spec, preserve existing content
58 - **Skip**: Leave as-is
59
604. **Generate specs**
61
62 For each capability, create a spec file following the OpenSpec spec format.
63
64 Use the **TodoWrite tool** to track progress through capabilities.
65
66 **Spec file structure** (`openspec/specs/<capability>/spec.md`):
67
68 ```markdown
69 # <Capability Name>
70
71 ## Purpose
72
73 <Brief description of what this capability does and why it exists.>
74
75 ## Requirements
76
77 ### Requirement: <Requirement Name>
78
79 <The system SHALL/SHOULD/MAY description using RFC 2119 language.>
80
81 #### Scenario: <Scenario Name>
82 - **GIVEN** <precondition>
83 - **WHEN** <action>
84 - **THEN** <expected outcome>
85
86 #### Scenario: <Another Scenario>
87 - **GIVEN** <precondition>
88 - **WHEN** <action>
89 - **THEN** <expected outcome>
90 ```
91
92 **Writing guidelines**:
93 - Use RFC 2119 keywords (SHALL, SHOULD, MAY) for requirement strength
94 - Derive requirements from actual code behavior, not aspirational features
95 - Include scenarios that reflect real code paths (check tests for scenario ideas)
96 - Reference source files in requirement descriptions when helpful (e.g., "Implemented in `src/core/workspace-manager.ts`")
97 - Keep requirements atomic — one concern per requirement
98 - Group related scenarios under their parent requirement
99
1005. **Write spec files**
101
102 For each capability:
103 ```bash
104 mkdir -p openspec/specs/<capability>
105 ```
106 Write the spec content to `openspec/specs/<capability>/spec.md`.
107
108 After writing each file, verify it exists and show brief progress.
109
1106. **Validate output**
111
112 Run validation if available:
113 ```bash
114 openspec validate --specs --json
115 ```
116
117 If validation fails, fix issues and re-validate.
118
1197. **Show summary**
120
121 Display what was generated:
122 ```
123 ## Specs Generated
124
125 | Capability | Requirements | Scenarios | Status |
126 |------------|-------------|-----------|--------|
127 | <name> | N | M | New/Merged/Overwritten |
128
129 Total: X capabilities, Y requirements, Z scenarios
130
131 Files written to `openspec/specs/`.
132 ```
133
134**Source Priority**
135
136When information conflicts across sources, prefer in this order:
1371. Actual code behavior (ground truth)
1382. Test assertions (verified behavior)
1393. BDD feature files / design docs (intended behavior)
1404. GitHub issues/PRs (discussed behavior)
1415. README / AGENTS.md (described behavior)
142
143**Guardrails**
144- Always confirm capability list with user before generating
145- Never fabricate requirements not supported by code or documentation
146- If a capability area is ambiguous, ask for clarification
147- Preserve existing spec content when merging (only add, don't remove unless user confirms)
148- Each spec file must have at least a Purpose section and one requirement
149- Use consistent formatting across all generated spec files