Precedence
Environment variables sit between config files and command-line flags in precedence: a flag beats a variable, a variable beats a config file. So--sandbox on the command line wins over anything in your environment, and your environment wins over ~/.cortex/config.toml.
Locations
The home directory resolves in the order
CORTEX_CONFIG_DIR, then CORTEX_HOME, then ~/.cortex. See Data locations for what ends up in each directory.
Account
Interactive use should prefer
cortex login, which stores the session in the OS keyring. See Sign in to the CLI.
Where tools run
This PC and SSH require an already connected Code session. Cortex will not create one for you and will not quietly substitute Cortex Cloud. See Cloud, This PC, and SSH.
Model selection
Logging and diagnostics
CORTEX_DIAGNOSTICS_DIR is the opt-in switch for writing diagnostic files at all. CLI troubleshooting has the allowlist, the size caps and the retention window.
Set for you, not by you
These are populated by Cortex for the processes it spawns. A plugin can read them; you should not set them yourself.
Cortex also sets a small number of further variables for its own task routing. They are not a supported surface and setting them yourself is not meaningful.
Hooks do not get an environment of their own. A hook belongs to a plugin and runs inside the plugin runtime rather than as a command Cortex spawns for it, so there are no hook-specific variables to read. See Hooks.
Standard variables Cortex respects
Checking what is in effect
.cortex/config.toml: it overrides your own config file, though not your environment. See Configuration.