This article follows the official documentation. We haven’t tested this tool for a hands-on review.
A coding agent editing a repository can accidentally add an API key or another credential to a source file. TruffleHog is an open-source command-line tool that scans Git repositories and files for exposed credentials, then checks whether those credentials still work. You can ask the agent to run TruffleHog before committing and save the results locally for you to review.
Use TruffleHog to check a repository, not to inspect everything an agent sees. TruffleHog scans the sources you specify. Running the command does not let it inspect the agent’s private prompt or context. Keep credentials out of agent prompts, and use TruffleHog to check files and Git history. The TruffleHog repository documents its supported sources and command options.
Install and scan a local repository
On a machine with Homebrew, install TruffleHog with the command listed in the official installation instructions:
brew install trufflehog
The README lists other options for Linux and Windows, such as Docker images and an installation script.
This example scans the current local Git repository and disables online credential checks. It writes structured JSON results to a file:
trufflehog git file://. --no-verification --json > /tmp/trufflehog-findings.json
TruffleHog scans the Git repository in the current directory when you use git file://.. The --no-verification flag tells it not to verify the results, so it does not test detected credentials against their services. The --json flag formats the results as JSON. The shell redirects those results to a file instead of showing them in the agent’s conversation.
The git scan reads the repository’s commits and its staged changes. It does not read edits that are not staged yet, so stage the agent’s changes with git add before the scan. To check the files in a directory as they are on disk, the README documents trufflehog filesystem with a path. For a local repository, TruffleHog first clones it to a temporary directory. The README explains this as protection against malicious Git configuration.
The scan reads local Git data. With verification disabled, it does not send detected credentials to their service providers for live checks. The JSON file can contain sensitive findings. Store it where only authorized people can access it, and do not ask the agent to print its contents. Review the file yourself, or use an approved reporting method that does not expose secret values. These commands follow the official CLI documentation; they were not run for this article.
Decide whether to verify credentials
TruffleHog’s verification step checks whether a detected credential still works. For the AWS detector, the README says TruffleHog makes a GetCallerIdentity call to the AWS API. Successful verification helps you prioritize findings: a string that looks like a key is less conclusive than a credential that successfully logs in. Verification contacts the relevant service over the network. Those requests can trigger limits on how many requests the service accepts or raise security alerts. Start with --no-verification for a scan that stays local.
For a verification-enabled scan, remove --no-verification from the command. Do this only when the machine is allowed to contact the services involved and the resulting requests are acceptable. The --results flag then limits the output by status. For example, --results=verified,unknown shows confirmed credentials and the ones where verification failed with an error. The local Git scan does not need credentials for GitHub or another Git host. Scanning a private repository hosted elsewhere is a different use case, and the source determines what access it requires. Keep any required authentication outside the agent prompt.
A scan also does not undo an exposure. If a credential was committed and pushed, rotate it with the service that issued it. Removing the text from the latest file does not revoke the credential.
Use the scan before a commit
Ask the coding agent to stage its changes and run the scan before it commits them. The agent can run the local command and report whether it finished. A person can then inspect the JSON output. If the scan finds a likely credential, the agent should identify the affected file or commit without quoting the credential into its response.
TruffleHog also documents a pre-commit hook, a script Git runs while preparing a commit. The hook scans the staged changes at that point. The guide recommends running git add and git commit as separate steps, because git commit -am might bypass the hook for changes that were not staged. Use the hook to run the check for Git commits without relying on an agent prompt. A hook checks the repository at commit time; it still does not protect secrets placed in an agent’s prompt or other private context. Limit which secrets the agent can reach in the first place.
A concise instruction for an agent with shell access could be:
Before committing, stage your changes and run the documented TruffleHog local Git scan with verification disabled. Save JSON output to
/tmp/trufflehog-findings.json. Do not open or print that file, and do not include any credential value in your response. Tell me only whether the command completed and where the output was saved.
This instruction gives the agent a specific check and keeps sensitive output out of its conversation. The scan does not check agent prompts or environment variables, and it does not prove that every external service is free of secrets. Browse the Awesome CLI directory for other command-line tools that coding agents can use.