Skip to content

feat(config): discover devbox.json in a .config subdirectory#2889

Open
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-x367mg
Open

feat(config): discover devbox.json in a .config subdirectory#2889
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-x367mg

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Addresses the auto-discovery half of #2792.

That issue asks to make the location of devbox.json more flexible so users can keep the project root tidy — either via an env var and/or by looking for the config in an alternative place such as ./.config/devbox.json. The env-var half is already supported (DEVBOX_CONFIG, merged in #2838). This PR adds the remaining piece: auto-discovery of .config/devbox.json.

Change

searchDir (in internal/devconfig/config.go) already had a try []string list of candidate config filenames that previously contained only devbox.json. This PR adds .config/devbox.json as a second candidate:

try := []string{
    configfile.DefaultName,
    filepath.Join(".config", configfile.DefaultName),
}

Behavior:

  • A top-level devbox.json always takes precedence over .config/devbox.json (it's tried first).
  • Because searchDir is used by both Open and Find, this works when running from the project directory and when walking up parent directories.
  • When the config is found at .config/devbox.json, that directory (.config) becomes the project directory, so devbox's generated files (.devbox/, devbox.lock) live alongside it inside .config — keeping the repository root clean, which is the goal of the issue.

Tests

Added TestOpenDotConfig in internal/devconfig/config_test.go:

  • FindsConfigInDotConfigDir — config in .config/devbox.json is discovered.
  • TopLevelConfigTakesPrecedence — a root devbox.json wins when both exist.
  • FindWalksUpToParentDotConfigFind from a child dir locates a parent's .config/devbox.json.
go test ./internal/devconfig/ -run 'TestOpen|TestFind'
go build ./...
go vet ./internal/devconfig/

All pass. (Two unrelated pre-existing tests — TestFindError/Permissions and TestFindError/ExactFilePermissions — fail in a root environment because chmod 0o000 doesn't restrict root; they fail identically on main and are untouched by this change.)

Notes / scope

This intentionally focuses on the core discovery path used by Open/Find, which is what the CLI commands rely on. If maintainers would prefer the project root to remain the parent of .config (keeping .devbox at the top level instead of inside .config), that's a larger change to how the project directory is derived from the config path and can be a follow-up — happy to adjust based on preference.

cc @eknowles (issue reporter)

🤖 Generated with Claude Code

https://claude.ai/code/session_01L4HytKeYVy9zYHadK7TfWN


Generated by Claude Code

Look for the project config in `.config/devbox.json` in addition to a
top-level `devbox.json`, so users can keep the project root tidy by
moving devbox's files into `.config`. A top-level `devbox.json` always
takes precedence when both exist.

This complements DEVBOX_CONFIG (already supported) and addresses the
auto-discovery half of #2792.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4HytKeYVy9zYHadK7TfWN
Copilot AI review requested due to automatic review settings June 23, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for auto-discovering devbox.json when it lives under a project’s .config/ subdirectory, addressing the remaining “auto-discovery” portion of issue #2792 (with DEVBOX_CONFIG already handled in #2838).

Changes:

  • Extend internal/devconfig.searchDir to try both devbox.json and .config/devbox.json, with top-level devbox.json taking precedence.
  • Add unit tests ensuring .config/devbox.json discovery works for both Open and parent-directory Find, and that precedence rules are enforced.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/devconfig/config.go Adds .config/devbox.json as a second candidate path in config discovery, preserving precedence of top-level devbox.json.
internal/devconfig/config_test.go Adds TestOpenDotConfig to cover discovery in .config, precedence vs top-level config, and parent-walking behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants