Skip to content

Guidance on integration with direnv #723

Closed

Description

@strangemonad

Thanks for this awesome project!

Opening this mostly to start the conversation. I don't know that I've fully landed on a final smooth and secure pattern.

The outcome of this ticket could be as simple as documentation around how to setup or something more involved.

Context:
You have ~/Code/my-repo/.envrc and you've already run cd ~/Code/my-repo && direnv allow .

Some options:

  1. broad whitelist
    This isn't ideal from a security perspective but works
# ~/.config/direnv/direnv.toml

[whitelist]
prefix = [
  "/Users/shawn/Code/my-repo."
]
  1. wt <> direnv shell hook

You could imagine a more refined version of the following shell code that could query wt for current worktrunk state and only trigger the direnv allow based on a wt config.

for rc in /Users/shawn/Code/my-repo.*/.envrc; do
  direnv allow "$rc"
done

Activity

  1. max-sixty commented on Jan 18, 2026

    @max-sixty
    Owner

    thanks for the issue!

    would be great to support this better. I don't use direnv myself so may need some guidance if I'm missing anything.

    would the post-switch hook work well for this?

      [hooks]
      post-switch = ["direnv allow ."]
    

    ...it runs after switching into the worktree, so the .envrc gets approved automatically. It can be a User Hook so it runs on all local projects?

  2. strangemonad commented on Jan 19, 2026

    @strangemonad
    Author

    post-switch is probably overkill since direnv allow only needs to happen once. I need to play around with this more. Ideally once the worktree is deleted, the direnv allow for that directory would also be cleaned up from whenever direnv stores its state.

  3. max-sixty commented on Jan 19, 2026

    @max-sixty
    Owner

    sorry, you're correct: post-create or post-start would be better, and then pre-remove for cleaning up

    I'm considering ways to make the hooks less verbose which will make this more discreet

    how does that sound?

  4. max-sixty commented on Jan 19, 2026

    @max-sixty
    Owner

    thinking about it some more: what's the downside of the whitelist option?

  5. strangemonad commented on Jan 19, 2026

    @strangemonad
    Author

    @max-sixty mostly a security issue. once direnv is allowed to operate on a path prefix, any .envrc under that prefix can then load env vars and run arbitrary code in the .envrc file.

  6. max-sixty commented on Feb 10, 2026

    @max-sixty
    Owner

    the hooks are now much less verbose! it'll add just a couple of words to the output when running in the background.

    so I think it makes sense to keep at that generic level. let me know how that goes, feel free to open a new issue if there are still issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions