Skip to content

Auto Activation

devenv includes a built in shell hook that automatically activates your developer environment when you cd into a project directory. No external tools required.

Add one line to your shell configuration file:

~/.bashrc
eval "$(devenv hook bash)"

Before a project can auto activate, you need to explicitly trust it. This is a security measure that prevents untrusted projects from modifying your shell.

Navigate to the project directory and run:

Terminal window
$ cd ~/myproject
$ devenv allow
devenv: allowed /home/user/myproject

To activate one or more profiles whenever the project is entered, pass them when allowing it:

$ devenv --profile backend --profile observability allow
devenv: allowed /home/user/myproject with profile backend, observability

The selected profiles also apply to subsequent devenv commands in the project. An explicit --profile takes priority. Run plain devenv allow again to clear the saved profile selection without revoking trust.

When you cd into the directory next time, devenv will automatically start a shell:

Terminal window
$ cd ~/myproject
(devenv) $

To stop a project from auto activating:

Terminal window
$ cd ~/myproject
$ devenv revoke
devenv: revoked /home/user/myproject

The hook runs on every directory change and:

  1. Checks the trust database to verify the project was allowed.
  2. If trusted, runs devenv shell in a subshell for that project.

If a project has not been trusted yet, you will see a message asking you to run devenv allow:

devenv: /home/user/myproject is not allowed. Run 'devenv allow' to trust this directory.

When you cd out of the project directory (or any of its subdirectories), the devenv shell exits automatically and you return to your normal shell:

Terminal window
(devenv) $ cd ..
$

The hook will not nest environments. While inside a devenv shell, navigating into a subdirectory of the same project keeps the current shell. Only navigating outside the project triggers deactivation.

Feature devenv hook direnv
External dependencies None Requires direnv
Setup One line in shell config direnv install + .envrc per project
Trust granularity Per project directory Per .envrc file
Environment application Spawns a subshell Modifies current shell in place
Unloading on exit Subshell exits automatically direnv unloads variables

Use devenv hook for a simple, dependency free setup. Use direnv if you prefer in place environment modification without a subshell.