Skip to content

[Bug]: update-agent-context.sh crashes ("HAS_GIT: unbound variable") when SPECIFY_FEATURE is unset, despite feature.json resolving the feature #3076

@montfort

Description

@montfort

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

  1. specify init a project (CLI 0.11.3, --script sh).
  2. Run /speckit-specify → creates the feature and writes .specify/feature.json.
  3. 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

  1. Initialize HAS_GIT with a default (or export it from get_feature_paths()) so set -u can't abort on it.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions