> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Scan code locally with the CLI

> Scan a Git repository's history or a directory for leaked secrets with infisical scan.

The [Infisical CLI](https://infisical.com/docs/cli/overview.md) includes a secret scanner, `infisical scan`, that finds leaked secrets in a Git repository's history, in a directory, or in [changes you haven't committed yet](https://infisical.com/docs/documentation/platform/secret-scanning/pre-commit-hook.md).

## Prerequisites

* The [Infisical CLI](https://infisical.com/docs/cli/install.md) installed
* Git installed, if you're scanning a Git repository

## Scan a Git repository

To scan the full history of the Git repository you're in, run:

```bash theme={"dark"}
infisical scan --verbose
```

The scan reads every commit on every branch. To scan a range of commits instead, pass [Git log](https://git-scm.com/docs/git-log) options with `--log-opts`, such as `--log-opts="--all commitA..commitB"`.

## Scan a directory without Git history

To scan the current files in a directory or a file without reading Git history, add `--no-git` and point `--source` at the directory or file:

```bash theme={"dark"}
infisical scan --no-git --source ./config --verbose
```

## Exit codes and reports

If the scan finds a secret, the command exits with code `1`, which fails a CI job.

To write the findings to a file, add `--report-path`, and pick a format with `--report-format`: `json` (the default), `csv`, `sarif`, or `junit`.

## Next steps

> [card] [Pre-commit hook](https://infisical.com/docs/documentation/platform/secret-scanning/pre-commit-hook.md)
>
> Prevent secrets from getting committed with a pre-commit hook that runs `infisical scan`.

> [card] [Ignore findings](https://infisical.com/docs/documentation/platform/secret-scanning/ignore-findings.md)
>
> Stop `infisical scan` from reporting secrets you've decided are safe to commit.

> [card] [Configuration](https://infisical.com/docs/documentation/platform/secret-scanning/local-configuration.md)
>
> Add your own detection rules to `infisical scan` and skip secrets you've decided are safe.

> [card] [infisical scan](https://infisical.com/docs/cli/reference.md#scan)
>
> See every flag of the scan commands.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.