You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
regression(mcp): support file-based secrets in env config (restore shell-expansion behavior) #2334
This made it straightforward to integrate with secret managers that expose secrets as files on disk (e.g. sops-nix, pass, systemd credentials, Docker secrets). Since Crush no longer evaluates shell expressions in env values, this pattern is silently broken — the literal string $(cat ...) is passed as the token value instead. The ability to reference file-based secrets in MCP server configuration is now lost.
The regression has a subtle failure mode: MCP servers that validate tokens eagerly on startup (e.g. forgejo-mcp) crash immediately with a broken pipe during the initialize handshake, while servers with lazy validation (e.g. github-mcp-server) appear to initialize successfully but silently fail when tools are actually invoked.
Proposed Feature
Introduce a env_files key (or similar) in the MCP server config to explicitly map environment variable names to file paths, which Crush reads at process startup:
Crush would read the file contents and set the environment variable before spawning the process — no shell required, no security regression.
Why not use $(echo $VAR)?
The currently documented workaround ($(echo $HOST_ENV_VAR)) does not help here: secrets managed by sops-nix, systemd, or similar tools are decrypted at runtime and are only available as files on disk — they are never present as host environment variables in the Crush process.
Alternatives Considered
Wrapper shell scripts per MCP server — functional but requires boilerplate outside the config and complicates NixOS/Home Manager module integration
Storing secrets as host env vars — not possible with file-based secret managers
changed the title [-]feat(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]WIP: feat(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+]on Mar 24, 2026
changed the title [-]WIP: feat(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]fix: (mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+]on Mar 24, 2026
changed the title [-]fix: (mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]fix(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+]on Mar 24, 2026
changed the title [-]fix(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]regression(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+]on Mar 24, 2026
I am finally able to actually use crush again after building a workaround.
The following workaround wraps every command with its args and env files as a shell script using Nix Home-Manager.
It expects charmbracelet/nur#60 to be merged and yants to be set per overlay to pkgs.lib.yants.
A clean solution for this would be to adopt the same variable substitution approach that opencode implements. Opencode supports a {file:/path/to/secret} syntax directly in config values, which allows file-based secrets to be injected into MCP server environment variables without shell expansion:
This would cover secret managers like sops-nix, systemd credentials, and Docker secrets, where secrets are only available as files at runtime and never as host environment variables. The opencode implementation could serve as a reference.
running shell commands that are stored in config files isn't hygienic. IMO, it would be better if there were a way to just use procsub. that's how i got here.
another option is to integrate with the OS secrets store.
the standard .env support would be great as well. just please do not store current login info in ~/.config like opencode or in ~/.local/share like other software (podman).
another option is to integrate with the OS secrets store.
the standard .env support would be great as well. just please do not store current login info in ~/.config like opencode or in ~/.local/share like other software (podman).
opencode does support secrets files and ~/.local/share and ~/.config are actually standards defined in the free desktop specifications
it's true that they're defined in the XDG desktop standard, but they're only as secure as your user, file system or disk device.
for Windows and MacOS, the desktop-environment integration that most software uses causes them to store secrets in the OS keyring, where they're usually only available to specific applications.
googling for site:https://opencode.ai/docs encrypt shows no results. plain-text API tokens are a no-go for me. anomalyco/opencode#4318 mentions a need to address this or support OS keyring.
these tools manage orchestration of agents which need access to APIs or at least your computer's own resources. The tasks are often delegated under the OS identity of the user themselves. the option for encrypted credentials should not be an afterthought. it should be considered a primary requirement, esp for these agent harnesses.
ideally, the CLI would support .env files, but also a CLI method using some -x LLM_SERVICE_TOKEN=<(cmd proc sub) which doesn't set the env var, but instead opens the file descriptor, then releases it.
nodeJS is used widely bc it deploys to many platforms easily, but package authors often don't know the first thing about system integation. this results in poor CLI choices, where tools typically don't examine file paths or file descriptors to determine whether <(cmd proc sub) was used.
on the other hand, Go emerged as a systems programming lang, so its culture & extension authors tend to handle CLI args properly.
I don't bother with NodeJS CLI tools (i also use NixOS btw... i haven't quite crossed off sops.nix though)
Alright, so we have a PR for this one: #2782. We're using the embedded Bash interpreter now, which is way, better, so you can do things like "$(cat /run/secrets/codeberg_token)" and "$(vault kv get my/little/secret)".
Activity
tunnckoCore commentedon Mar 6, 2026
Or just support
.envor.env.localor.env.charm?This does actually seem to work
(set -a; source .env.crush; crush -y)- yes including the parens, and ye bash/zsh.malikwirin commentedon Mar 6, 2026
I dont unterstand. Where would I
(set -a; source .env.crush; crush -y)?[-]feat(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]WIP: feat(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+][-]WIP: feat(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]fix: (mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+][-]fix: (mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]fix(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+][-]fix(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/-][+]regression(mcp): support file-based secrets in env config (restore shell-expansion behavior)[/+]malikwirin commentedon Apr 9, 2026
I am finally able to actually use crush again after building a workaround.
The following workaround wraps every command with its args and env files as a shell script using Nix Home-Manager.
It expects charmbracelet/nur#60 to be merged and yants to be set per overlay to
pkgs.lib.yants.This is a workaround and I still believe crush should be compatible with secret managers that only provide paths at configure time
malikwirin commentedon Apr 9, 2026
A clean solution for this would be to adopt the same variable substitution approach that opencode implements. Opencode supports a
{file:/path/to/secret}syntax directly in config values, which allows file-based secrets to be injected into MCP server environment variables without shell expansion:This would cover secret managers like sops-nix, systemd credentials, and Docker secrets, where secrets are only available as files at runtime and never as host environment variables. The opencode implementation could serve as a reference.
dcunited001 commentedon May 1, 2026
@malikwirin you can still use sops with environment variables, though it's not the intended usage for long running processes.
https://github.com/getsops/sops#passing-secrets-to-other-processes
running shell commands that are stored in config files isn't hygienic. IMO, it would be better if there were a way to just use procsub. that's how i got here.
dcunited001 commentedon May 1, 2026
avoiding nodejs is how i got to charm lol
another option is to integrate with the OS secrets store.
the standard
.envsupport would be great as well. just please do not store current login info in~/.configlike opencode or in~/.local/sharelike other software (podman).malikwirin commentedon May 1, 2026
opencode does support secrets files and
~/.local/shareand~/.configare actually standards defined in the free desktop specificationsdcunited001 commentedon May 1, 2026
it's true that they're defined in the XDG desktop standard, but they're only as secure as your user, file system or disk device.
for Windows and MacOS, the desktop-environment integration that most software uses causes them to store secrets in the OS keyring, where they're usually only available to specific applications.
googling for
site:https://opencode.ai/docs encryptshows no results. plain-text API tokens are a no-go for me. anomalyco/opencode#4318 mentions a need to address this or support OS keyring.these tools manage orchestration of agents which need access to APIs or at least your computer's own resources. The tasks are often delegated under the OS identity of the user themselves. the option for encrypted credentials should not be an afterthought. it should be considered a primary requirement, esp for these agent harnesses.
ideally, the CLI would support
.envfiles, but also a CLI method using some-x LLM_SERVICE_TOKEN=<(cmd proc sub)which doesn't set the env var, but instead opens the file descriptor, then releases it.nodeJS is used widely bc it deploys to many platforms easily, but package authors often don't know the first thing about system integation. this results in poor CLI choices, where tools typically don't examine file paths or file descriptors to determine whether
<(cmd proc sub)was used.on the other hand, Go emerged as a systems programming lang, so its culture & extension authors tend to handle CLI args properly.
I don't bother with NodeJS CLI tools (i also use NixOS btw... i haven't quite crossed off sops.nix though)
meowgorithm commentedon May 2, 2026
Hey! Two issues here and both are good ones:
We hear you on both. Looking into the regression first.
meowgorithm commentedon May 2, 2026
Alright, so we have a PR for this one: #2782. We're using the embedded Bash interpreter now, which is way, better, so you can do things like
"$(cat /run/secrets/codeberg_token)"and"$(vault kv get my/little/secret)".meowgorithm commentedon May 10, 2026
Thanks for your patience, everyone. This one's merged and will be available in the next release, likely Monday.
Also, it's using a the embedded bash interpreter for shell expansion now, so it should generally be way better than before.
dcunited001 commentedon May 12, 2026
Thanks for looking into this. I'm just a bit paranoid about things.