This document explains how feature branches and specification directories are created in the Spec-Driven Development workflow. The create-new-feature scripts (bash and PowerShell) automatically generate sequential branch numbers, create human-readable branch names from feature descriptions, and initialize the necessary directory structure for specifications. This process occurs before the /speckit.specify command (see 5.3) generates the actual specification content.
For information about the broader cross-platform script architecture, see Cross-Platform Script Architecture.
The system provides two functionally equivalent scripts that handle feature initialization:
| Script | Path | Purpose |
|---|---|---|
| Bash | scripts/bash/create-new-feature.sh | Unix/Linux/macOS environments |
| PowerShell | scripts/powershell/create-new-feature.ps1 | Windows/cross-platform environments |
Both scripts are invoked by AI agents during the /speckit.specify command execution. They create a new Git branch (if Git is available), generate a unique feature number, create the specification directory structure, and initialize the spec file from a template.
Sources: scripts/bash/create-new-feature.sh1-298 scripts/powershell/create-new-feature.ps11-283
| Option | Type | Description |
|---|---|---|
--json / -Json | Flag | Output results in JSON format instead of plain text |
--short-name / -ShortName | String | Override automatic branch name generation with custom name |
--number / -Number | Integer | Manually specify branch number (bypasses auto-detection) |
<feature_description> | Required | Natural language description of the feature |
The scripts produce structured output containing the generated branch information:
Plain Text Mode:
BRANCH_NAME: 003-user-authentication
SPEC_FILE: /path/to/specs/003-user-authentication/spec.md
FEATURE_NUM: 003
SPECIFY_FEATURE environment variable set to: 003-user-authentication
JSON Mode (--json):
Sources: scripts/bash/create-new-feature.sh43-55 scripts/bash/create-new-feature.sh290-297 scripts/powershell/create-new-feature.ps114-28 scripts/powershell/create-new-feature.ps1268-282
The scripts must operate from anywhere within the repository hierarchy. They use a fallback strategy to locate the repository root:
find_repo_root()This dual-mode operation ensures the scripts function in repositories initialized with --no-git, while still leveraging Git's branch tracking when available.
Sources: scripts/bash/create-new-feature.sh70-81 scripts/bash/create-new-feature.sh161-173 scripts/powershell/create-new-feature.ps141-60 scripts/powershell/create-new-feature.ps1132-148
The system ensures unique, sequential branch numbers by examining both Git branches and spec directories, then selecting the next available number.
get_highest_from_branches()The function examines all branches (local and remote) to find the highest feature number:
Key operations:
git branch -a to list all branches*, whitespace, remotes/origin/ prefixes^[0-9]{3}-Sources: scripts/bash/create-new-feature.sh103-127
get_highest_from_specs()The function scans the specs/ directory for existing feature folders:
Key operations:
$specs_dirgrep -o '^[0-9]\+'$((10#$number)) to avoid octal conversionSources: scripts/bash/create-new-feature.sh83-101
check_existing_branches()The function coordinates both detection methods:
This ensures the next feature number accounts for:
Sources: scripts/bash/create-new-feature.sh129-150 scripts/bash/create-new-feature.sh237-247
The scripts generate human-readable branch names from natural language descriptions using stop word filtering and intelligent word selection.
The generate_branch_name() function removes common English words that don't contribute semantic value:
Stop word list (bash):
Algorithm:
Examples:
| Input Description | Filtered Words | Generated Branch Name |
|---|---|---|
| "I want to add a user authentication system" | ["user", "authentication", "system"] | NNN-user-authentication-system |
| "Build API for OAuth2 integration" | ["build", "api", "oauth2", "integration"] | NNN-build-api-oauth2-integration |
| "The photo album organizing feature" | ["photo", "album", "organizing", "feature"] | NNN-photo-album-organizing |
Sources: scripts/bash/create-new-feature.sh180-226 scripts/powershell/create-new-feature.ps1155-198
GitHub enforces a 244-byte maximum for branch names. The scripts validate and truncate names that exceed this limit:
The truncation preserves the feature number prefix and removes trailing hyphens to maintain clean branch naming.
Sources: scripts/bash/create-new-feature.sh253-272 scripts/powershell/create-new-feature.ps1224-242
The scripts adapt their behavior based on Git availability, ensuring the workflow functions in both Git-managed and non-Git repositories.
When Git is available (HAS_GIT=true):
git fetch --all --prune to synchronize remote branch informationgit checkout -b $BRANCH_NAMESources: scripts/bash/create-new-feature.sh163-165 scripts/bash/create-new-feature.sh239-241 scripts/bash/create-new-feature.sh274-275
When Git is unavailable (HAS_GIT=false):
git fetch, git checkout)specs/ directory scanning for feature numberingSPECIFY_FEATURE environment variable to track current featureSPECIFY_FEATURE to locate the active feature directorySources: scripts/bash/create-new-feature.sh166-173 scripts/bash/create-new-feature.sh244-245 scripts/bash/create-new-feature.sh276-278
In non-Git environments, the system cannot infer the current feature from the Git branch name. The SPECIFY_FEATURE environment variable provides an explicit feature context.
| Command | Behavior with SPECIFY_FEATURE |
|---|---|
/speckit.specify | Uses variable to determine which specs/NNN-name/ directory to write spec.md |
/speckit.plan | Reads from specs/${SPECIFY_FEATURE}/spec.md, writes to specs/${SPECIFY_FEATURE}/plan.md |
/speckit.tasks | Reads from specs/${SPECIFY_FEATURE}/plan.md, writes to specs/${SPECIFY_FEATURE}/tasks.md |
/speckit.implement | Reads from specs/${SPECIFY_FEATURE}/tasks.md for implementation instructions |
The variable must be set in the AI agent's environment context before executing workflow commands. The agent context files (e.g., CLAUDE.md) document this requirement:
Must be set in the context of the agent you're working with prior to using
/speckit.planor follow-up commands.
Sources: scripts/bash/create-new-feature.sh288-296 scripts/powershell/create-new-feature.ps1265-281 README.md273-276
After determining the branch name and number, the scripts create the specification directory structure and initialize the spec file.
The spec file is populated from the template, which contains structured sections for:
This file becomes the input for the /speckit.specify command, which fills in the template sections based on the feature description.
Sources: scripts/bash/create-new-feature.sh177-178 scripts/bash/create-new-feature.sh280-285 scripts/powershell/create-new-feature.ps1152-153 scripts/powershell/create-new-feature.ps1254-263
The following table maps high-level concepts to concrete code entities in the scripts:
The feature creation scripts are automatically invoked by AI agents during the /speckit.specify command execution. The following sequence shows the integration:
Sources: scripts/bash/create-new-feature.sh1-298 scripts/powershell/create-new-feature.ps11-283
Refresh this wiki