This document covers the specify init command and its internal implementation. Project initialization is the process of bootstrapping a new Spec Kit project by downloading templates from GitHub releases, extracting them to the target directory, and setting up Git repository infrastructure.
For information about the interactive selection UI used during initialization, see Interactive Selection System. For details on environment validation performed before initialization, see Environment Validation. For GitHub API integration and rate limiting, see GitHub API Integration.
The init command is the primary entry point for creating new Spec Kit projects. It coordinates template downloads, directory structure creation, Git initialization, and AI agent configuration. The command supports two main scenarios: creating a new project directory or initializing in the current directory.
Sources: src/specify_cli/__init__.py980-992
The init command accepts the following parameters:
| Parameter | Type | Purpose |
|---|---|---|
project_name | Argument | Target directory name (optional with --here, or use . for current directory) |
--ai | Option | AI assistant identifier (e.g., claude, gemini, copilot) |
--script | Option | Script type: sh (bash/zsh) or ps (PowerShell) |
--ignore-agent-tools | Flag | Skip CLI tool verification for selected AI agent |
--no-git | Flag | Skip Git repository initialization |
--here | Flag | Initialize in current directory instead of creating new directory |
--force | Flag | Skip confirmation when current directory is non-empty |
--skip-tls | Flag | Disable SSL/TLS verification (not recommended) |
--debug | Flag | Enable verbose diagnostic output |
--github-token | Option | GitHub API token for authenticated requests |
Sources: src/specify_cli/__init__.py981-991
Initialization Command Flow
This diagram shows the complete flow from command invocation to successful project initialization, including validation, selection, download, and setup phases.
Sources: src/specify_cli/__init__.py980-1269
The initialization process handles three directory scenarios:
New directory creation: specify init project-name
./project-name--force for new directories)Current directory with . syntax: specify init .
here = True internallyCurrent directory with --here flag: specify init --here
. syntax--here and project nameSources: src/specify_cli/__init__.py1020-1060
Templates are downloaded from GitHub releases as pre-packaged ZIP archives. Each release contains 32 package variants (16 AI agents × 2 script types).
Package names follow this pattern:
spec-kit-template-{agent}-{script}-v{version}.zip
Where:
{agent}: AI assistant identifier (e.g., claude, gemini, copilot){script}: Script type (sh or ps){version}: Semantic version (e.g., 0.1.0)Example: spec-kit-template-claude-sh-v0.1.0.zip
Template Package Selection Process
This diagram illustrates how the correct template package is identified and downloaded from the latest GitHub release.
Sources: src/specify_cli/__init__.py637-683
The download process uses the httpx library with SSL verification via truststore. It handles GitHub API rate limiting by parsing response headers and providing actionable error messages.
The system extracts rate limit information from GitHub API responses:
| Header | Purpose |
|---|---|
X-RateLimit-Limit | Total requests allowed per hour |
X-RateLimit-Remaining | Remaining requests in current window |
X-RateLimit-Reset | Timestamp when limit resets |
Retry-After | Seconds to wait before retry (on 429 errors) |
When rate limits are exceeded, the error message includes:
--github-token for authenticated requestsSources: src/specify_cli/__init__.py68-123
GitHub tokens can be provided via:
--github-token command line optionGH_TOKEN environment variableGITHUB_TOKEN environment variablePriority: CLI option > GH_TOKEN > GITHUB_TOKEN
Sources: src/specify_cli/__init__.py59-66
Template extraction handles two distinct scenarios with different merge behaviors:
For new project directories:
Directory Structure Flattening
This diagram shows how nested ZIP structures are automatically flattened during extraction.
Sources: src/specify_cli/__init__.py846-870
For initialization in existing directories:
.vscode/settings.json is merged, not overwrittenCurrent Directory Merge Logic
This diagram shows how template files are merged into existing project directories when using --here flag.
Sources: src/specify_cli/__init__.py800-844
For .vscode/settings.json, a deep merge is performed:
Sources: src/specify_cli/__init__.py594-635
After template extraction, three setup operations occur:
On non-Windows systems, all .sh scripts under .specify/scripts/ are made executable:
Script Permission Setup
This diagram shows how shell scripts are automatically made executable on Unix-like systems.
The permission logic:
Sources: src/specify_cli/__init__.py901-943
The constitution is initialized from the template:
Constitution Initialization
This diagram shows the constitution setup logic, which preserves existing constitutions during re-initialization.
Sources: src/specify_cli/__init__.py945-978
Git initialization follows this decision tree:
Git Initialization Decision Tree
This diagram shows the complete Git initialization logic including error handling and skip conditions.
The is_git_repo() function checks if a directory is within a Git working tree by running:
Sources: src/specify_cli/__init__.py515-568 src/specify_cli/__init__.py1169-1183
The initialization process integrates with StepTracker for live progress display. The tracker manages these steps:
| Step Key | Label | Status Updates |
|---|---|---|
precheck | Check required tools | Complete after environment validation |
ai-select | Select AI assistant | Complete after selection (interactive or CLI) |
script-select | Select script type | Complete after selection |
fetch | Fetch latest release | Running → Complete (with version info) |
download | Download template | Complete (with filename) |
extract | Extract template | Running → Complete |
zip-list | Archive contents | Complete (with entry count) |
extracted-summary | Extraction summary | Complete (with item count) |
chmod | Ensure scripts executable | Complete (with count) or Error (with failures) |
constitution | Constitution setup | Complete, Skip, or Error |
cleanup | Cleanup | Complete after ZIP removal |
git | Initialize git repository | Complete, Skip, or Error (with message) |
final | Finalize | Complete or Error |
The tracker is attached to a Live display that auto-refreshes as steps complete. See StepTracker and Progress Display for implementation details.
Sources: src/specify_cli/__init__.py1129-1202
After successful initialization, the project contains:
project-root/
├── .specify/
│ ├── memory/
│ │ └── constitution.md # Copied from constitution-template.md
│ ├── scripts/
│ │ ├── check-prerequisites.{sh,ps1}
│ │ ├── common.{sh,ps1}
│ │ ├── create-new-feature.{sh,ps1}
│ │ ├── setup-plan.{sh,ps1}
│ │ └── update-agent-context.{sh,ps1}
│ └── templates/
│ ├── constitution-template.md
│ ├── plan-template.md
│ ├── spec-template.md
│ └── tasks-template.md
├── .{agent}/ # Agent-specific directory
│ └── commands/ # Slash commands for AI agent
│ ├── constitution.{md,toml}
│ ├── specify.{md,toml}
│ ├── clarify.{md,toml}
│ ├── plan.{md,toml}
│ ├── tasks.{md,toml}
│ └── implement.{md,toml}
├── {AGENT}.md # Agent context file (e.g., CLAUDE.md)
├── .vscode/ # VS Code settings (if applicable)
│ └── settings.json
└── .git/ # Git repository (unless --no-git)
Where:
{agent}: Actual agent folder name from AGENT_CONFIG[selected_ai]["folder"]{sh,ps1}: Script type selected during initialization{md,toml}: Command format based on agent requirementsSources: src/specify_cli/__init__.py126-229
If initialization fails after directory creation:
--here initialization: files are left in place (no automatic rollback)Error Recovery Logic
This diagram shows the cleanup behavior when initialization fails.
Sources: src/specify_cli/__init__.py1186-1200
Git initialization failures are handled gracefully:
git stepThe error panel persists after the Live display closes, ensuring users see the Git error details.
Sources: src/specify_cli/__init__.py1174-1222
After successful initialization, three panels are displayed:
Warns users about potential credential storage in agent folders:
Some agents may store credentials, auth tokens, or other identifying and private
artifacts in the agent folder within your project.
Consider adding {agent_folder} (or parts of it) to .gitignore to prevent
accidental credential leakage.
Sources: src/specify_cli/__init__.py1224-1236
Provides sequential commands for getting started:
CODEX_HOME)/speckit.constitution, /speckit.specify, /speckit.plan, /speckit.tasks, /speckit.implementSources: src/specify_cli/__init__.py1238-1268
Lists optional quality-improvement commands:
/speckit.clarify: Structured clarification before planning/speckit.analyze: Cross-artifact consistency checking/speckit.checklist: Quality validation checklistsSources: src/specify_cli/__init__.py1270-1279
The AGENT_CONFIG dictionary defines properties for each supported AI agent:
Where:
name: Human-readable agent name for UI displayfolder: Directory name within project for agent-specific filesinstall_url: Installation documentation URL (None for IDE-based agents)requires_cli: Whether agent requires CLI tool verificationFor IDE-based agents (requires_cli: False):
--ignore-agent-tools flag is not neededSources: src/specify_cli/__init__.py126-229
The Codex CLI requires setting CODEX_HOME environment variable to the project's .codex directory. The next steps panel includes platform-specific commands:
export CODEX_HOME=/path/to/project/.codexsetx CODEX_HOME C:\path\to\project\.codexThe path is properly shell-quoted using shlex.quote() to handle spaces and special characters.
Sources: src/specify_cli/__init__.py1246-1256
Amazon Q Developer CLI does not support custom arguments for slash commands. This limitation is documented in the supported agents table and reflected in template generation.
Sources: README.md148
Refresh this wiki