CLI Usage
Basic Commands
AI Guard provides a simple CLI interface:
bash
# Analyze entire projectnpx ai-guard
# Analyze only git staged filesnpx ai-guard --staged
# Show versionnpx ai-guard --version
# Show helpnpx ai-guard --helpAnalyze Entire Project
Run AI Guard without arguments to analyze all files in your project:
bash
npx ai-guardThis will scan all TypeScript and JavaScript files according to your include/exclude patterns in the config file.
Analyze Staged Files
Use the --staged flag to analyze only files staged in git:
bash
npx ai-guard --stagedThis is ideal for pre-commit hooks, as it only checks the files you're about to commit.
Exit Codes
AI Guard uses standard exit codes for CI/CD integration:
| Exit Code | Meaning | Description |
|---|---|---|
| 0 | Success | No violations found |
| 1 | Violations | AI patterns detected |
| 2 | Error | Configuration or runtime error |
In CI pipelines, exit code 1 will fail the build, preventing merge until violations are fixed.
Output Format
Violations are grouped by file and include:
- File path relative to project root
- Line number where violation occurs
- Rule name in brackets
- Specific violation message
- Total count of violations per file
bash
src/services/api.ts Line 23: [excessive-comments] Comment ratio 18% exceeds threshold of 15% Line 45: [generic-names] Avoid generic variable name: 'result'
Found 2 violations in 1 file.Use AI Guard in your CI pipeline by adding 'npx ai-guard' as a test script. Failed checks will prevent merges.