Bug Description
The core scripts/bash/update-agent-context.sh (the variant that sources scripts/bash/common.sh) crashes when run without SPECIFY_FEATURE in the environment — even though .specify/feature.json already identifies the active feature and get_feature_paths() resolves FEATURE_DIR from it correctly.
Since 0.11, common.sh::get_current_branch() returns an empty string when SPECIFY_FEATURE is unset (it no longer derives from the git branch). get_feature_paths() emits CURRENT_BRANCH="" and does not export HAS_GIT. Then in update-agent-context.sh::validate_environment():
- it treats empty
CURRENT_BRANCH as fatal → ERROR: Unable to determine current feature (a false positive — the feature was resolved via feature.json);
- the next line references
HAS_GIT, which was never assigned → under set -u this aborts with HAS_GIT: unbound variable.
Net effect: the after_plan hook (and any manual run) fails and the agent context file (e.g. CLAUDE.md) is not updated.
Steps to Reproduce
specify init a project (CLI 0.11.3, --script sh).
- Run
/speckit-specify → creates the feature and writes .specify/feature.json.
- In a fresh shell without
SPECIFY_FEATURE exported: bash .specify/scripts/bash/update-agent-context.sh claude.
Expected Behavior
Since .specify/feature.json already identifies the active feature (as check-prerequisites.sh and get_feature_paths() use), the script should update the agent context without requiring SPECIFY_FEATURE or a git feature branch.
Actual Behavior
ERROR: Unable to determine current feature
.../update-agent-context.sh: line 147: HAS_GIT: unbound variable
Workaround that confirms the cause: SPECIFY_FEATURE=<feature> bash .../update-agent-context.sh claude → exit 0, succeeds.
Suggested Fix
- Initialize
HAS_GIT with a default (or export it from get_feature_paths()) so set -u can't abort on it.
- Don't treat empty
CURRENT_BRANCH as fatal when FEATURE_DIR/feature.json already resolved the feature — gate on feature resolution, not branch (consistent with the 0.11 feature/branch decoupling and with check-prerequisites.sh).
Related
Complements #3067 / PR #3069 (which fix the self-contained extension variant's mtime plan-selection) and the #2887 family (inconsistent feature.json bypass across scripts). This is the core variant (the one that sources common.sh), where the same mismatch produces a hard crash rather than a wrong-plan selection.
Specify CLI Version
0.11.3
AI Agent
Claude Code
Bug Description
The core
scripts/bash/update-agent-context.sh(the variant thatsourcesscripts/bash/common.sh) crashes when run withoutSPECIFY_FEATUREin the environment — even though.specify/feature.jsonalready identifies the active feature andget_feature_paths()resolvesFEATURE_DIRfrom it correctly.Since 0.11,
common.sh::get_current_branch()returns an empty string whenSPECIFY_FEATUREis unset (it no longer derives from the git branch).get_feature_paths()emitsCURRENT_BRANCH=""and does not exportHAS_GIT. Then inupdate-agent-context.sh::validate_environment():CURRENT_BRANCHas fatal →ERROR: Unable to determine current feature(a false positive — the feature was resolved viafeature.json);HAS_GIT, which was never assigned → underset -uthis aborts withHAS_GIT: unbound variable.Net effect: the
after_planhook (and any manual run) fails and the agent context file (e.g.CLAUDE.md) is not updated.Steps to Reproduce
specify inita project (CLI 0.11.3,--script sh)./speckit-specify→ creates the feature and writes.specify/feature.json.SPECIFY_FEATUREexported:bash .specify/scripts/bash/update-agent-context.sh claude.Expected Behavior
Since
.specify/feature.jsonalready identifies the active feature (ascheck-prerequisites.shandget_feature_paths()use), the script should update the agent context without requiringSPECIFY_FEATUREor a git feature branch.Actual Behavior
Workaround that confirms the cause:
SPECIFY_FEATURE=<feature> bash .../update-agent-context.sh claude→ exit 0, succeeds.Suggested Fix
HAS_GITwith a default (or export it fromget_feature_paths()) soset -ucan't abort on it.CURRENT_BRANCHas fatal whenFEATURE_DIR/feature.jsonalready resolved the feature — gate on feature resolution, not branch (consistent with the 0.11 feature/branch decoupling and withcheck-prerequisites.sh).Related
Complements #3067 / PR #3069 (which fix the self-contained extension variant's mtime plan-selection) and the #2887 family (inconsistent
feature.jsonbypass across scripts). This is the core variant (the one thatsourcescommon.sh), where the same mismatch produces a hard crash rather than a wrong-plan selection.Specify CLI Version
0.11.3
AI Agent
Claude Code