Repository navigation
Description
Bug report form
- I have done a basic search of the issue tracker to find any existing issues that are similar.
- I have checked that my version is at least the latest stable release available via my installation method.
Describe the bug
I am trying to redirect Nushell's default config, cache, and data directories by setting XDG_CONFIG_HOME, XDG_CACHE_HOME, and XDG_DATA_HOME. However, I do not want these variables to be inherited by child processes started from Nushell.
I've discovered that these three variables seem to be "locked" during the startup phase:
- Even when using the workaround of "assigning an empty string first, then calling
hide-env", the variables cannot be fully removed during the execution ofenv.nuorconfig.nu. - In an interactive shell, running the assignment and
hide-envin a single line separated by a semicolon (e.g.,$env.XDG_CONFIG_HOME = ""; hide-env XDG_CONFIG_HOME) also fails. The deletion only works if the commands are executed as two separate inputs.
This prevents a clean directory redirection via startup scripts without leaking environment variables to other applications.
How to reproduce
- Set the environment variable
XDG_CONFIG_HOMEbefore launching Nushell. - In
env.nuorconfig.nu, add the following:
$env.XDG_CONFIG_HOME = ""
hide-env XDG_CONFIG_HOME- After launch, check
$env.XDG_CONFIG_HOMEstill exists
Run command in pwsh:
> $env:XDG_CONFIG_HOME = "$HOME\.config\" ; $env:XDG_DATA_HOME = "$HOME\.local\share\" ; $env:XDG_CACHE_HOME = "$HOME\.cache\" ; nuContent of ~\.config\nushell\env.nu
$env.XDG_CONFIG_HOME = ""
hide-env XDG_CONFIG_HOME
$env.XDG_CACHE_HOME = ""
hide-env XDG_CACHE_HOME
$env.XDG_DATA_HOME = ""
hide-env XDG_DATA_HOMERun command in the nu session:
> $env | table | find "XDG"
╭───┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 0 │ │ XDG_CACHE_HOME │ C:\Users\Username\.cache\ │
│ │ │ │
│ 1 │ │ XDG_CONFIG_HOME │ C:\Users\Username\.config\ │
│ │ │ │
│ 2 │ │ XDG_DATA_HOME │ C:\Users\Username\.local\share\ │
│ │ │ │
╰───┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯At the same time, other environment variables set in the same manner can be successfully removed using hide-env within ~\.config\nushell\env.nu.
Expected behavior
It should be possible to fully remove these initialization-related environment variables using hide-env within configuration files.
Alternatively, a mechanism for directory redirection that doesn't rely on global environment variables would be appreciated.
Configuration
| key | value |
|---|---|
| version | 0.110.0 |
| major | 0 |
| minor | 110 |
| patch | 0 |
| branch | |
| commit_hash | d40e191 |
| build_os | windows-x86_64 |
| build_target | x86_64-pc-windows-msvc |
| rust_version | rustc 1.90.0 (1159e78c4 2025-09-14) |
| rust_channel | 1.90.0-x86_64-pc-windows-msvc |
| cargo_version | cargo 1.90.0 (840b83a10 2025-07-30) |
| build_time | 2026-01-18 02:12:43 +00:00 |
| build_rust_channel | release |
| allocator | standard |
| features | default, mcp, network, plugin, rustls-tls, sqlite, trash-support |
| installed_plugins | |
| experimental_options | example=false, reorder-cell-paths=true, pipefail=false, enforce-runtime-annotations=false |
Activity
fdncred commentedon May 6, 2026
The documentation may not bel clear enough https://www.nushell.sh/book/configuration.html#additional-startup-configuration. But XDG_CONFIG_HOME has to be set before nushell is run. If you want nushell to use or disuse these environment variable it has to be set BEFORE nushell ever runs. So, clearing them in env.nu won't help to get rid of them. They'd have to be cleared/removed before nushell starts.
ErrorPower2001 commentedon May 6, 2026
Thanks for your reply. I understand that these variables must be set before Nushell runs for redirection to work, and that is exactly what I am doing.
However, I also found this consistency BUG in how environment variables are handled:
In an interactive shell (after the prompt is ready), I observed the following inconsistent behavior:
If these variables can be successfully removed step-by-step in an interactive shell, it implies that the engine no longer locks them. So, why does it fail when executed in a single block (with a semicolon)? This inconsistency looks like a BUG to me.
ErrorPower2001 commentedon May 6, 2026
Additionally, I would like to ask: Does Nushell currently provide independent configuration options (separate from environment variables) to specify the config, data, or cache directories?
For instance, are there command-line arguments (like
--config-dir <path>) or internal settings that allow a user to redirect the entire Nushell configuration suite to a specific directory (e.g.,%UserProfile%\.config\nushell) without relying on global environment variables likeXDG_CONFIG_HOME?As I mentioned earlier, my primary goal is to have Nushell run within a custom path while ensuring that other unrelated programs (e.g., tools in child processes) are not affected by the presence of these XDG variables. Having native path redirection options would be far more robust and elegant than manually attempting to clear environment variables after startup.
fdncred commentedon May 6, 2026
Is this behavior only seen with XDG_* env vars or any env var?
fdncred commentedon May 6, 2026
Look at the config file with
config nu --doc | nu-highlight | less -FRXSand you'll see the latest config file options. I believe we added the ability to change the config history file path recently.If you don't see changes in there I think it's left to XDG.
ErrorPower2001 commentedon May 6, 2026
All of them, including environment variables defined before Nushell starts and those defined within the interactive shell.
Step: before Nushell starts
Step: within interactive shell
Is this a scoping issue?
fdncred commentedon May 6, 2026
I'll look into it but i'm not sure why you need to set the env var to "". You should be able to just hide it. Also, does
hidework vshide-env?ErrorPower2001 commentedon May 6, 2026
Oh, setting it to
""is indeed not necessary. I just happened to discover this behavior while trying to removeXDG_*variables inenv.nu. I thought it was a BUG, so I submitted the feedback.hideseems to work correctly even on the same line. Here is the test:fdncred commentedon May 6, 2026
Also, can you try setting
$env.AAAA = nullinstead of an empty string. This works for me without any code changes.Ugh. That's because
hide"just works".hide-envdoesn't work very well. Wondering if we should just removehide-enventirely.Update: After talking with @Bahex and testing a bit more
hidedoesn't "just work". The reason it appears to be "working" above is becauseAAAAis being set tonull. However, it's still there and not removed.Bahex commentedon May 6, 2026
Minimal example demonstrating the issue:
fdncred commentedon May 6, 2026
@ErrorPower2001 can you try out #18170 to see if it fixes your problem?
ErrorPower2001 commentedon May 7, 2026
Tested #18170 and confirmed it fixes the problem. Everything is working as expected now. Thank you!
fix hide-env, refactor: rename remove_env_var to hide_env_var for cla…