Archive a completed change in the experimental workflow.
Store selection: If the user names a store (a store is a standalone OpenSpec repo registered on this machine) or the work lives in one, run openspec store list --json to discover registered store ids, then pass --store <id> on the commands that read or write specs and changes (new change, status, instructions, list, show, validate, archive, doctor, context, schemas, view). Once selected, treat --store <id> as sticky for the rest of the workflow. Every unscoped example of those commands below is shorthand: before running it, append the flag. For example, run openspec status --change "<name>" --json --store "<id>", not the unscoped form shown below. Other commands do not take the flag. Hints printed by commands already carry the flag; keep it on follow-ups. Without a store, commands act on the nearest local openspec/ root.
Project check: These steps expect a project that already uses OpenSpec. Before the first step that writes anything (new change, archive, sync specs, or authoring an artifact file), confirm the project has a root: run openspec list --json (with --store <id> when a store is selected, since the store is then the root) and read root. A root object means the project is set up. "root": null means it is not - there is no openspec/ directory here, and a write such as openspec new change would create one as a side effect. The command also exits non-zero, which is that answer rather than a broken CLI, so read the JSON instead of retrying or working around it.
One "root": null is not about setup: when a status error message starts with Declared in or Invalid store declaration in and names this project's openspec/config.yaml (or config.yml), the project does use OpenSpec through a store it declares, which this machine cannot resolve (the store is not registered, or the store: line is malformed). Do not treat it as uninitialized and skip the branches below: stop before writing and show the user that error's message and fix.
Otherwise, with no root, what happens next depends on how this workflow was reached:
- Auto-selected: you chose this workflow yourself, without the user naming OpenSpec, naming this skill, or running its slash command. Stop using OpenSpec and answer the request normally, as you would with no OpenSpec installed. Do not ask them to set anything up and do not mention OpenSpec setup.
- Explicit OpenSpec request: the user named OpenSpec, named this skill, or ran its slash command. Stop before writing and ask how to proceed: set this project up (
openspec init), target a store they already have (--store <id>), or continue without OpenSpec for this request. Wait for their answer.
In both branches, never create the root as a side effect: do not run openspec init until the user asks for it, do not hand-create openspec/ files, and do not let a command create it.
<capability-path> is the spec directory relative to specs/ (for example, user-auth or identity/user-auth). Preserve the full path from each delta spec when resolving its main spec.
Input: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
Steps
Select the change
If a name is provided, use it. Otherwise:
- Infer from conversation context if the user mentioned a change
- Auto-select if only one active change exists
- If ambiguous, run
openspec list --json to get available changes and ask the user to select one
When prompting, show only active changes (not already archived).
Include the schema used for each change if available.
Always announce: "Using change: " and how to override (e.g., /opsx:archive <other>).
Load current archive inputs before the existing archive checks:
After resolving the selected change and planning root, run:
openspec instructions archive --change "<name>" --json
Keep the same selected-root flags on this command. This lookup is advisory and
optional: it only supplies extra prompt inputs, so it must never block archiving.
If it exits non-zero or returns invalid JSON — for example on an older CLI that
does not support this command yet — continue the archive workflow with no
context and no operation guidance. Do not report an error and do not stop.
A successful response may omit both optional fields. Treat context as a
required prompt-level input: read and consider it, and apply relevant project
facts, conventions, and constraints. Treat operationGuidance as optional
additive advice: read and consider every entry, and follow entries that are
applicable and compatible with the built-in archive workflow.
Keep both fields separate from built-in steps, explicit user choices, resolved
paths, CLI checks, and command contracts. If context conflicts with one of those
controlling inputs, report the conflict and preserve the controlling value. If
guidance is inapplicable or conflicts with a controlling input, do not follow it
and explain why. Do not infer replacement paths, skipped prompts, or flags from
either field, and do not copy their text verbatim into specs, change artifacts,
or archive summaries unless the user separately asks for it. These are
prompt-level behavior contracts, not enforceable checks.
Check artifact completion status
Run openspec status --change "<name>" --json to check artifact completion.
Parse the JSON to understand:
schemaName: The workflow being used
planningHome, changeRoot, artifactPaths, and actionContext: path and scope context
artifacts: List of artifacts with their status (done, skipped, or other)
If any artifacts are neither done nor skipped (skipped artifacts satisfy the requirement - the change declares skip_specs):
- Display warning listing incomplete artifacts
- Ask the user to confirm they want to proceed
- Proceed if user confirms
Check task completion status
Read the tasks file (typically tasks.md) to check for incomplete tasks.
A checkbox is complete when its only content is x or X; spacing inside
the brackets does not matter, so - [ x] counts as complete too. Every
other marker is incomplete - - [ ], an empty - [], and markers OpenSpec
assigns no meaning to such as - [~] or - [-]. Never read an unfamiliar
marker as complete.
If incomplete tasks found:
- Display warning showing count of incomplete tasks
- Ask the user to confirm they want to proceed
- Proceed if user confirms
If no tasks file exists: Proceed without task-related warning.
Assess delta spec sync state
Use artifactPaths.specs.existingOutputPaths from status JSON as the only
delta-spec source. If the specs entry is missing or
existingOutputPaths is empty, proceed without a sync prompt and do not infer
delta specs from other artifacts.
If delta specs exist:
- Compare each delta spec with its corresponding main spec at
<planningHome.root>/openspec/specs/<capability-path>/spec.md (use the store-aware planningHome.root from step 2, not a hardcoded repo path)
- A missing main spec is not automatically "already synced". For a new capability, the main spec is an output of the sync, not an input:
- If the delta has MODIFIED or RENAMED requirements, report that only ADDED requirements can create a new main spec and mark that capability as sync-blocked. Never invent a requirement that has no current version.
- Otherwise, if the delta has only REMOVED requirements and the change's
.openspec.yaml declares retire_capabilities: true, the capability is already retired: count it as already synced, warn that there is nothing left to remove, and do not recreate the main spec. Apply this rule both now and when verifying a completed sync.
- Otherwise, if the delta has no ADDED requirements, report that no sync is possible and mark that capability as sync-blocked. For a REMOVED-only delta, warn that there is no main spec to remove from and leave the main-spec tree unchanged.
openspec archive refuses the unmarked REMOVED-only case with Spec must have at least one requirement.
- Otherwise, count the capability as needing sync and name it in the summary (
<capability-path>: new main spec will be created). If the delta also has REMOVED requirements, warn that they will be ignored because there is no main spec to remove from. The sync creates the main spec from only the delta's ADDED requirements, exactly as openspec archive does.
- Determine what changes would be applied (adds, modifications, removals, renames)
- Continue assessing the remaining capabilities even when one is sync-blocked. Show a combined summary before prompting.
Prompt options:
- If any capability is sync-blocked: explain why and offer only "Archive without syncing", "Cancel"
- Otherwise, if changes needed: "Sync now (recommended)", "Archive without syncing"
- Otherwise, if already synced: "Archive now", "Sync anyway", "Cancel"
Route on the answer:
- "Cancel" — stop, do not archive
- "Archive without syncing" or "Archive now" — proceed to archive
- "Sync now" or "Sync anyway" — sync, then verify (below). Do not start any sync while a capability is sync-blocked; explain the blocker and repeat the available choices.
- Anything else — ask again rather than archiving
Before a selected sync writes any main spec, run
openspec instructions specs --change "<name>" --json once with the same
selected-root flags. Require a zero exit status and valid artifact-instruction
JSON. If the lookup fails or returns invalid JSON, report the error and stop
before writing any main spec or moving the change. A valid response with omitted
rules is the no-rules case. Apply returned rules only to the content and
form of main specs produced by this merge; do not use them as archive guidance,
change CLI behavior, or copy the rule text into any output file.
Then run the openspec-sync-specs workflow inline (agent-driven intelligent merge) for change '', passing the delta spec analysis and the fetched specs-rule snapshot from above, and wait for it to finish. The inline sync must reuse that snapshot without fetching specs instructions again. Do not delegate it to a background task — step 5 would move changeRoot out from under a sync that is still reading it, leaving the change archived and the main specs never updated. If your agent can only run it by delegation, delegate synchronously and wait for the result.
Then re-run the comparison from the top of this step, including the explicitly retired, missing-spec case, against every capability that has a delta spec in artifactPaths.specs.existingOutputPaths — not only the ones the sync reports it touched. A successful sync leaves nothing left to apply, so each capability must now read as already synced:
- ADDED requirements present
- MODIFIED requirements carrying the scenario and description changes named in the delta, with their other scenarios intact
- REMOVED requirements gone — and where this sync retired a capability (removed its last requirement, leaving
## Requirements empty), its main spec deleted rather than left empty; a spec the sync deliberately kept and reported is also a match
- RENAMED requirements present under the new name and absent under the old one
If the sync failed, or any capability does not match, report what differs and stop — do not archive. Nothing has moved and changeRoot is intact, so the user can fix the mismatch or re-run the sync and start the archive again.
Perform the archive
Create an archive directory under planningHome.changesDir if it doesn't exist:
mkdir -p "<planningHome.changesDir>/archive"
Generate the target name: use the change name as-is when it already starts with a YYYY-MM-DD- prefix; otherwise prepend the current date as YYYY-MM-DD-<change-name>. Never stack a second date (same rule as openspec archive).
Check if target already exists:
- If yes: Fail with error, suggest renaming existing archive or using different date
- If no: Move
changeRoot to the archive directory
mv "<changeRoot>" "<planningHome.changesDir>/archive/<target-name>"
Display summary
Show archive completion summary including:
- Change name
- Schema that was used
- Archive location
- Whether specs were synced (if applicable)
- Note about any warnings (incomplete artifacts/tasks)
Output On Success
## Archive Complete
**Change:** <change-name>
**Schema:** <schema-name>
**Archived to:** the archive path derived from `planningHome.changesDir`/<target-name>/
**Specs:** <"✓ Synced to main specs" only if the step 4 verification passed; otherwise "No delta specs" or "Sync skipped">
<"All artifacts complete. All tasks complete." — or, if archived with warnings, list them instead (e.g. "Archived with 2 incomplete tasks")>
Guardrails
- Announce the selected change; prompt for selection when it is ambiguous
- Use artifact graph (openspec status --json) for completion checking
- Don't block archive on warnings - just inform and confirm
- Preserve .openspec.yaml when moving to archive (it moves with the directory)
- Show clear summary of what happened
- If sync is requested, run the
openspec-sync-specs workflow inline (agent-driven)
- Never archive while a spec sync is still in flight — run the sync inline and verify the main specs before moving
changeRoot
- If delta specs exist, always run the sync assessment and show the combined summary before prompting
- Apply relevant runtime context and report conflicts; operation guidance remains advisory
- Consider every guidance entry and explain any inapplicable or conflicting advice
- Existing CLI checks, resolved paths, prompts, and command contracts are unchanged
- Artifact rules constrain only the specs being written and are never operation guidance
- Never copy runtime context, operation guidance, or artifact-rule text verbatim into output files
1---2name: openspec-archive-change3description: Archive a completed OpenSpec change in the experimental workflow. Use when the user wants to finalize and archive a change after implementation is complete. Also use when the user says "openspec archive" or "opsx archive".4license: MIT5---67Archive a completed change in the experimental workflow.89**Store selection:** If the user names a store (a store is a standalone OpenSpec repo registered on this machine) or the work lives in one, run `openspec store list --json` to discover registered store ids, then pass `--store <id>` on the commands that read or write specs and changes (`new change`, `status`, `instructions`, `list`, `show`, `validate`, `archive`, `doctor`, `context`, `schemas`, `view`). Once selected, treat `--store <id>` as sticky for the rest of the workflow. Every unscoped example of those commands below is shorthand: before running it, append the flag. For example, run `openspec status --change "<name>" --json --store "<id>"`, not the unscoped form shown below. Other commands do not take the flag. Hints printed by commands already carry the flag; keep it on follow-ups. Without a store, commands act on the nearest local `openspec/` root.1011**Project check:** These steps expect a project that already uses OpenSpec. Before the first step that writes anything (`new change`, `archive`, `sync specs`, or authoring an artifact file), confirm the project has a root: run `openspec list --json` (with `--store <id>` when a store is selected, since the store is then the root) and read `root`. A root object means the project is set up. `"root": null` means it is not - there is no `openspec/` directory here, and a write such as `openspec new change` would create one as a side effect. The command also exits non-zero, which is that answer rather than a broken CLI, so read the JSON instead of retrying or working around it.1213One `"root": null` is not about setup: when a `status` error message starts with `Declared in` or `Invalid store declaration in` and names this project's `openspec/config.yaml` (or `config.yml`), the project does use OpenSpec through a store it declares, which this machine cannot resolve (the store is not registered, or the `store:` line is malformed). Do not treat it as uninitialized and skip the branches below: stop before writing and show the user that error's `message` and `fix`.1415Otherwise, with no root, what happens next depends on how this workflow was reached:1617- **Auto-selected**: you chose this workflow yourself, without the user naming OpenSpec, naming this skill, or running its slash command. Stop using OpenSpec and answer the request normally, as you would with no OpenSpec installed. Do not ask them to set anything up and do not mention OpenSpec setup.18- **Explicit OpenSpec request**: the user named OpenSpec, named this skill, or ran its slash command. Stop before writing and ask how to proceed: set this project up (`openspec init`), target a store they already have (`--store <id>`), or continue without OpenSpec for this request. Wait for their answer.1920In both branches, never create the root as a side effect: do not run `openspec init` until the user asks for it, do not hand-create `openspec/` files, and do not let a command create it.2122`<capability-path>` is the spec directory relative to `specs/` (for example, `user-auth` or `identity/user-auth`). Preserve the full path from each delta spec when resolving its main spec.2324**Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.2526**Steps**27281. **Select the change**2930 If a name is provided, use it. Otherwise:31 - Infer from conversation context if the user mentioned a change32 - Auto-select if only one active change exists33 - If ambiguous, run `openspec list --json` to get available changes and ask the user to select one3435 When prompting, show only active changes (not already archived).36 Include the schema used for each change if available.3738 Always announce: "Using change: <name>" and how to override (e.g., `/opsx:archive <other>`).3940 **Load current archive inputs before the existing archive checks:**4142 After resolving the selected change and planning root, run:43 ```bash44 openspec instructions archive --change "<name>" --json45 ```46 Keep the same selected-root flags on this command. This lookup is advisory and47 optional: it only supplies extra prompt inputs, so it must never block archiving.48 If it exits non-zero or returns invalid JSON — for example on an older CLI that49 does not support this command yet — continue the archive workflow with no50 context and no operation guidance. Do not report an error and do not stop.5152 A successful response may omit both optional fields. Treat `context` as a53 required prompt-level input: read and consider it, and apply relevant project54 facts, conventions, and constraints. Treat `operationGuidance` as optional55 additive advice: read and consider every entry, and follow entries that are56 applicable and compatible with the built-in archive workflow.5758 Keep both fields separate from built-in steps, explicit user choices, resolved59 paths, CLI checks, and command contracts. If context conflicts with one of those60 controlling inputs, report the conflict and preserve the controlling value. If61 guidance is inapplicable or conflicts with a controlling input, do not follow it62 and explain why. Do not infer replacement paths, skipped prompts, or flags from63 either field, and do not copy their text verbatim into specs, change artifacts,64 or archive summaries unless the user separately asks for it. These are65 prompt-level behavior contracts, not enforceable checks.66672. **Check artifact completion status**6869 Run `openspec status --change "<name>" --json` to check artifact completion.7071 Parse the JSON to understand:72 - `schemaName`: The workflow being used73 - `planningHome`, `changeRoot`, `artifactPaths`, and `actionContext`: path and scope context74 - `artifacts`: List of artifacts with their status (`done`, `skipped`, or other)7576 **If any artifacts are neither `done` nor `skipped`** (skipped artifacts satisfy the requirement - the change declares skip_specs):77 - Display warning listing incomplete artifacts78 - Ask the user to confirm they want to proceed79 - Proceed if user confirms80813. **Check task completion status**8283 Read the tasks file (typically `tasks.md`) to check for incomplete tasks.8485 A checkbox is complete when its only content is `x` or `X`; spacing inside86 the brackets does not matter, so `- [ x]` counts as complete too. Every87 other marker is incomplete - `- [ ]`, an empty `- []`, and markers OpenSpec88 assigns no meaning to such as `- [~]` or `- [-]`. Never read an unfamiliar89 marker as complete.9091 **If incomplete tasks found:**92 - Display warning showing count of incomplete tasks93 - Ask the user to confirm they want to proceed94 - Proceed if user confirms9596 **If no tasks file exists:** Proceed without task-related warning.97984. **Assess delta spec sync state**99100 Use `artifactPaths.specs.existingOutputPaths` from status JSON as the only101 delta-spec source. If the `specs` entry is missing or102 `existingOutputPaths` is empty, proceed without a sync prompt and do not infer103 delta specs from other artifacts.104105 **If delta specs exist:**106 - Compare each delta spec with its corresponding main spec at `<planningHome.root>/openspec/specs/<capability-path>/spec.md` (use the store-aware `planningHome.root` from step 2, not a hardcoded repo path)107 - A missing main spec is **not automatically** "already synced". For a new capability, the main spec is an *output* of the sync, not an input:108 - If the delta has MODIFIED or RENAMED requirements, report that only ADDED requirements can create a new main spec and mark that capability as sync-blocked. Never invent a requirement that has no current version.109 - Otherwise, if the delta has only REMOVED requirements and the change's `.openspec.yaml` declares `retire_capabilities: true`, the capability is already retired: count it as already synced, warn that there is nothing left to remove, and do not recreate the main spec. Apply this rule both now and when verifying a completed sync.110 - Otherwise, if the delta has no ADDED requirements, report that no sync is possible and mark that capability as sync-blocked. For a REMOVED-only delta, warn that there is no main spec to remove from and leave the main-spec tree unchanged. `openspec archive` refuses the unmarked REMOVED-only case with `Spec must have at least one requirement`.111 - Otherwise, count the capability as needing sync and name it in the summary (`<capability-path>: new main spec will be created`). If the delta also has REMOVED requirements, warn that they will be ignored because there is no main spec to remove from. The sync creates the main spec from only the delta's ADDED requirements, exactly as `openspec archive` does.112 - Determine what changes would be applied (adds, modifications, removals, renames)113 - Continue assessing the remaining capabilities even when one is sync-blocked. Show a combined summary before prompting.114115 **Prompt options:**116 - If any capability is sync-blocked: explain why and offer only "Archive without syncing", "Cancel"117 - Otherwise, if changes needed: "Sync now (recommended)", "Archive without syncing"118 - Otherwise, if already synced: "Archive now", "Sync anyway", "Cancel"119120 Route on the answer:121 - "Cancel" — stop, do not archive122 - "Archive without syncing" or "Archive now" — proceed to archive123 - "Sync now" or "Sync anyway" — sync, then verify (below). Do not start any sync while a capability is sync-blocked; explain the blocker and repeat the available choices.124 - Anything else — ask again rather than archiving125126 Before a selected sync writes any main spec, run127 `openspec instructions specs --change "<name>" --json` once with the same128 selected-root flags. Require a zero exit status and valid artifact-instruction129 JSON. If the lookup fails or returns invalid JSON, report the error and stop130 before writing any main spec or moving the change. A valid response with omitted131 `rules` is the no-rules case. Apply returned `rules` only to the content and132 form of main specs produced by this merge; do not use them as archive guidance,133 change CLI behavior, or copy the rule text into any output file.134135 Then run the `openspec-sync-specs` workflow inline (agent-driven intelligent merge) for change '<name>', passing the delta spec analysis and the fetched specs-rule snapshot from above, and wait for it to finish. The inline sync must reuse that snapshot without fetching `specs` instructions again. Do not delegate it to a background task — step 5 would move `changeRoot` out from under a sync that is still reading it, leaving the change archived and the main specs never updated. If your agent can only run it by delegation, delegate synchronously and wait for the result.136137 Then re-run the comparison from the top of this step, including the explicitly retired, missing-spec case, against every capability that has a delta spec in `artifactPaths.specs.existingOutputPaths` — not only the ones the sync reports it touched. A successful sync leaves nothing left to apply, so each capability must now read as already synced:138 - ADDED requirements present139 - MODIFIED requirements carrying the scenario and description changes named in the delta, with their other scenarios intact140 - REMOVED requirements gone — and where this sync retired a capability (removed its last requirement, leaving `## Requirements` empty), its main spec deleted rather than left empty; a spec the sync deliberately kept and reported is also a match141 - RENAMED requirements present under the new name and absent under the old one142143 If the sync failed, or any capability does not match, report what differs and stop — do not archive. Nothing has moved and `changeRoot` is intact, so the user can fix the mismatch or re-run the sync and start the archive again.1441455. **Perform the archive**146147 Create an `archive` directory under `planningHome.changesDir` if it doesn't exist:148 ```bash149 mkdir -p "<planningHome.changesDir>/archive"150 ```151152 Generate the target name: use the change name as-is when it already starts with a `YYYY-MM-DD-` prefix; otherwise prepend the current date as `YYYY-MM-DD-<change-name>`. Never stack a second date (same rule as `openspec archive`).153154 **Check if target already exists:**155 - If yes: Fail with error, suggest renaming existing archive or using different date156 - If no: Move `changeRoot` to the archive directory157158 ```bash159 mv "<changeRoot>" "<planningHome.changesDir>/archive/<target-name>"160 ```1611626. **Display summary**163164 Show archive completion summary including:165 - Change name166 - Schema that was used167 - Archive location168 - Whether specs were synced (if applicable)169 - Note about any warnings (incomplete artifacts/tasks)170171**Output On Success**172173```markdown174## Archive Complete175176**Change:** <change-name>177**Schema:** <schema-name>178**Archived to:** the archive path derived from `planningHome.changesDir`/<target-name>/179**Specs:** <"✓ Synced to main specs" only if the step 4 verification passed; otherwise "No delta specs" or "Sync skipped">180181<"All artifacts complete. All tasks complete." — or, if archived with warnings, list them instead (e.g. "Archived with 2 incomplete tasks")>182```183184**Guardrails**185- Announce the selected change; prompt for selection when it is ambiguous186- Use artifact graph (openspec status --json) for completion checking187- Don't block archive on warnings - just inform and confirm188- Preserve .openspec.yaml when moving to archive (it moves with the directory)189- Show clear summary of what happened190- If sync is requested, run the `openspec-sync-specs` workflow inline (agent-driven)191- Never archive while a spec sync is still in flight — run the sync inline and verify the main specs before moving `changeRoot`192- If delta specs exist, always run the sync assessment and show the combined summary before prompting193- Apply relevant runtime context and report conflicts; operation guidance remains advisory194- Consider every guidance entry and explain any inapplicable or conflicting advice195- Existing CLI checks, resolved paths, prompts, and command contracts are unchanged196- Artifact rules constrain only the specs being written and are never operation guidance197- Never copy runtime context, operation guidance, or artifact-rule text verbatim into output files