Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. Decide on a cortex location.
  2. Set CORTEX_PATH in their shell startup file.
  3. Restart the shell.
  4. 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:

  1. --config <path> flag: explicit override, always wins.
  2. XDG config dir, the default: $XDG_CONFIG_HOME/cerebro/config.toml, or $HOME/.config/cerebro/config.toml if XDG_CONFIG_HOME is unset. Users who do nothing get this. Same path on every platform.
  3. CORTEX_PATH env var, a legacy fallback. If CORTEX_PATH already points at a directory containing config.toml, that still works.
  4. ./config.toml in 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_PATH set: still work via fallback #3.
  • Power users and scripted runs: --config always 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_PATH set to a different cortex silently gets the XDG config. This is the desired behavior, but it means CORTEX_PATH no 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.toml in 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 dirs crate handles home_dir(). The code reads XDG_CONFIG_HOME itself, falling back to $HOME/.config, so the resolution is identical on every platform. Cerebro deliberately doesn’t use dirs::config_dir(), which on macOS returns ~/Library/Application Support and would surprise users coming from Linux.
  • The integration tests previously relied on CORTEX_PATH for config. They now pass --config explicitly. Unit tests in main.rs::tests never depended on a real XDG config, so they needed no changes.
  • This decision deliberately leaves the MCP server’s use of CORTEX_PATH alone: it locates the data directory, not the config.