Repository navigation
Description
Description
The PowerShell script .specify/scripts/powershell/create-new-feature.ps1 only checks the specs/ directory on the current branch to determine the next feature number, but does not check existing branch names. This causes numbering conflicts when working with multiple feature branches that haven't been merged to main.
Expected Behavior
When running the script from main, it should:
- Check the
specs/directory for existing spec folders with pattern\d{3}-* - Also check
git branchoutput for existing branches with pattern\d{3}-* - Use the highest number found from either source
- Increment by 1 to determine the next feature number
Current Behavior
The script only checks step 1 (specs directory on current branch). If feature branches exist but haven't been merged to main, the script will reuse feature numbers, creating conflicts.
Reproduction Steps
- Initialize a new spec-kit project
- From
mainbranch, run the script to create feature 001:.\.specify\scripts\powershell\create-new-feature.ps1 -ShortName "first-feature"
- Creates branch
001-first-feature - Creates
specs/001-first-feature/directory
- Creates branch
- Push branch
001-first-featureto remote (do NOT merge to main) - Checkout
mainagain - Run the script to create feature 002:
.\.specify\scripts\powershell\create-new-feature.ps1 -ShortName "second-feature"
Expected: Creates branch 002-second-feature
Actual: Creates branch 001-second-feature (reuses 001)
Root Cause
Looking at lines 82-92 of create-new-feature.ps1:
$existingSpecs = Get-ChildItem -Path $specsDir -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '^\d{3}' } |
ForEach-Object {
if ($_.Name -match '^(\d{3})') {
[int]$matches[1]
}
} |
Sort-Object -Descending |
Select-Object -First 1The script only checks directories in $specsDir, not branch names via git branch.
Suggested Fix
Add branch checking logic before determining feature number:
# Get highest number from specs directory
$existingSpecs = Get-ChildItem -Path $specsDir -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '^\d{3}' } |
ForEach-Object {
if ($_.Name -match '^(\d{3})') {
[int]$matches[1]
}
} |
Sort-Object -Descending |
Select-Object -First 1
# Get highest number from branch names
$existingBranches = git branch -a |
ForEach-Object { $_.Trim() -replace '^\*?\s+', '' -replace '^remotes/origin/', '' } |
Where-Object { $_ -match '^\d{3}-' } |
ForEach-Object {
if ($_ -match '^(\d{3})') {
[int]$matches[1]
}
} |
Sort-Object -Descending |
Select-Object -First 1
# Use the highest number from either source
$highestExisting = [Math]::Max(
$(if ($existingSpecs) { $existingSpecs } else { 0 }),
$(if ($existingBranches) { $existingBranches } else { 0 })
)
$featureNumber = $highestExisting + 1Workaround
Until fixed, merge spec directories to main after creating each feature branch, so the next run can see the previous feature number in the specs directory.
Environment
- OS: Windows 11
- PowerShell Version: 7.5.4
- spec-kit: v0.0.20
Activity
fgalarraga commentedon Oct 21, 2025
✅ Fix Verified and Tested
I can confirm the proposed fix works correctly! Here are the test results:
Test Setup
create-new-feature.ps1(checking both specs/ directory AND git branches)fix/branch-numbering-detectionbranchmainbranchTest Results
Test 1 - Create First Feature:
001-first-featureTest 2 - Create Second Feature (The Critical Test):
002-second-feature(NOT001-second-feature)001-first-featurebranch on remote002as expectedFix Confirmation
The fix successfully:
Implementation Details
The fix adds branch detection logic that:
git branch -aremotes/origin/)^\d{3}-pattern[Math]::Max()to determine the starting pointCode Added
This fix resolves the issue completely and enables the proper workflow of creating multiple feature branches in parallel without requiring merges to main for correct numbering.
Fixes #975
maxmeyer3141 commentedon Nov 3, 2025
HI there, i think this won't completly fix the problem with the branch numbering when using coding agents because the speckit.specify command prompt template instructs the agent to call the script with the
Numberparameter which bypasses this solution.I suggest to update the git commands in https://github.com/github/spec-kit/blob/main/templates/commands/specify.md aswell.
Template (Source)
b. Find the highest feature number across all sources for the short-name:
- Remote branches:
git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-<short-name>$'- Local branches:
git branch | grep -E '^[* ]*[0-9]+-<short-name>$'- Specs directories: Check for directories matching `specs/[0-9]+-``
Template (fix)
b. Find the highest feature number across all sources for the short-name:
- Remote branches:
git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-$'- Local branches:
git branch | grep -E '^[* ]*[0-9]+-$'- Specs directories: Check for directories matching
specs/[0-9]+-Am i correct?
Fixes github#975
MisinformedDNA commentedon Apr 13, 2026
Yep, still an issue with Github Copilot.
Fixes github#975
Fixes github#975