CLI Usage

Basic Commands

AI Guard provides a simple CLI interface:

bash
# Analyze entire project
npx ai-guard
# Analyze only git staged files
npx ai-guard --staged
# Show version
npx ai-guard --version
# Show help
npx ai-guard --help

Analyze Entire Project

Run AI Guard without arguments to analyze all files in your project:

bash
npx ai-guard

This 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 --staged

This 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 CodeMeaningDescription
0SuccessNo violations found
1ViolationsAI patterns detected
2ErrorConfiguration 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.