relic guard stops secrets from reaching your git history. It runs two checks:
- Dotenv files: flags committed or staged
.env,.env.local,.env.production,*.env, and.dev.varsfiles. - Relic values: decrypts your linked project’s secrets on your device and searches for exact occurrences of their values in the content being committed.
sk********.
Quick Start
1
Link your project
Run
relic init at the repository root so the guard knows which project’s secrets to match.
Without relic.toml, only the dotenv check runs.2
Install the pre-commit hook
git commit now runs relic guard scan --staged and is blocked when it finds a leak.3
Scan the existing tree
Scanning
Without
--staged or --range, the guard scans the given paths (default: the current directory). Inside a git repository it scans tracked files plus untracked files that aren’t gitignored, so a gitignored local .env is not reported.
Examples:
Exit Codes
Output
--json, each finding includes type (dotenv or value), file, and for value findings line, column, secrets (key and environment), and preview. Range scans add the commit SHA.
Value Matching
The guard decrypts secrets the same wayrelic run does, then builds an Aho-Corasick automaton over all values and scans every file in a single pass. Decrypted values stay in memory for the duration of the scan and are never written to disk.
To avoid noise, it skips values that:
- are shorter than the minimum length (default
8) - are booleans, numbers, or common literals like
production - point at local hosts, such as
http://localhost:3000orpostgres://user:[email protected]/db - repeat a single character
When Values Can’t Be Loaded
If you’re logged out, offline, or the repository has norelic.toml, the dotenv check still runs and the output says that value matching was skipped. The commit is not blocked for that reason. Pass --require-values to fail instead, which is useful in CI.
Value loading times out after 20 seconds so a slow network can’t hang your commit.
Authentication
Service account exports are rate limited to 6 requests per minute with a burst of 3. Each
-e
flag costs one request, so pass at most three environments per CI run.Ignoring Findings
Add arelic-guard-ignore comment anywhere on a line to skip value findings on that line:
.relicguardignore file at the repository root. It uses gitignore syntax:
Configuration
Add a[guard] section to relic.toml:
.env.example, .env.sample, and .env.template (and names like .env.local.example) are always allowed.
Pre-commit Hooks
relic guard install writes .git/hooks/pre-commit. If a pre-commit hook already exists, it’s moved to pre-commit.pre-relic and still runs first. relic guard uninstall restores it.
If the repository uses a hook manager, the guard prints the snippet to add instead of writing hooks:
- Lefthook
- Husky
- pre-commit
lefthook.yml
relic guard install offers to add this for you. Pass --yes to skip the prompt.The installed hook skips the scan with a warning when
relic isn’t on your PATH, so teammates
without Relic can still commit.CI
Scan every commit in a pull request so a secret that was added and later removed is still caught. Use a service account for value matching..github/workflows/leak-guard.yml
--require-values if you accept fork contributions; the dotenv check still runs for them.