Skip to main content
Endor Labs hooks for Claude Code send a structured event for every session, user prompt, tool call, shell command, and file operation. The hook also enforces your Coding Agent Governance policies locally before each tool call runs.
See Endor Labs MCP server in Claude Code to query Endor Labs from the assistant. See Endor Labs Agent Kit in Claude Code to install workflow agents.

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, Linux, or Windows with Claude Code installed. Windows machines need a generated configuration.
  • endorctl is on PATH. This applies to the hand-written configuration on this page. A generated configuration installs and updates endorctl automatically at session start.
  • ENDOR_TOKEN is not exported in the environment that launches Claude Code. Hooks authenticate with the API key and secret only.

Create the hook configuration

Claude Code passes the Endor Labs credentials and namespace to the hooks from the env block in settings.json, so the configuration is self-contained. Replace the placeholder values in env with your namespace and an API key issued for the AI Audit User role. To skip editing by hand, see Generate a configuration in your browser to build settings.json or a macOS configuration profile. The generated file also installs and updates endorctl at session start. The env block also sets ENDOR_AI_AUDIT_CACHE_ENABLED to true. This turns on the local event cache. The hook sends cached events in batches, about every 30 seconds while hooks run. It also sends them at session start and end. The same cache carries the developer’s resolved email to every tool event and subagent event in the session. Without it, those events fall back to the operating system login. Use the following configuration for macOS and Linux.
On Windows, generate the file instead. See Generate a configuration in your browser to produce it, or use the Claude Code tab under Generate a configuration manually.

Install for one developer

Use a per-user install for a single-machine trial or a personal setup.
  1. Open ~/.claude/settings.json in a text editor. Create the file if it does not exist.
  2. Add the env and hooks blocks from the hook configuration to the file. If the file already has a hooks key, add the new event entries to it instead of adding a second hooks key.
  3. Save the file and restart any active Claude Code session.

Install on a managed fleet

Claude Code reads enterprise hooks from a managed settings file. On macOS, the file is /Library/Application Support/ClaudeCode/managed-settings.json. On Linux, it is /etc/claude-code/managed-settings.json. Use your MDM, such as Jamf, Intune, Kandji, or JumpCloud, to deliver that file to each managed machine. The env block in the configuration holds the Endor Labs credentials, so you don’t need a separate shell setup. When Claude Code starts with the --managed-settings flag, the hook includes those settings when it records the session’s agent configuration. An administrator-managed source, such as the managed settings file or an MDM profile, takes precedence over the flag. The flag’s settings apply under such a source only when it sets parentSettingsBehavior to merge. Allow lists from the flag stay in effect unless an administrator-managed source locks them, for example with allowManagedPermissionRulesOnly.
On macOS, a configuration profile with the com.anthropic.claudecode payload type can lose its env block to another profile. macOS keeps one env block per payload type. If another product, for example a developer analytics tool, ships a profile with this payload type and sets env, the Endor Labs hooks can run without credentials. The hooks then stop reporting, with no error.Before you deploy, check your fleet for other profiles with this payload type. If one exists, combine both payloads into one profile. A combined profile can lose the Endor Labs env block again when either product changes its template, so repeat the profile checks after each profile push.
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.

Add repository hooks

Add <repository>/.claude/settings.json and commit it. Claude Code runs repository hooks alongside user and enterprise hooks, so security-sensitive projects can extend the configuration. For local additions outside source control, use <repository>/.claude/settings.local.json.

Claude Code hook events used by Coding Agent Governance

The hook processes these seven Claude Code events. The hook accepts and ignores Claude Code events outside this set, such as Stop, PermissionRequest, and SubagentStart, if a configuration registers them. An older configuration keeps working, but the hook records nothing for those events. When you connect the Anthropic Compliance API, the SessionStart hook resolves the developer’s organization identity from their Claude account email. Session policies can then match on the developer’s organization roles and groups. 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 tool call.

Run the hook in audit-only mode

For an audit-only rollout, set ENDOR_AI_AUDIT_NO_BLOCKING=true in the Claude Code 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 tool call. 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 Claude Code 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 Claude Code 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 Claude Code. Claude Code stops the tool call 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, Claude Code 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, Claude Code allows the tool call, 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 Claude Code after the hooks file or a policy changed. Claude Code 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.

Hooks run, but no events reach Endor Labs

On macOS, another profile with the com.anthropic.claudecode payload type can replace the Endor Labs env block. See Check a Claude Code macOS profile to confirm the cause and fix it, starting at step 5.

Next steps

With hooks deployed, continue with the following pages: