# Auto Activation

**New in version 2.1**

[Read more about auto activation in the v2.1 release post](/blog/2026/05/07/devenv-21-nix-with-zsh-fish-and-nushell-via-libghostty/)

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

## Setup

* Bash

  Add one line to your shell configuration file:

  **\~/.bashrc**

  ```bash
  eval "$(devenv hook bash)"
  ```

* Zsh

  Add one line to your shell configuration file:

  **\~/.zshrc**

  ```bash
  eval "$(devenv hook zsh)"
  ```

* Fish

  Usually nothing to do — devenv installed via Nix ships a snippet that fish loads automatically. If it doesn’t load for you, add this instead:

  **\~/.config/fish/config.fish**

  ```fish
  devenv hook fish | source
  ```

* Nushell

  Usually nothing to do — devenv installed via Nix ships a snippet that nu loads automatically. If it doesn’t load for you, add this instead:

  Run once, in Nu:

  ```nu
  mkdir ($nu.default-config-dir | path join autoload)
  devenv hook nu | save --force ($nu.default-config-dir | path join autoload/devenv-hook.nu)
  ```

### Passing arguments to `devenv shell`

**New in version 2.3**

Place arguments for the auto-activated `devenv shell` after `--`. For example, to disable the TUI in shells started by the Fish hook without changing other `devenv` commands:

**\~/.config/fish/config.fish**

```fish
devenv hook fish -- --no-tui | source
```

The same separator works in every supported shell:

**\~/.bashrc**

```bash
eval "$(devenv hook bash -- --no-tui)"
```

## Trusting a project

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:

```sh
$ 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:

```shellsession
$ 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:

```sh
$ cd ~/myproject
(devenv) $
```

## Revoking trust

To stop a project from auto activating:

```sh
$ cd ~/myproject
$ devenv revoke
devenv: revoked /home/user/myproject
```

## How it works

The hook runs on every directory change and:

2. Checks the trust database to verify the project was allowed.
3. 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`:

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

> **Note**
>
> The hook detects projects by looking for a `devenv.nix` file. Before version 2.2, it looked for `devenv.yaml` instead, so projects with only `devenv.nix` were not auto-detected.

## Automatic deactivation

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:

```sh
(devenv) $ cd ..
$
```

## Re-entry protection

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.

## Comparison with direnv

| Feature                 | `devenv hook`                | [direnv](/integrations/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](/integrations/direnv/) if you prefer in place environment modification without a subshell.