Skip to main content
Endor Labs hooks for Cursor send a structured event for every session, prompt, MCP tool call, shell command, and file operation in the IDE. The hook also enforces your Coding Agent Governance policies locally before each action reaches the agent.
See Endor Labs MCP server in Cursor to query Endor Labs from the assistant. See Endor Labs Agent Kit in Cursor to install workflow agents. See Deploy hooks for Cursor to capture events and enforce Coding Agent Governance policies.

Before you begin

Confirm the following requirements before you install the hook:
  • An admin has completed the prerequisites, including creating an API key with the AI Audit User role.
  • The target machine runs macOS or Linux with Cursor installed. For Windows, generate the configuration.
  • endorctl is on PATH. This applies to the hand-written configuration below. A generated configuration installs and updates endorctl automatically at session start.
  • For the hand-written configuration, the shell that launches Cursor has these environment variables set:
    • ENDOR_API (for example, https://api.endorlabs.com)
    • ENDOR_NAMESPACE
    • ENDOR_API_CREDENTIALS_KEY
    • ENDOR_API_CREDENTIALS_SECRET
Do not export ENDOR_TOKEN in the environment that runs the hook. Hooks authenticate with the API key and secret only, and on older versions of endorctl the extra token triggered a mixed-authentication error that blocked endorctl ai-audit.
Prefer generating this file over maintaining it by hand. The in-browser generator assembles hooks.json from the mdm-scripts repository sources for macOS, Linux, and Windows. It writes the credentials into every hook command and adds a bootstrap that installs and updates endorctl at session start.
Use the following hooks.json configuration for macOS and Linux. Every hook has its own settings, and each command sets ENDOR_AI_AUDIT_CACHE_ENABLED=true so the hook batches events locally and sends them at sessionEnd. Cursor can pass environment from a sessionStart hook, but a conversation that resumes after a restart loses that environment, and hooks fired inside subagents never receive it.
On Windows, generate the file instead. See Generate a configuration in your browser to produce it, or use the Cursor tab under Generate a configuration manually.

Install for one developer

Use this for a single-machine trial or a personal install.
  1. Open ~/.cursor/hooks.json in a text editor. Create the file if it does not exist.
  2. Paste the configuration shown in Before you begin.
  3. Save the file and restart Cursor.

Install on a managed macOS fleet

Cursor reads enterprise hooks from /Library/Application Support/Cursor/hooks.json. Use your MDM, such as Jamf, Intune, Kandji, or JumpCloud, to deliver that file to each managed machine. If you deliver a hand-written file, also set the four Endor Labs environment variables (ENDOR_API, ENDOR_NAMESPACE, ENDOR_API_CREDENTIALS_KEY, ENDOR_API_CREDENTIALS_SECRET) in the shell that launches Cursor. A generated file includes the credentials inline.
On macOS, environment variables set in ~/.zshrc reach apps launched from a terminal but not apps launched from Spotlight. Ship the variables through your MDM payload, for example a launchctl setenv profile, so apps launched from Spotlight also receive them.
If your MDM’s deployment script rejects the inline JSON payload, encode the configuration in Base64 in the script and decode it on the target machine. This avoids the quoting and escaping issues that some MDMs introduce when they deliver JSON.

Per-repository overrides

Add <repository>/.cursor/hooks.json and commit it. Workspace hooks layer on top of user hooks and let security-sensitive projects extend the configuration.

Cursor hook events used by Coding Agent Governance

The following table lists every event the hook processes. The hook accepts and ignores Cursor events outside this set, such as subagentStart, preCompact, afterShellExecution, afterFileEdit, and stop, if a configuration registers them. An older configuration keeps working, but those events record nothing. A Block policy denies a Cursor Tab read. Cursor can’t pause a Tab read for approval, so an Ask policy denies it the same way. Cursor’s hook response for beforeTabFileRead holds only a permission and no message, so neither the developer nor the agent sees the policy’s User Message. If the hook itself errors out, the action runs anyway and Cursor keeps working, so a hook problem never blocks a developer. The usual cause is a missing binary. An unreadable local policy cache does not disable enforcement, because the hook falls back to the built-in system policies. A successfully evaluated Block policy still stops the action.

Run the hook in audit-only mode

For an audit-only rollout, set ENDOR_AI_AUDIT_NO_BLOCKING=true in the Cursor hook environment, in the same place as the Endor Labs credentials. endorctl ai-audit then downgrades every Block action to Alert at evaluation time. Endor Labs still records violations under Policy Violations, but the hook never denies a action. Ask Permission policies can still prompt the developer. Use audit-only mode to trial a new policy without interrupting developers. Unset the variable when you’re ready to enforce. The values 1, t, T, true, TRUE, and True turn the option on. Any other value, including an unset or empty variable, keeps enforcement on.

Verify hooks are firing

  1. Start a session in Cursor and ask the agent to run a benign shell command, such as ls.
  2. Select Agent Governance > Inventory from the left sidebar. The page opens on the Workstation Inventory tab.
  3. Confirm the developer’s Cursor row shows a recent value under Last Active.
If no row appears, see Troubleshoot missing events.

What developers see when a policy fires

When a policy with the Block action matches an event, the hook returns a deny response to Cursor. Cursor stops the action and shows the User Message to the developer when the hook response can carry it. A response that includes a message also explains that a governance policy denied the action and tells the agent not to work around the block. When a policy with the Ask Permission action matches, Cursor asks the developer to confirm or deny, where it can pause at that event. Where it cannot pause, the outcome depends on the event type. Endor Labs records the match under Policy Violations as Ask either way. See Enforcement behavior to review the per-agent behavior. When a policy with the Alert action matches, the hook allows the action to proceed. Endor Labs records the event under Policy Violations for your security team to review.

Troubleshoot missing events

Hook errors never block the developer. If the hook cannot run or reach the Endor Labs API, Cursor allows the action, and the event is missing from inventory with no error. Run these checks if a developer’s actions never appear under Workstation Inventory or Policy Violations:
  • Confirm the developer has started at least one session. With the event cache enabled, the hook batches events and sends them to Endor Labs within about 30 seconds of hook activity. The hook also sends every queued event at session start and end. Inventory Sessions, Last Active, and counts can therefore lag the newest actions by that interval.
  • Confirm endorctl is on PATH in the environment that runs the hook. If the binary is not found, the hook does nothing and shows no error. Run endorctl version from the same shell to verify.
  • Confirm only one endorctl installation is active. If endorctl ai-audit fails with Failed with non-blocking status code: No stderr output, conflicting installations are the likely cause, such as an npx-provisioned endorctl alongside a Homebrew install. Keep one installation method per machine, remove the others, then run endorctl version to confirm.
  • Confirm the hook receives the Endor Labs API URL, namespace, API key, and secret. A hand-written configuration reads them from ENDOR_API, ENDOR_NAMESPACE, ENDOR_API_CREDENTIALS_KEY, and ENDOR_API_CREDENTIALS_SECRET.
  • Confirm ENDOR_TOKEN is not also exported alongside your Coding Agent Governance API key credentials in the hook environment. Hooks rely only on ENDOR_API_CREDENTIALS_KEY and ENDOR_API_CREDENTIALS_SECRET. ENDOR_TOKEN is redundant and, on older versions of endorctl, triggered a mixed-authentication error that blocked endorctl ai-audit.
  • Confirm the API key has the AI Audit User role and has not expired.
  • Confirm the developer restarted Cursor after the hooks file or a policy changed. Cursor reads the configuration and refreshes the local policy cache at session start.
  • Confirm the JSON file parses. A trailing comma silently disables every hook in the file.
  • Confirm the Endor Labs API is reachable from the environment that runs the hook. Network failures appear as gaps in the inventory.

Next steps

With hooks deployed, continue with the following pages: