Agent shell tool doesn't source login shell, causing pre-commit hooks to fail

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Brief summary:
The agent’s shell tool starts a minimal non-login shell, so environment setup from ~/.zshrc (like activated Python/pixi environments) is never loaded.

Where it appears:
Agent mode shell tool when running git commit in any repo that uses pre-commit hooks requiring a pre-activated environment (e.g. pixi/conda/nvm-based toolchains).

Bug description:
The shell tool launches zsh without the -l (login) flag, so ~/.zshrc and ~/.zprofile are never sourced. Pre-commit hooks that check for an activated environment (e.g. PIXI_IN_SHELL, virtualenv, nvm) find nothing set and attempt a full bootstrap, which fails due to missing credentials or network restrictions in the sandbox. The same git commit succeeds instantly in any user-facing terminal because those shells inherit the fully-initialized environment. The fix would be to source the user’s shell init files (or run as a login shell) when the shell tool is invoked.

Steps to Reproduce

  1. Open a repo that uses pre-commit hooks requiring an activated environment (e.g. pixi/conda)
  2. Ask the Cursor agent to run git commit via the shell tool
  3. Hooks fail with environment activation errors

Expected Behavior

The agent’s shell tool should source the user’s login shell init files (~/.zshrc / ~/.zprofile) so pre-commit hooks have access to the same environment available in any user-facing terminal.

Operating System

MacOS

Version Information

Version: 3.0.13 (Universal)
VSCode Version: 1.105.1
Commit: 48a15759f53cd5fc9b5c20936ad7d79847d914b0
Date: 2026-04-07T03:05:17.114Z (1 day ago)
Layout: glass
Build Type: Stable
Release Track: Default
Electron: 39.8.1
Chromium: 142.0.7444.265
Node.js: 22.22.1
V8: 14.2.231.22-electron.0
OS: Darwin arm64 25.1.0

For AI issues: which model did you use?

Sonnet 4.6

Additional Information

The workaround is committing from the integrated terminal directly, where the environment is already active. The issue only affects the agent’s shell tool.

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @LaurenLeite !

I think there may be some helpful tips available over in this thread: Cursor terminal documentation missing non-interactive agent shell configuration guidance - #6 by mohitjain

Hey, thanks for the pointer! I did end up going down that rabbit hole and found that the ~/.zshenv approach mentioned there doesn’t fully work for our setup — Cursor’s snapshot restore runs after .zshenv and clobbers the PATH changes anyway.

What actually fixed it was the preToolUse hook approach that @DevZen and @mohitjain describe later in that thread. Instead of direnv/nix, I needed pixi and nodenv, but the pattern is the same — the hook injects the right PATH entries after the snapshot restore, right before each command runs.

~/.cursor/hooks/setup-env.sh:

#!/bin/bash

input=$(cat)

if ! command -v jq >/dev/null 2>&1; then

echo '{"permission": "allow"}'

exit 0

fi

read -r -d '' inject <<'INJECT'

export PATH="$HOME/.pixi/bin:$HOME/.nodenv/shims:$HOME/.nodenv/bin:$PATH";

INJECT

echo "$input" | jq --arg prefix "$inject" '{

  permission: "allow",

  updated_input: {

    command: ($prefix + " " + .tool_input.command)

  }

}'

chmod +x ~/.cursor/hooks/setup-env.sh

~/.cursor/hooks.json:

{

    "version": 1,

    "hooks": {

        "preToolUse": [

        {

              "command": "/Users/YOUR_USERNAME/.cursor/hooks/setup-env.sh",

              "matcher": "Shell"

        }

        ]

     }

}

Restart your agent session after adding the files. Swap in whatever PATH entries your toolchain needs!