Shell Hooks
The shell hook watches for directory changes and automatically loads or unloads secrets based on the kredsfile.yaml in scope. Install it once per shell and it runs transparently on every cd.
How it works
The hook installs a shell function that intercepts kredenv commands and wraps directory change detection. When you move into a directory with a kredsfile.yaml that has autoload: true, secrets are injected into your environment. When you leave, they are unloaded.
The hook also intercepts kredenv load and kredenv unload so they work correctly in your interactive shell.
Installation
Bash
Add to ~/.bashrc:
echo 'eval "$(kredenv hook bash)"' >> ~/.bashrcThen restart your shell or run:
source ~/.bashrcZsh
Add to ~/.zshrc:
echo 'eval "$(kredenv hook zsh)"' >> ~/.zshrcThen restart your shell or run:
source ~/.zshrcFish
Add to ~/.config/fish/config.fish:
echo 'kredenv hook fish | source' >> $__fish_config_dir/config.fishThen restart your shell.
PowerShell
Add to your PowerShell profile:
Add-Content $PROFILE 'Invoke-Expression (& { (kredenv hook powershell | Out-String) })'Then restart PowerShell or run:
. $PROFILENushell
Nushell loads hooks from saved scripts in the autoload directory:
kredenv hook nushell | save -f ($nu.default-config-dir | path join "autoload" "kredenv.nu")WARNING
After upgrading kredenv, re-run this command to regenerate the hook script with the latest version.
Verifying the Hook
Check that the hook is active:
echo $__KREDENV_BINIf this prints the path to the kredenv binary, the hook is installed and active.
Starship Integration
kredenv exposes two environment variables for use in prompt frameworks:
KREDENV_LOADED_COUNT— number of secrets currently loadedKREDENV_LOADED_VARS— comma-separated list of loaded secret names
See Prompt Frameworks for setup examples.