11. XDG as default config location; CORTEX_PATH becomes a legacy fallback
Date: 2026-06-06
Status
Accepted. Supersedes the implicit decision in
0007: TOML configuration format, which
assumed CORTEX_PATH would point at the config.
Context
The cerebro command-line tool and TUI load config.toml via this priority:
CORTEX_PATH env var > --config CLI flag > XDG config dir > ./config.toml
That ordering made CORTEX_PATH the de-facto requirement: a user who didn’t
set it would either find an XDG config, if one happened to exist, or fail.
The README and getting-started docs reflected this, telling users to place
config.toml in their cortex, meaning the directory pointed to by
CORTEX_PATH.
In practice, this meant the user had to:
- Decide on a cortex location.
- Set
CORTEX_PATHin their shell startup file. - Restart the shell.
- Only then would the binary find the config.
If the user missed a step, the binary either picked up an unintended file,
the ./config.toml fallback, or failed. The MCP server kept working because
it falls back to ~/Projects/cortex. The cerebro and cerebro-tui
binaries didn’t. They sat silently on an absent config.
The principle of least surprise: a freshly installed tool shouldn’t require
environment variables to do its job. The XDG base-directory spec already
defines a sensible default: $XDG_CONFIG_HOME/cerebro/config.toml, falling
back to $HOME/.config/cerebro/config.toml when XDG_CONFIG_HOME is unset.
The same path works on every platform, which avoids the surprise of
dirs::config_dir() returning ~/Library/Application Support on macOS for
users coming from Linux. CORTEX_PATH conflated two unrelated questions,
where the config lives and where the data lives, and the conflation was the
source of the confusion.
Decision
The command-line tool cerebro and the TUI cerebro-tui use this new resolution order:
--config <path>flag: explicit override, always wins.- XDG config dir, the default:
$XDG_CONFIG_HOME/cerebro/config.toml, or$HOME/.config/cerebro/config.tomlifXDG_CONFIG_HOMEis unset. Users who do nothing get this. Same path on every platform. CORTEX_PATHenv var, a legacy fallback. IfCORTEX_PATHalready points at a directory containingconfig.toml, that still works../config.tomlin the current working directory, a last-resort fallback, unchanged.
The decision leaves cerebro-mcp unchanged: it still uses CORTEX_PATH to
locate the cortex data directory, where generated content/ lives, and
falls back to ~/Projects/cortex. This is a separate concern from config and
was never the source of confusion.
crates/cerebro/src/main.rs::resolve_config_path and
crates/cerebro-tui/src/bin/cerebro-tui.rs::resolve_config_path both
implement the new priority. Integration tests in
crates/cerebro/tests/integration.rs now pass --config explicitly so they
don’t pick up a developer’s real XDG config from their machine.
Consequences
Pros
- New users: install, run
cerebro build, it reads the XDG default. No env vars required. - Existing users with
CORTEX_PATHset: still work via fallback #3. - Power users and scripted runs:
--configalways wins, no surprises. CORTEX_PATH’s documentation now matches reality: a pointer to the MCP server’s data directory, not a config prerequisite.
Cons
- A user with both an XDG config and
CORTEX_PATHset to a different cortex silently gets the XDG config. This is the desired behavior, but it meansCORTEX_PATHno longer wins. Release notes should call it out. - Tests now depend on an explicit
--config. Future test authors must remember to pass it. This change updated the existing integration tests. - This change reworked the example
config.tomlin the README. External tutorials or screenshots showing the old “put it in your cortex” pattern are now stale.
Migration
For users currently relying on CORTEX_PATH to point at their config:
# Old: config was at $CORTEX_PATH/config.toml
# New: move it to the XDG location
mv "$CORTEX_PATH/config.toml" ~/.config/cerebro/config.toml
# CORTEX_PATH can stay set (MCP still uses it) or be unset if you accept the default
For users with no config at all, run cerebro build once after install and
follow the “config not found” error message, which points at the XDG path.
Notes
- The
dirscrate handleshome_dir(). The code readsXDG_CONFIG_HOMEitself, falling back to$HOME/.config, so the resolution is identical on every platform. Cerebro deliberately doesn’t usedirs::config_dir(), which on macOS returns~/Library/Application Supportand would surprise users coming from Linux. - The integration tests previously relied on
CORTEX_PATHfor config. They now pass--configexplicitly. Unit tests inmain.rs::testsnever depended on a real XDG config, so they needed no changes. - This decision deliberately leaves the MCP server’s use of
CORTEX_PATHalone: it locates the data directory, not the config.