Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
---
title: "Scan code locally with the CLI"
sidebarTitle: "Scan with the CLI"
description: "Scan a Git repository's history or a directory for leaked secrets with infisical scan."
---
The [Infisical CLI](/cli/overview) 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](/documentation/platform/secret-scanning/pre-commit-hook).
## Prerequisites
- The [Infisical CLI](/cli/install) 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
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
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
<CardGroup cols={2}>
<Card title="Pre-commit hook" icon="git-commit-horizontal" href="/documentation/platform/secret-scanning/pre-commit-hook">
Prevent secrets from getting committed with a pre-commit hook that runs `infisical scan`.
</Card>
<Card title="Ignore findings" icon="eye-off" href="/documentation/platform/secret-scanning/ignore-findings">
Stop `infisical scan` from reporting secrets you've decided are safe to commit.
</Card>
<Card title="Configuration" icon="settings" href="/documentation/platform/secret-scanning/local-configuration">
Add your own detection rules to `infisical scan` and skip secrets you've decided are safe.
</Card>
<Card title="infisical scan" icon="terminal" href="/cli/reference#scan">
See every flag of the scan commands.
</Card>
</CardGroup>