# Claude Code Integration

Connect Claude Code to Capsule Security for complete visibility into AI coding assistant activity, including prompts, tool execution, session lifecycle, and MCP tool usage.

## Overview

This integration uses Claude Code's hooks system to capture AI coding assistant activity. Hooks are shell commands that execute at specific points in Claude Code's lifecycle, providing automated workflows and audit capabilities.

![Claude Code Hooks](/assets/claude-code.2f595d998fc5e82008d2375e30b9d9c5865e6cf0c3368d09b195dc8ea952803a.9c1bb791.png)

The following hooks are configured:

| Hook Event | Description |
|  --- | --- |
| **SessionStart** | Session initialization and context with MCP tools definitions |
| **UserPromptSubmit** | User prompts, with their pasted images, before submission |
| **PreToolUse** | Tool execution requests (before execution) |
| **PostToolUse** | Tool execution results (after successful completion) |
| **Stop** | Agent stop events when the agent finished responding |
| **SessionEnd** | Session termination and cleanup |
| **SubagentStart** | A subagent was spawned by the agent |
| **SubagentStop** | A subagent finished, with its final message |


## Pasted Images

Images pasted or attached to a prompt are analyzed together with that prompt before Claude receives it, so a prevention policy can block a prompt because of what its image shows. Each image is also stored and shown with its message in the session log.

- **Formats and size:** PNG, JPEG, GIF and WebP, up to 5 MB per image. Beyond 10 MB of images in one prompt, the remaining images are analyzed after Claude responds and cannot block that prompt.
- **What leaves the machine:** only images that are part of a submitted prompt. In the terminal, an image pasted and then removed before submitting is not sent.
- **Non-interactive runs:** images in prompts sent with `claude -p` are analyzed after Claude responds.
- **Older configurations:** a `managed-settings.json` generated before image analysis was available still sends images, but only after Claude responds, so they cannot block the prompt. Redeploy the current configuration to analyze images before submission.


## Prerequisites

Before you begin, ensure you have:

- **Claude Code** installed. On Windows, version 2.1.139 or later: the Windows hooks start PowerShell through Claude Code's exec form (`command` plus `args`), which older versions do not run
- A **Capsule Security** account with admin access


## Step 1: Generate the Configuration

1. Log in to the **Capsule Security** portal
2. Navigate to **Integrations** and locate **Claude Code**
3. Click **Install** - Capsule automatically generates a `managed-settings.json` file containing:
  - Hook commands for all lifecycle events
  - An embedded authentication token scoped to your organization
  - Platform-specific scripts (bash for macOS/Linux, PowerShell for Windows)
4. Select your target platform (**macOS**, **Linux**, or **Windows**) to download the configuration file. **Windows** downloads `capsule-claude-code-windows.zip`, which contains `managed-settings.json` and the `hooks\capsule-hook.ps1` dispatcher its hooks run. Never deploy the macOS or Linux file to Windows: its hooks run through `bash` and fail on machines without Git for Windows


## Step 2: Deploy the Configuration

Deploy the configuration to every developer machine with your Mobile Device Management (MDM) tool.

**Setup:**

1. Deploy the downloaded `managed-settings.json` file to the appropriate path for your platform:


| Platform | Path |
|  --- | --- |
| **macOS** | `/Library/Application Support/ClaudeCode/managed-settings.json` |
| **Linux / WSL** | `/etc/claude-code/managed-settings.json` |
| **Windows** | `C:\Program Files\ClaudeCode\managed-settings.json` |


On Windows, also deploy `hooks\capsule-hook.ps1` from the archive to `C:\Program Files\ClaudeCode\hooks\capsule-hook.ps1`.

Use your organization's device management solution (Jamf, Intune, SCCF, etc.) to distribute the file to all developer machines. Set appropriate file permissions (read-only recommended).

1. Include the hooks configuration provided by Capsule Security in the deployed file
2. Set appropriate file permissions (read-only recommended to prevent user modifications)


**Limitations:**

- Users can potentially override or disable hooks with project-level settings (`.claude/settings.json`)
- Users can add local overrides via `.claude/settings.local.json`
- Requires MDM infrastructure capable of deploying user-level configuration files
- Manual updates required when hooks configuration changes


**Key Considerations:**

- Centrally managed by your IT or security team
- Your organization is responsible for deployment and updates


For step-by-step, platform-specific instructions, see the dedicated MDM guides:

- [Jamf Pro](/guides/mdm-jamf)
- [Kandji](/guides/mdm-kandji)
- [JumpCloud](/guides/mdm-jumpcloud)
- [Microsoft Intune](/guides/mdm-intune)
- [ManageEngine Endpoint Central](/guides/mdm-manageengine)
- [Microsoft SCCM](/guides/mdm-sccm)
- [Tanium](/guides/mdm-tanium)


## Step 3: Restart Claude Code

For the hooks to take effect:

1. Exit Claude Code by pressing **Ctrl+C** or typing `/exit`
2. Restart Claude Code


## Step 4: Verify the Installation

1. Run `/hooks` in Claude Code to confirm all hooks are listed
2. Start a session and execute a simple task to generate activity:

```
Create a new file called test.txt with the content "Hello World"
```
3. Log in to the **Capsule Security** portal
4. Navigate to **Inventory > Agents** and confirm your Claude Code agent appears
5. Click on the agent and review the audit logs to verify events are captured:
  - Session start event
  - User prompt
  - Tool execution (Write tool)
  - Session activity
6. To view the full conversation, navigate to **Observability** and filter by **Activity Type - Session**


### Troubleshooting

If events are not appearing:

1. **Verify the managed-settings.json is in the correct path** for your platform (see Step 2)
2. **Check file permissions** - the file must be readable by the user running Claude Code
3. **Verify settings file syntax** - ensure the file contains valid JSON:

```bash
cat "/Library/Application Support/ClaudeCode/managed-settings.json" | python3 -m json.tool
```
4. **Run `/hooks` in Claude Code** - if no hooks are listed, the file is not being loaded
5. **Check Claude Code logs** for hook execution errors
6. **Contact Capsule Security support** if issues persist


## Security Considerations

Claude Code hooks execute with your current environment credentials. Before deploying hooks:

1. **Review all hook scripts** provided by Capsule Security
2. **Verify the endpoint URL** matches your organization's Capsule instance
3. **Protect authentication tokens** used by hooks (never commit to version control)
4. **Use `.claude/settings.local.json`** for sensitive configuration values
5. **Ensure `.claude/settings.local.json` is in `.gitignore`**


## Support

For help with this integration:

- **Email**: support@capsule.security
- **Include**: Your organization ID, integration status, and any error messages


## References

- [Claude Code Hooks Documentation](https://code.claude.com/docs/en/hooks)
- [Claude Code Hooks Guide](https://code.claude.com/docs/en/hooks-guide)
- [Claude Code Settings](https://code.claude.com/docs/en/settings)
- [Claude Code Hook Configuration](https://code.claude.com/docs/en/settings#hook-configuration)