> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-cli/cortex-cli-for-code-security/cortex-cli-pre-commit-hooks.md).

# Cortex CLI pre-commit hooks

Integrate the Application Security secrets scanner as a pre-commit hook by installing the Cortex CLI. The scanner executes the hook locally before a commit. This setup ensures that secrets checks are enforced before any changes are committed.

When setting up pre-commit hooks, you can choose between local hooks and global hooks.

* **Local**: Installs the hook in the `.git/hooks` directory of the **current** repository, ensuring that Cortex XSIAM secrets scans automatically run on your code before every commit
* **Global**: Installs the hook for **all** Git repositories on your machine, so Cortex XSIAM secrets scans will automatically run on your code before every commit, regardless of the project

**How to configure pre-commit hooks**

{% hint style="warning" %}

### Danger

These common prerequisites are required for all types of installation (both local and global) of the Cortex CLI pre-commit hook.

* Ensure you have a license for Application Security
* Install the Cortex XSIAM CLI binary locally. Refer to [Connect Cortex CLI](/cortex-cli/connect-cortex-cli.md) for information about onboarding the CLI
* Obtain Cortex XSIAM API credentials (API Key ID and API Key) available from the CLI onboarding process (see above), and your API base URL. For more information on creating API keys, refer to [Create a new API key](/xsiam-api/create-a-new-api-key.md)
* **Git**: You must have Git installed on your machine. For installation instructions, refer to the [official Git website](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
  {% endhint %}

1. Create a directory:

   ```programlisting
    mkdir -p ~/.cortexcli
   ```
2. Create a `.cortex.yaml` file in the `~/.cortexcli/` directory.
3. Open the `.cortex.yaml` file and add your Cortex XSIAM API credentials and API base URL to the `yaml` file:

   * `CORTEX_API_BASE_URL`: \<replace with the base API URL>
   * `CORTEX_API_KEY_ID`: \<replace with API Key ID>
   * `CORTEX_API_KEY`: \<replace with API Key>

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><h3>Note</h3><p>It is recommended you configure credentials for the Cortex CLI using a configuration file.</p></div>
4. **For local hooks**: Install the Cortex CLI pre-commit hook package to set up a local hook for the current Git repository:

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><h3>Prerequisite</h3><p>For local installation: Install the <strong>pre-commit</strong> framework version 3.2.0 or greater. Refer to <a href="https://pre-commit.com/">https://pre-commit.com/</a> for installation instructions.</p></div>

   1. * For **macOS**, you can use **Homebrew**:

        ```programlisting
         brew install pre-commit
        ```
      * For other installations run:

        ```programlisting
         pip install pre-commit
        ```
   2. **Navigate to the root of your repository** → **run the following command**:

      ```programlisting
       cortexcli code pre-commit install --mode local
      ```
5. **For Global hooks**: Install the Cortex CLI pre-commit hook package to set up hooks for all Git repositories on your machine.

   ```programlisting
   cortexcli code pre-commit install --mode global
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><h3>Note</h3><p>The <strong>pre-commit</strong> framework is not required for global mode.</p></div>

**References**

To set up the Cortex CLI as a pre-commit hook on supported platforms, refer to the following official Git documentation for managing hooks:

* **Git Hooks**: A comprehensive guide on all available Git hooks, including `Pre-commit`: <https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks>
* **Atlassian Git Tutorial**: A tutorial that explains the purpose and usage of both local and server-side hooks, including `pre-commit`: <https://www.atlassian.com/git/tutorials/git-hooks>


---

# 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://cortex-docs.paloaltonetworks.com/cortex-cli/cortex-cli-for-code-security/cortex-cli-pre-commit-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.
