Files
Tabish Bidiwale 938d03be9a feat(init): add IDE restart instruction after init (#323)
Add prominent restart instruction in success message to inform users
they need to restart their IDE/coding tool for slash commands to appear.
Applies to all tools when slash commands are created or refreshed.

Also updates cli-init spec to document the restart instruction requirement.
2025-11-21 20:29:53 +11:00

18 KiB

CLI Init Specification

Purpose

The openspec init command SHALL create a complete OpenSpec directory structure in any project, enabling immediate adoption of OpenSpec conventions with support for multiple AI coding assistants.

Requirements

Requirement: Progress Indicators

The command SHALL display progress indicators during initialization to provide clear feedback about each step.

Scenario: Displaying initialization progress

  • WHEN executing initialization steps
  • THEN validate environment silently in background (no output unless error)
  • AND display progress with ora spinners:
    • Show spinner: "⠋ Creating OpenSpec structure..."
    • Then success: "✔ OpenSpec structure created"
    • Show spinner: "⠋ Configuring AI tools..."
    • Then success: "✔ AI tools configured"

Requirement: Directory Creation

The command SHALL create the complete OpenSpec directory structure with all required directories and files.

Scenario: Creating OpenSpec structure

  • WHEN openspec init is executed
  • THEN create the following directory structure:
openspec/
├── project.md
├── AGENTS.md
├── specs/
└── changes/
    └── archive/

Requirement: File Generation

The command SHALL generate required template files with appropriate content for immediate use.

Scenario: Generating template files

  • WHEN initializing OpenSpec
  • THEN generate openspec/AGENTS.md containing complete OpenSpec instructions for AI assistants
  • AND generate project.md with project context template

Requirement: AI Tool Configuration

The command SHALL configure AI coding assistants with OpenSpec instructions using a grouped selection experience so teams can enable native integrations while always provisioning guidance for other assistants.

Scenario: Prompting for AI tool selection

  • WHEN run interactively
  • THEN present a multi-select wizard that separates options into two headings:
    • Natively supported providers shows each available first-party integration (Claude Code, Cursor, OpenCode, …) with checkboxes
    • Other tools explains that the root-level AGENTS.md stub is always generated for AGENTS-compatible assistants and cannot be deselected
  • AND mark already configured native tools with "(already configured)" to signal that choosing them will refresh managed content
  • AND keep disabled or unavailable providers labelled as "coming soon" so users know they cannot opt in yet
  • AND allow confirming the selection even when no native provider is chosen because the root stub remains enabled by default
  • AND change the base prompt copy in extend mode to "Which natively supported AI tools would you like to add or refresh?"

Requirement: AI Tool Configuration Details

The command SHALL properly configure selected AI tools with OpenSpec-specific instructions using a marker system.

Scenario: Configuring Claude Code

  • WHEN Claude Code is selected
  • THEN create or update CLAUDE.md in the project root directory (not inside openspec/)
  • AND populate the managed block with a short stub that points teammates to @/openspec/AGENTS.md

Scenario: Configuring CodeBuddy Code

  • WHEN CodeBuddy Code is selected
  • THEN create or update CODEBUDDY.md in the project root directory (not inside openspec/)
  • AND populate the managed block with a short stub that points teammates to @/openspec/AGENTS.md

Scenario: Configuring Cline

  • WHEN Cline is selected
  • THEN create or update CLINE.md in the project root directory (not inside openspec/)
  • AND populate the managed block with a short stub that points teammates to @/openspec/AGENTS.md

Scenario: Configuring iFlow CLI

  • WHEN iFlow CLI is selected
  • THEN create or update IFLOW.md in the project root directory (not inside openspec/)
  • AND populate the managed block with a short stub that points teammates to @/openspec/AGENTS.md

Scenario: Creating new CLAUDE.md

  • WHEN CLAUDE.md does not exist
  • THEN create new file with stub instructions wrapped in markers so the full workflow stays in openspec/AGENTS.md:
<!-- OPENSPEC:START -->
# OpenSpec Instructions

This project uses OpenSpec to manage AI assistant workflows.

- Full guidance lives in '@/openspec/AGENTS.md'.
- Keep this managed block so 'openspec update' can refresh the instructions.
<!-- OPENSPEC:END -->

Requirement: Interactive Mode

The command SHALL provide an interactive menu for AI tool selection with clear navigation instructions.

Scenario: Displaying interactive menu

  • WHEN run in fresh or extend mode
  • THEN present a looping select menu that lets users toggle tools with Space and review selections with Enter
  • AND when Enter is pressed on a highlighted selectable tool that is not already selected, automatically add it to the selection before moving to review so the highlighted tool is configured
  • AND label already configured tools with "(already configured)" while keeping disabled options marked "coming soon"
  • AND change the prompt copy in extend mode to "Which AI tools would you like to add or refresh?"
  • AND display inline instructions clarifying that Space toggles tools and Enter selects the highlighted tool before reviewing selections

Requirement: Safety Checks

The command SHALL perform safety checks to prevent overwriting existing structures and ensure proper permissions.

Scenario: Detecting existing initialization

  • WHEN the openspec/ directory already exists
  • THEN inform the user that OpenSpec is already initialized, skip recreating the base structure, and enter an extend mode
  • AND continue to the AI tool selection step so additional tools can be configured
  • AND display the existing-initialization error message only when the user declines to add any AI tools

Requirement: Success Output

The command SHALL provide clear, actionable next steps upon successful initialization.

Scenario: Displaying success message

  • WHEN initialization completes successfully
  • THEN include prompt: "Please explain the OpenSpec workflow from openspec/AGENTS.md and how I should work with you on this project"

Scenario: Displaying restart instruction

  • WHEN initialization completes successfully and tools were created or refreshed
  • THEN display a prominent restart instruction before the "Next steps" section
  • AND inform users that slash commands are loaded at startup
  • AND instruct users to restart their coding assistant to ensure /openspec commands appear

Requirement: Exit Codes

The command SHALL use consistent exit codes to indicate different failure modes.

Scenario: Returning exit codes

  • WHEN the command completes
  • THEN return appropriate exit code:
    • 0: Success
    • 1: General error (including when OpenSpec directory already exists)
    • 2: Insufficient permissions (reserved for future use)
    • 3: User cancelled operation (reserved for future use)

Requirement: Additional AI Tool Initialization

openspec init SHALL allow users to add configuration files for new AI coding assistants after the initial setup.

Scenario: Configuring an extra tool after initial setup

  • GIVEN an openspec/ directory already exists and at least one AI tool file is present
  • WHEN the user runs openspec init and selects a different supported AI tool
  • THEN generate that tool's configuration files with OpenSpec markers the same way as during first-time initialization
  • AND leave existing tool configuration files unchanged except for managed sections that need refreshing
  • AND exit with code 0 and display a success summary highlighting the newly added tool files

Requirement: Success Output Enhancements

openspec init SHALL summarize tool actions when initialization or extend mode completes.

Scenario: Showing tool summary

  • WHEN the command completes successfully
  • THEN display a categorized summary of tools that were created, refreshed, or skipped (including already-configured skips)
  • AND personalize the "Next steps" header using the names of the selected tools, defaulting to a generic label when none remain

Requirement: Exit Code Adjustments

openspec init SHALL treat extend mode without new native tool selections as a successful refresh.

Scenario: Allowing empty extend runs

  • WHEN OpenSpec is already initialized and the user selects no additional natively supported tools
  • THEN complete successfully while refreshing the root AGENTS.md stub
  • AND exit with code 0

Requirement: Slash Command Configuration

The init command SHALL generate slash command files for supported editors using shared templates.

Scenario: Generating slash commands for Claude Code

  • WHEN the user selects Claude Code during initialization
  • THEN create .claude/commands/openspec/proposal.md, .claude/commands/openspec/apply.md, and .claude/commands/openspec/archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for CodeBuddy Code

  • WHEN the user selects CodeBuddy Code during initialization
  • THEN create .codebuddy/commands/openspec/proposal.md, .codebuddy/commands/openspec/apply.md, and .codebuddy/commands/openspec/archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Cline

  • WHEN the user selects Cline during initialization
  • THEN create .clinerules/openspec-proposal.md, .clinerules/openspec-apply.md, and .clinerules/openspec-archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND include Cline-specific Markdown heading frontmatter
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Crush

  • WHEN the user selects Crush during initialization
  • THEN create .crush/commands/openspec/proposal.md, .crush/commands/openspec/apply.md, and .crush/commands/openspec/archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND include Crush-specific frontmatter with OpenSpec category and tags
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Cursor

  • WHEN the user selects Cursor during initialization
  • THEN create .cursor/commands/openspec-proposal.md, .cursor/commands/openspec-apply.md, and .cursor/commands/openspec-archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Factory Droid

  • WHEN the user selects Factory Droid during initialization
  • THEN create .factory/commands/openspec-proposal.md, .factory/commands/openspec-apply.md, and .factory/commands/openspec-archive.md
  • AND populate each file from shared templates that include Factory-compatible YAML frontmatter for the description and argument-hint fields
  • AND include the $ARGUMENTS placeholder in the template body so droid receives any user-supplied input
  • AND wrap the generated content in OpenSpec managed markers so openspec update can safely refresh the commands

Scenario: Generating slash commands for OpenCode

  • WHEN the user selects OpenCode during initialization
  • THEN create .opencode/commands/openspec-proposal.md, .opencode/commands/openspec-apply.md, and .opencode/commands/openspec-archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Windsurf

  • WHEN the user selects Windsurf during initialization
  • THEN create .windsurf/workflows/openspec-proposal.md, .windsurf/workflows/openspec-apply.md, and .windsurf/workflows/openspec-archive.md
  • AND populate each file from shared templates (wrapped in OpenSpec markers) so workflow text matches other tools
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Kilo Code

  • WHEN the user selects Kilo Code during initialization
  • THEN create .kilocode/workflows/openspec-proposal.md, .kilocode/workflows/openspec-apply.md, and .kilocode/workflows/openspec-archive.md
  • AND populate each file from shared templates (wrapped in OpenSpec markers) so workflow text matches other tools
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Codex

  • WHEN the user selects Codex during initialization
  • THEN create global prompt files at ~/.codex/prompts/openspec-proposal.md, ~/.codex/prompts/openspec-apply.md, and ~/.codex/prompts/openspec-archive.md (or under $CODEX_HOME/prompts if set)
  • AND populate each file from shared templates that map the first numbered placeholder ($1) to the primary user input (e.g., change identifier or question text)
  • AND wrap the generated content in OpenSpec markers so openspec update can refresh the prompts without touching surrounding custom notes

Scenario: Generating slash commands for GitHub Copilot

  • WHEN the user selects GitHub Copilot during initialization
  • THEN create .github/prompts/openspec-proposal.prompt.md, .github/prompts/openspec-apply.prompt.md, and .github/prompts/openspec-archive.prompt.md
  • AND populate each file with YAML frontmatter containing a description field that summarizes the workflow stage
  • AND include $ARGUMENTS placeholder to capture user input
  • AND wrap the shared template body with OpenSpec markers so openspec update can refresh the content
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for Gemini CLI

  • WHEN the user selects Gemini CLI during initialization
  • THEN create .gemini/commands/openspec/proposal.toml, .gemini/commands/openspec/apply.toml, and .gemini/commands/openspec/archive.toml
  • AND populate each file as TOML that sets a stage-specific description = "<summary>" and a multi-line prompt = """ block with the shared OpenSpec template
  • AND wrap the OpenSpec managed markers (<!-- OPENSPEC:START --> / <!-- OPENSPEC:END -->) inside the prompt value so openspec update can safely refresh the body between markers without touching the TOML framing
  • AND ensure the slash-command copy matches the existing proposal/apply/archive templates used by other tools

Scenario: Generating slash commands for iFlow CLI

  • WHEN the user selects iFlow CLI during initialization
  • THEN create .iflow/commands/openspec-proposal.md, .iflow/commands/openspec-apply.md, and .iflow/commands/openspec-archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND include YAML frontmatter with name, id, category, and description fields for each command
  • AND wrap the generated content in OpenSpec managed markers so openspec update can safely refresh the commands
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Scenario: Generating slash commands for RooCode

  • WHEN the user selects RooCode during initialization
  • THEN create .roo/commands/openspec-proposal.md, .roo/commands/openspec-apply.md, and .roo/commands/openspec-archive.md
  • AND populate each file from shared templates so command text matches other tools
  • AND include simple Markdown headings (e.g., # OpenSpec: Proposal) without YAML frontmatter
  • AND wrap the generated content in OpenSpec managed markers where applicable so openspec update can safely refresh the commands
  • AND each template includes instructions for the relevant OpenSpec workflow stage

Requirement: Non-Interactive Mode

The command SHALL support non-interactive operation through command-line options for automation and CI/CD use cases.

Scenario: Select all tools non-interactively

  • WHEN run with --tools all
  • THEN automatically select every available AI tool without prompting
  • AND proceed with initialization using the selected tools

Scenario: Select specific tools non-interactively

  • WHEN run with --tools claude,cursor
  • THEN parse the comma-separated tool IDs and validate against available tools
  • AND proceed with initialization using only the specified valid tools

Scenario: Skip tool configuration non-interactively

  • WHEN run with --tools none
  • THEN skip AI tool configuration entirely
  • AND only create the OpenSpec directory structure and template files

Scenario: Invalid tool specification

  • WHEN run with --tools containing any IDs not present in the AI tool registry
  • THEN exit with code 1 and display available values (all, none, or the supported tool IDs)

Scenario: Help text lists available tool IDs

  • WHEN displaying CLI help for openspec init
  • THEN show the --tools option description with the valid values derived from the AI tool registry

Requirement: Root instruction stub

openspec init SHALL always scaffold the root-level AGENTS.md hand-off so every teammate finds the primary OpenSpec instructions.

Scenario: Creating root AGENTS.md

  • GIVEN the project may or may not already contain an AGENTS.md file
  • WHEN initialization completes in fresh or extend mode
  • THEN create or refresh AGENTS.md at the repository root using the managed marker block from TemplateManager.getAgentsStandardTemplate()
  • AND preserve any existing content outside the managed markers while replacing the stub text inside them
  • AND create the stub regardless of which native AI tools are selected

Why

Manual creation of OpenSpec structure is error-prone and creates adoption friction. A standardized init command ensures:

  • Consistent structure across all projects
  • Proper AI instruction files are always included
  • Quick onboarding for new projects
  • Clear conventions from the start