Skip to content

Inability to fully hide XDG environment variables in config files #18169

Closed

Description

@ErrorPower2001

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:

  1. Even when using the workaround of "assigning an empty string first, then calling hide-env", the variables cannot be fully removed during the execution of env.nu or config.nu.
  2. In an interactive shell, running the assignment and hide-env in 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

  1. Set the environment variable XDG_CONFIG_HOME before launching Nushell.
  2. In env.nu or config.nu, add the following:
$env.XDG_CONFIG_HOME = ""
hide-env XDG_CONFIG_HOME
  1. After launch, check $env. XDG_CONFIG_HOME still exists

Run command in pwsh:

> $env:XDG_CONFIG_HOME = "$HOME\.config\" ; $env:XDG_DATA_HOME = "$HOME\.local\share\" ; $env:XDG_CACHE_HOME = "$HOME\.cache\" ; nu

Content 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_HOME

Run 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

  1. added
    status:needs-triage
    on May 6, 2026
  2. fdncred commented on May 6, 2026

    @fdncred
    Contributor

    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.

  3. ErrorPower2001 commented on May 6, 2026

    @ErrorPower2001
    Author

    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.

    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:

    1. Step-by-step execution (Success): If I run these as two separate commands, the variable is fully removed.
    $env.XDG_CONFIG_HOME = ""  # Press Enter
    hide-env XDG_CONFIG_HOME   # Press Enter -> Variable is gone
    1. Single-line with semicolon (Failure): If I combine them with a semicolon, the deletion fails even in the same session.
    $env.XDG_CONFIG_HOME = ""; hide-env XDG_CONFIG_HOME  # Variable persists

    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.

  4. ErrorPower2001 commented on May 6, 2026

    @ErrorPower2001
    Author

    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 like XDG_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.

  5. fdncred commented on May 6, 2026

    @fdncred
    Contributor
    1. Step-by-step execution (Success): If I run these as two separate commands, the variable is fully removed.

    $env.XDG_CONFIG_HOME = "" # Press Enter
    hide-env XDG_CONFIG_HOME # Press Enter -> Variable is gone
    2. Single-line with semicolon (Failure): If I combine them with a semicolon, the deletion fails even in the same session.

    $env.XDG_CONFIG_HOME = ""; hide-env XDG_CONFIG_HOME # Variable persists
    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.

    Is this behavior only seen with XDG_* env vars or any env var?

  6. fdncred commented on May 6, 2026

    @fdncred
    Contributor

    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?

    Look at the config file with config nu --doc | nu-highlight | less -FRXS and 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.

  7. ErrorPower2001 commented on May 6, 2026

    @ErrorPower2001
    Author

    Is this behavior only seen with XDG_* env vars or any env var?

    All of them, including environment variables defined before Nushell starts and those defined within the interactive shell.

    Step: before Nushell starts

    pwsh> $env:AAAA = AAAA ; nu.exe
    nu> $env.AAAA = "" ; hide-env AAAA

    Step: within interactive shell

    > $env.AAAA = "AAAA"
    > $env.AAAA = "" ; hide-env AAAA

    Is this a scoping issue?

  8. fdncred commented on May 6, 2026

    @fdncred
    Contributor

    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 hide work vs hide-env?

  9. ErrorPower2001 commented on May 6, 2026

    @ErrorPower2001
    Author

    Oh, setting it to "" is indeed not necessary. I just happened to discover this behavior while trying to remove XDG_* variables in env.nu. I thought it was a BUG, so I submitted the feedback.

    hide seems to work correctly even on the same line. Here is the test:

    ~>  def greet [] { echo "Hello!" }
    ~>  greet
    Hello!
    ~>  hide greet # it works
    ...
    ~>  def greet [] { echo "Hello!" } ; hide greet
    ~>  greet
    Error: nu::shell::external_command
    
      × External command failed
       ╭─[entry #5:1:2]
     1 │  greet
       ·  ──┬──
       ·    ╰── Command `greet` not found
       ╰────
      help: Did you mean `get`?
  10. fdncred commented on May 6, 2026

    @fdncred
    Contributor

    Also, can you try setting $env.AAAA = null instead of an empty string. This works for me without any code changes.

    ❯ $env.AAAA = "AAAA"
    ❯ $env.AAAA = null ; hide AAAA
    ❯ $env.AAAA

    Ugh. That's because hide "just works". hide-env doesn't work very well. Wondering if we should just remove hide-env entirely.

    Update: After talking with @Bahex and testing a bit more hide doesn't "just work". The reason it appears to be "working" above is because AAAA is being set to null. However, it's still there and not removed.

  11. Bahex commented on May 6, 2026

    @Bahex
    Member

    Minimal example demonstrating the issue:

    ">"; $env.FOO = "before"
    ">"; $env.FOO = "after"; hide-env FOO
    ">"; $env.FOO
    # => before
  12. fdncred commented on May 6, 2026

    @fdncred
    Contributor

    @ErrorPower2001 can you try out #18170 to see if it fixes your problem?

  13. ErrorPower2001 commented on May 7, 2026

    @ErrorPower2001
    Author

    Tested #18170 and confirmed it fixes the problem. Everything is working as expected now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions