Cursor-agent does not inherit from direnv

Describe the Bug

Similar to this report it seems that environmental variables created by direnv are not part of the cursor-agent environment.

This is very problematic for me because I need to use a specific GitHub personal access token with one project. We check in .cursor/mcp.json to our Git repository, and have this config:

{
  "mcpServers": {
    "github": {
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer ${env:GITHUB_PERSONAL_ACCESS_TOKEN}"
      }
    }
}

Since cursor is not correctly inheriting the PAT from .envrc, I cannot access GitHub MCP.

Steps to Reproduce

Set up direnv, create an .envrc with this content:

export DIRENV_ENABLED_FOR_CURSOR="yes"

Then start cusor-agent and run ! echo $DIRENV_ENABLED_FOR_CURSOR and there will be no output.

Expected Behavior

The cursor agent should inherit the shell environment.

Operating System

MacOS

Version Information

About Cursor CLI

CLI Version 2026.02.27-e7d2ef6
Model Claude 4.6 Sonnet
OS darwin (arm64)
Terminal wezterm
Shell zsh

Does this stop you from using Cursor

Sometimes - I can sometimes use Cursor

Hey, thanks for the detailed report. This is a known issue. The CLI starts a non-interactive shell (zsh -c), so it only sources ~/.zshenv, not ~/.zshrc. Since most users put eval "$(direnv hook zsh)" in .zshrc, direnv never runs.

Workaround: move the direnv hook to ~/.zshenv:

# ~/.zshenv
eval "$(direnv hook zsh)"

This makes sure direnv loads even in non-interactive shell sessions.

One more thing. The ${env:GITHUB_PERSONAL_ACCESS_TOKEN} syntax in your mcp.json is VS Code-specific and might not resolve in the CLI. If the workaround above doesn’t fix the MCP config, try ${GITHUB_PERSONAL_ACCESS_TOKEN} instead, without the env: prefix.

The team is aware of the CLI environment inheritance issue. Your report helps with visibility and prioritization.

Let me know if the workaround helps.

Removing the env: from ${env:GITHUB_PERSONAL_ACCESS_TOKEN} did allow GitHub MCP to authenticate, but it used my global GITHUB_PERSONAL_ACCESS_TOKEN instead of the one configured in .envrc, even after making the change to ~/.zshrenv. So no, the workaround suggested does not work.

Furthermore, removing env: from mcp.json is contradictory, because the cursor-agent mcp docs clearly state:

MCP in the CLI uses the same configuration as the editor

And if that is the case, then ENV interpolation should be using the env: prefix…? I don’t want to break my team’s ability to use Cusor (desktop) with this change.

Clearly there are some fundamental issues with cursor-agent and environment variables, and possibly some discrepancies between Cursor (desktop) and cusor-agent when it comes to MCP servers. This is very frustrating.

Hey, fair point. The .zshenv workaround doesn’t fully fix it. Even if the direnv hook loads, cursor-agent doesn’t guarantee that .envrc will activate for a specific project.

About the docs, you’re right. The CLI MCP page at MCP | Cursor Docs clearly says “MCP in the CLI uses the same configuration as the editor”, but in practice the ${env:...} syntax isn’t supported in the CLI.

So there are two issues:

  • cursor-agent doesn’t inherit direnv-specific environment variables
  • the ${env:...} syntax doesn’t resolve in the CLI, even though the docs claim parity with desktop

Both are on the team’s radar.

1 Like

@deanrie is there a way to automatically inject environmental variables specifically into Cursor’s local agent at all–I don’t need to use direnv and would gladly use a workaround!?

I want to solve the same problem woody has mentioned but am not tied to using DIRENV

How can we fix this problem.

Hey, there isn’t a proper fix on the CLI side yet, but there is a workaround.

@elviskahoro if direnv isn’t a must, the simplest option is to export the needed variables in your session before starting cursor-agent:

export GITHUB_PERSONAL_ACCESS_TOKEN="your-token"
cursor-agent

Or do it in one go via a wrapper script or alias:

# ~/.zshenv or ~/.bashrc
export GITHUB_PERSONAL_ACCESS_TOKEN="your-token"

If you have lots of project-specific variables, you can run source .envrc && cursor-agent. This loads variables from .envrc into the current session before the agent starts.

For MCP config in the CLI, use ${GITHUB_PERSONAL_ACCESS_TOKEN} instead of ${env:GITHUB_PERSONAL_ACCESS_TOKEN}. The env: syntax isn’t supported in the CLI yet.

@acehinnnqru same workarounds above. The issue is that cursor-agent starts a non-interactive shell and doesn’t inherit variables from .zshrc or direnv. Until there’s a fix, you need to make sure the variables are available in the environment before starting the agent.

The team is aware of both issues inheritance and the ${env:...} syntax. There’s no ETA yet, but your reports help with prioritization.

Thanks for adding suggestions for us w.r.t CLI. I was primarily referring to the agent that’s automatically dispatched through the agent window. I’m looking to do something like this: https://github.com/elviskahoro/elviskahoro/blob/main/mcp.json