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_TOKENis 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 theenv 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.
Install for one developer
Use a per-user install for a single-machine trial or a personal setup.- Open
~/.claude/settings.jsonin a text editor. Create the file if it does not exist. - Add the
envandhooksblocks from the hook configuration to the file. If the file already has ahookskey, add the new event entries to it instead of adding a secondhookskey. - 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.
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 asStop, 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, setENDOR_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
- Start a session in Claude Code and ask the agent to run a benign shell command, such as
ls. - Select Agent Governance > Inventory from the left sidebar. The page opens on the Workstation Inventory tab.
- Confirm the developer’s Claude Code row shows a recent value under Last Active.
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
PATHin the environment that runs the hook. If the binary is not found, the hook does nothing and shows no error. Runendorctl versionfrom the same shell to verify. - Confirm only one endorctl installation is active. If
endorctl ai-auditfails withFailed with non-blocking status code: No stderr output, conflicting installations are the likely cause, such as annpx-provisioned endorctl alongside a Homebrew install. Keep one installation method per machine, remove the others, then runendorctl versionto 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, andENDOR_API_CREDENTIALS_SECRET. - Confirm
ENDOR_TOKENis not also exported alongside your Coding Agent Governance API key credentials in the hook environment. Hooks rely only onENDOR_API_CREDENTIALS_KEYandENDOR_API_CREDENTIALS_SECRET.ENDOR_TOKENis redundant and, on older versions of endorctl, triggered a mixed-authentication error that blockedendorctl 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 thecom.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:- See Triage policy violations to set your daily review workflow.
- See Coding Agent Governance overview to track adoption and enforcement trends.