Skip to content

direnv integration

direnv loads and unloads environment variables according to your current directory. murk supports direnv, so your secrets load when you cd into a project. You need no manual export and no wrapper script.

Secrets loading automatically on cd via direnv

Terminal window
murk env
direnv allow

murk env writes a .envrc that runs murk export for your vault. direnv allow tells direnv that it can run that .envrc. direnv needs this opt-in for each directory, so that a repository you do not trust cannot set environment variables when you cd into it.

After that, direnv exports every secret you can read when you enter the project. That includes shared secrets, group secrets and your own me overrides. direnv unsets them when you leave.

direnv reloads when .envrc changes, not when .murk changes. After git pull or murk rotate, run direnv reload. To make direnv watch the vault, add this line above the eval line in .envrc:

Terminal window
watch_file .murk

Before the first load on a machine, murk can stop with “not trusted on this machine yet”. Review the vault and run murk trust once, as described in working in teams. Then run direnv allow as usual.

murk does not export a variable that changes how programs, your shell or murk itself run, such as PATH, LD_PRELOAD, GIT_*, HTTPS_PROXY and MURK_*. Otherwise the .envrc would let the last writer of the vault make that choice. So murk export stops and names the key. See Variable names a vault may not set for the list and for --allow-reserved.

murk keeps your private key in ~/.config/murk/keys/, outside the repository, with restricted permissions. The CLI finds it from the absolute path of the vault. So under direnv, the repository holds nothing about the key, and the .envrc only runs murk export.

murk init also writes a .env for shells that do not use direnv. It holds a MURK_KEY_FILE line with the path to your key file, never the key itself, so source .env works too. That path is specific to your machine, so keep .env in .gitignore. murk doctor warns when git does not ignore .env.

If you prefer not to use direnv, murk exec gives the same result for a single command, without secrets in your shell environment:

Terminal window
murk exec -- ./deploy.sh # runs with all secrets in the environment

Use this pattern also where no shell session exists for direnv to hook into, such as CI (see CI/CD).