> For the complete documentation index, see [llms.txt](https://docs.ox.security/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ox.security/scan-and-analyze-with-ox/scanning/ox-cli-1/scanning-code-with-ox-cli/integrate-ox-cli-with-git-hooks.md).

# Integrate OX CLI with Git Hooks

You can integrate the OX CLI with Git hooks to automatically scan your code before committing or pushing changes. Unlike manual scans, Git hooks run automatically as part of your Git workflow, helping identify security issues without requiring developers to remember to run scans.

OX CLI supports two types of Git hook installations:

| Installation type                                        | Use when                                                                   | Description                                                                                                                                                           |
| -------------------------------------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [**Repository Git hooks**](#manage-repository-git-hooks) | You want to enable automatic scanning for a specific repository.           | Installs Git hooks only in the selected repository. This option is useful when different repositories require different Git hook configurations.                      |
| [**Global Git hooks**](#global-git-hooks)                | You want to enable automatic scanning in all repositories on your machine. | Installs Git hooks once by using Git's global `core.hooksPath` configuration. This option is useful when you want the same scanning behavior across all repositories. |

### Before you begin

Make sure that:

* The OX CLI is installed.
* The CLI is authenticated using one of the supported authentication methods.

### Manage repository Git hooks

Repository Git hooks apply only to the current repository.

| Task                          | Command                                           | Description                                                      |
| ----------------------------- | ------------------------------------------------- | ---------------------------------------------------------------- |
| **Install a pre-push hook**   | `ox-cli install-git-hook --type pre-push`         | Installs the default Git hook that scans before pushing changes. |
| **Install a pre-commit hook** | `ox-cli install-git-hook --type pre-commit`       | Installs a Git hook that scans before each commit.               |
| **Uninstall a pre-push hook** | `ox-cli uninstall-git-hook --type pre-push`       | Removes the installed pre-push hook.                             |
| **Replace an existing hook**  | `ox-cli install-git-hook --type pre-push --force` | Replaces an existing non-OX Git hook.                            |

### Global Git hooks

Global Git hooks apply to all repositories on your machine.

#### Global Git hook behavior

Global Git hooks differ from repository Git hooks in the following ways:

| Behavior         | Description                                                                                                    |
| ---------------- | -------------------------------------------------------------------------------------------------------------- |
| Target directory | The CLI ignores any target directory that you specify.                                                         |
| `--force`        | Not supported for global Git hooks.                                                                            |
| Existing hooks   | Existing global hooks are preserved. OX installs its hook alongside existing hooks and chains their execution. |

#### Manage global Git hooks

| Task                                 | Command                                              | Description                                               |
| ------------------------------------ | ---------------------------------------------------- | --------------------------------------------------------- |
| **Install a global pre-push hook**   | `ox-cli install-git-hook --global --type pre-push`   | Installs the default global Git hook.                     |
| **Install a global pre-commit hook** | `ox-cli install-git-hook --global --type pre-commit` | Installs a global Git hook that scans before each commit. |
| **Uninstall a global pre-push hook** | `ox-cli uninstall-git-hook --global --type pre-push` | Removes the installed global pre-push hook.               |

### Limitations

Global Git hooks have the following limitations:

* Repositories that define their own `core.hooksPath` aren't covered because Git gives precedence to the repository-specific configuration. This is common with **Husky**, **lefthook**, and **pre-commit**. Install a repository Git hook for these repositories instead.
* A POSIX shell is required. On Windows, Git must be installed with Git Bash or another compatible shell.
* If the global hooks directory already contains an OX backup from a previous installation, uninstall the existing global Git hook before installing a new one.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ox.security/scan-and-analyze-with-ox/scanning/ox-cli-1/scanning-code-with-ox-cli/integrate-ox-cli-with-git-hooks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
