Skip to content

feat: add system-wide config file support#963

Open
goodtune wants to merge 15 commits intomax-sixty:mainfrom
goodtune:claude/system-config-paths-CVQDx
Open

feat: add system-wide config file support#963
goodtune wants to merge 15 commits intomax-sixty:mainfrom
goodtune:claude/system-config-paths-CVQDx

Conversation

@goodtune
Copy link

@goodtune goodtune commented Feb 10, 2026

Load organization-wide defaults from a system config file before user config, allowing companies to distribute shared preferences via configuration management.

Config loading order (later overrides earlier):

  1. System config (organization defaults)
  2. User config (personal preferences)
  3. Environment variables

System config search locations:

  • $WORKTRUNK_SYSTEM_CONFIG_PATH (explicit override)
  • $XDG_CONFIG_DIRS directories (colon-separated)
  • Linux: /etc/xdg/worktrunk/config.toml
  • macOS: /Library/Application Support/worktrunk/config.toml
  • Windows: %PROGRAMDATA%\worktrunk\config.toml

Uses the same format as user config. Visible in wt config show.

Prior art in other highly correlated tools:

Cleaned up version of #960.

claude and others added 6 commits February 10, 2026 05:57
Load organization-wide defaults from a system config file before user
config, allowing companies to distribute shared preferences via
configuration management.

Config loading order (later overrides earlier):
1. System config (organization defaults)
2. User config (personal preferences)
3. Environment variables

System config search locations:
- $WORKTRUNK_SYSTEM_CONFIG_PATH (explicit override)
- $XDG_CONFIG_DIRS directories (colon-separated)
- Linux: /etc/xdg/worktrunk/config.toml
- macOS: /Library/Application Support/worktrunk/config.toml
- Windows: %PROGRAMDATA%\worktrunk\config.toml

Uses the same format as user config. Visible in `wt config show`.

https://claude.ai/code/session_01FeQXY5Hu8STpn5DZPvkxWC
Apply rustfmt formatting to fix CI lint failures:
- Split long `pub use` statement across multiple lines in `mod.rs`
- Condense multi-line path building to single line in `path.rs`
- Format long string assignment in `tests.rs`
- Improve method chaining formatting in integration tests
Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to test environment setup to prevent
platform-specific system config paths from appearing in snapshots.

Changes:
- Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_wt_cmd()` (TestRepo)
- Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_cli_command()` (standalone tests)
- Add filter for non-canonicalized macOS temp paths (`/var/folders/...`)

This ensures tests show consistent "Not found (optional)" for system config
across Linux, macOS, and Windows, preventing snapshot mismatches.
Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to `test_env_vars()` to ensure PTY-based
tests (like switch picker) have consistent system config behavior across platforms.

Without this, PTY tests would fall back to platform-specific system config
paths, causing test output to vary between Linux, macOS, and Windows.
@max-sixty
Copy link
Owner

thanks for the reformed PR

is this actually something that people want, though? I agree re the git comparison. But I don't think I've seen this much in other tools.

Could folks share some use cases where this would be helpful?

@goodtune
Copy link
Author

Here are some examples where it would be useful in our company.

We already deploy standardised configuration to all our developer machines to configure a proxy ANTHROPIC_BASE_URL, some OpenTelemetry config, etc in our /etc/claude-code/managed-config.json.

We have begun installing worktrunk on all their machines. We want to encourage them to use it to manage their agents worktrees, but also their interactive navigation. I have a couple of immediate use cases that I would like to standardise for them.

  1. most of our projects need to collect dependencies from either submodules or some other package system based off a file in the repository
    • rather than having to ask every developer to configure post-create trigger to run git submodule update --init or our-internal-tool-that-fetches-dependencies we can do this in one place.
  2. we have a hierarchy we are trying to encourage to help users get more familiar with worktrees
    • setting worktree-path = "../{{ branch | sanitize }}" in /etc/xdg/worktrunk/config.toml would allow us to not have to instruct every developer to do this themselves in ~/.config/worktrunk/config.toml

Unless we have something like this, we need to ask users to copy our preferred configuration into their home directory. They don't always follow instructions to the letter, so when they try to follow along with internal guides they get confused because they missed a step.

The philosophy I think is very sound, and is echoed through specifications such as the XDG base directory standard, and tools such as pip (/etc/pip.conf), uv (/etc/uv/uv.toml), npm (/etc/npmrc), Cargo (/.cargo/config.toml), Docker (/etc/docker/daemon.json), systemd (/etc/systemd/), SSH (/etc/ssh/ssh_config), Vim (/etc/vimrc), and Ansible (/etc/ansible/ansible.cfg). This pattern exists precisely because it solves real operational problems in managed environments.

The ability to set sensible defaults system-wide while still allowing users to override them in their personal config is well-established and makes tools manageable in enterprise/team settings. Users who don't need this feature wouldn't be affected, but for organizations deploying tools at scale, it's the difference between a smooth rollout and constant support tickets.

@max-sixty
Copy link
Owner

ok, that makes a lot of sense, thanks for the thoughtful response @goodtune

let me make some small adjustments to the code, if that's OK

@goodtune
Copy link
Author

Absolutely, please tweak as needed!

max-sixty and others added 3 commits February 10, 2026 18:20
Eliminate all test/non-test cfg annotations from path.rs. Both user
config and system config now use the same pattern: env var check first,
then platform default. Test isolation relies on env vars set by
TestRepo (WORKTRUNK_CONFIG_PATH, WORKTRUNK_SYSTEM_CONFIG_PATH), which
already covered integration tests.

Delete system_config_search_dirs() (fragile double-.parent() hack),
replace with default_system_config_path() that returns the env var
or first platform default.

Co-authored-by: Claude <noreply@anthropic.com>
…paths

Cover the system config resolution paths that were previously behind
#[cfg(not(test))] and never tested: XDG_CONFIG_DIRS lookup (found and
not-found cases), and platform default display path fallback.

Co-authored-by: Claude <noreply@anthropic.com>
Add tests for empty system config (hint message), invalid system config
(TOML parse error display), and unknown keys warning during config loading.
These exercise the render_system_config() and config loading paths.

Co-Authored-By: Claude <noreply@anthropic.com>
@goodtune
Copy link
Author

Looks good, thanks for taking the time to improve it.

max-sixty and others added 5 commits February 12, 2026 15:53
System config is a niche feature for organizations. Replace the dedicated
section, TOML example, and table row with a single sentence pointing to
`wt config show`. Env vars remain in the table for discoverability.

Co-Authored-By: Claude <noreply@anthropic.com>
Test from main needed its snapshot updated to include the new
SYSTEM CONFIG section in config show output.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty
Copy link
Owner

hi @goodtune — wdyt about those changes? lmk if you think we can make any final improvements. ty!

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.

3 participants