Skip to content

feat(scripts): add SPECIFY_INIT_DIR to target a member project from the repo root#2892

Draft
PascalThuet wants to merge 3 commits into
github:mainfrom
PascalThuet:feat/monorepo-init-dir
Draft

feat(scripts): add SPECIFY_INIT_DIR to target a member project from the repo root#2892
PascalThuet wants to merge 3 commits into
github:mainfrom
PascalThuet:feat/monorepo-init-dir

Conversation

@PascalThuet
Copy link
Copy Markdown
Contributor

@PascalThuet PascalThuet commented Jun 7, 2026

Summary

Adds SPECIFY_INIT_DIR, an environment variable that lets Spec Kit scripts target an explicit project root from another directory.

This covers monorepo use cases such as running from the repository root while targeting apps/web, without cd apps/web.

Behavior

  • When unset or empty, root detection behaves as before.
  • When set, SPECIFY_INIT_DIR must point to the project root: the directory containing .specify/.
  • Relative values resolve from the current working directory.
  • Invalid values fail fast and do not fall back to the current directory or Git root.
  • Feature selection remains separate and still resolves inside the selected project: SPECIFY_FEATURE_DIRECTORY > .specify/feature.json > branch lookup.

Changes

  • scripts/bash/common.sh and scripts/powershell/common.ps1 honor SPECIFY_INIT_DIR in root resolution.
  • Bash call sites that depend on root resolution now propagate failures instead of masking them.
  • create-new-feature.sh exits when root resolution fails.
  • agent-context update scripts honor SPECIFY_INIT_DIR, so context updates are written to the selected project.
  • Docs, changelog, and regression tests were updated.

Validation

  • uv run pytest tests/test_init_dir.py tests/test_timestamp_branches.py::TestGetFeaturePathsSinglePrefix tests/test_timestamp_branches.py::TestFeatureDirectoryResolution -v
    • 18 passed, 14 skipped
    • PowerShell cases were skipped locally because pwsh is not installed.
  • uvx ruff check tests/test_init_dir.py
    • passed

Out of Scope

  • No --project CLI flag.
  • No change to Python CLI project selection.
  • No change to how agent runtimes inherit environment variables.

Related to #2834.

PascalThuet and others added 3 commits June 7, 2026 16:30
…utside its directory

Adds a project-root override so a non-interactive / CI caller can run a Spec Kit
command against a member project (e.g. apps/web in a monorepo) from outside that
directory, without cd. SPECIFY_INIT_DIR names the project root — the directory
containing .specify/ — and is honored by get_repo_root in scripts/bash/common.sh,
mirrored in scripts/powershell/common.ps1.

Strict by design, per maintainer guidance on github#2834: when set, the path must exist
and contain .specify/, otherwise the resolver hard-errors and never falls back to
the current directory or the git toplevel (which would silently write to the wrong
project's specs/). Relative paths normalize against the current directory (with
CDPATH="" to avoid CDPATH-based misresolution); trailing slashes are tolerated; an
empty string is treated as unset.

Resolution stays two independent axes: SPECIFY_INIT_DIR selects the project, while
SPECIFY_FEATURE_DIRECTORY / .specify/feature.json / branch detection select the
feature within it (project-then-feature). The bash get_repo_root call sites that
feed real resolution are split into decl/assignment so the hard error propagates
instead of being masked by `local`.

Env var only; the --project CLI flag is deferred. Adds tests/test_init_dir.py
(positive + negative, bash and PowerShell) and documents the variable and the
two-axis precedence in docs/reference/core.md.

Refs: github#2834

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant