Commands Reference
Complete documentation for all 12 PromptGuard CLI commands.
promptguard init
Initialize PromptGuard in your project by scanning for LLM SDKs and applying transformations.
Usage
promptguard init [OPTIONS]
Options
Option Short Description Default --api-key <KEY>-kPromptGuard API key (required) - --provider <PROVIDER>-pSpecific provider to configure Auto-detect --base-url <URL>Custom proxy URL https://api.promptguard.co/api/v1--yes-ySkip confirmation prompts false--no-backupSkip creating backup files false--dry-runPreview changes without modifying files false
Examples
Basic
Specific Provider
Auto-confirm
Dry Run
promptguard init --api-key pg_sk_test_xxx
What It Does
Scans project for LLM SDK usage
Detects OpenAI, Anthropic, Cohere, HuggingFace SDKs
Creates backup files (*.bak)
Modifies SDK initialization to add baseURL/base_url
Saves API key to .env
Creates .promptguard.json configuration
promptguard scan
Scan project for LLM SDK usage without making any changes (dry-run).
Usage
promptguard scan [OPTIONS]
Options
Option Short Description --jsonOutput results in JSON format
Examples
# Basic scan
promptguard scan
# JSON output
promptguard scan --json
Output
🛡️ PromptGuard CLI v2.0.0
==================================================
📊 LLM SDK Detection Report
OpenAI SDK (3 files, 5 instances)
├── src/services/ai.ts
├── src/utils/chat.ts
└── lib/completions.ts
Anthropic SDK (1 files, 1 instances)
└── src/services/claude.ts
Summary:
• Total files scanned: 47
• Total instances: 6
Providers detected:
✓ openai
✓ anthropic
Next: promptguard init
promptguard status
Show current PromptGuard configuration and status.
Usage
Examples
Output
PromptGuard Status
==================================================
Status: ✓ Active
API Key: pg_sk_test_1********* (configured)
Proxy URL: https://api.promptguard.co/api/v1
Configuration:
• Config file: .promptguard.json
• Files managed: 3
• Providers: openai, anthropic
View full dashboard: https://app.promptguard.co/dashboard
promptguard apply
Re-apply transformations based on current configuration. Useful after changing proxy URL or providers.
Usage
When to Use
After updating proxy URL in config
After manual code changes
To re-apply transformations if files were modified
Examples
promptguard disable
Temporarily disable PromptGuard by restoring original files while keeping configuration and backups.
Usage
What It Does
Restores all files from backups
Marks configuration as disabled
Keeps .promptguard.json and backups
Examples
Re-enable later with:
promptguard enable
Re-enable PromptGuard by re-applying transformations.
Usage
What It Does
Re-scans project for LLM SDKs
Re-applies transformations
Marks configuration as enabled
Prerequisites
Must have been previously initialized
Configuration file must exist
promptguard revert
Completely remove PromptGuard by restoring original files and deleting all configuration.
Usage
promptguard revert [OPTIONS]
Options
Option Short Description --yes-ySkip confirmation prompt
What It Does
Restores all files from backups
Deletes all backup files
Removes API key from .env
Deletes .promptguard.json
Examples
This action cannot be undone. Your code will be restored to its original state.
promptguard config
View current configuration details.
Usage
Examples
Output
PromptGuard Configuration
==================================================
Configuration:
Version: 1.0
Status: Enabled ✓
Proxy URL: https://api.promptguard.co/api/v1
Providers: openai, anthropic
Environment file: .env
API key variable: PROMPTGUARD_API_KEY
Backups: Enabled
Backup extension: .bak
Exclude patterns:
• **/*.test.js
• **/*.test.ts
• **/node_modules/**
• **/dist/**
• **/__tests__/**
• **/.venv/**
Metadata:
CLI version: 2.0.0
Files managed: 3
Configuration file: /path/to/project/.promptguard.json
Commands:
promptguard disable - Temporarily disable PromptGuard
promptguard enable - Re-enable PromptGuard
promptguard revert - Completely remove PromptGuard
promptguard key
Manage API keys (update, view, rotate).
Usage
What It Does
Interactive menu for:
Update API key
Show full key
Rotate key (guidance)
Examples
API Key Management
==================================================
Current API key:
PROMPTGUARD_API_KEY = pg_sk_test_...1234
Options:
1. Update API key
2. Show full key (masked)
3. Rotate key
4. Cancel
Select option (1-4):
promptguard logs
View activity logs and link to dashboard.
Usage
Examples
Output
Activity Logs
==================================================
ℹ Fetching logs from PromptGuard API...
View your complete activity logs at:
https://app.promptguard.co/dashboard/activity
Recent activity:
• Request logs
• Security events
• API usage
For real-time monitoring:
Visit the dashboard at https://app.promptguard.co/dashboard
Detailed logs are available in the web dashboard. CLI shows summary and links.
promptguard test
Test configuration and verify API connectivity.
Usage
What It Does
Validates API key format
Tests connection to PromptGuard API
Checks configuration status
Examples
Output
Test PromptGuard Configuration
==================================================
Testing configuration...
🔑 API Key Validation
✓ API key is valid
✓ Proxy endpoint is reachable
⚙️ Configuration Check
✓ PromptGuard is enabled
Providers: openai
Proxy: https://api.promptguard.co/api/v1
✓ Configuration test complete!
Next steps:
• Run your application
• Monitor requests: https://app.promptguard.co/dashboard
• View logs: promptguard logs
promptguard doctor
Diagnose common configuration issues.
Usage
What It Checks
Configuration file exists and is valid
API key format
Backup files present
File permissions
SDK detection
Examples
promptguard update
Check for CLI updates and show installation instructions.
Usage
Examples
Output
Update PromptGuard CLI
==================================================
Current version: v2.0.0
ℹ Checking for updates...
To update PromptGuard CLI:
• Using install script:
curl -fsSL https://get.promptguard.co | sh
• Using Homebrew:
brew upgrade promptguard
• Using cargo:
cargo install --force promptguard-cli
Release notes:
https://github.com/acebot712/promptguard-cli/releases
Documentation:
https://docs.promptguard.co/cli
Global Options
Available for all commands:
Option Short Description --help-hShow help for command --version-VShow CLI version
Examples
# Show version
promptguard --version
# Help for specific command
promptguard init --help
# General help
promptguard --help
Exit Codes
Code Meaning 0Success 1General error 2Invalid arguments 3Not initialized 4API error 5File system error
Useful for CI/CD:
if ! promptguard test ; then
echo "PromptGuard configuration test failed"
exit 1
fi
Environment Variables
The CLI respects these environment variables:
Variable Description Default PROMPTGUARD_API_KEYAPI key (alternative to —api-key) - PROMPTGUARD_CONFIG_PATHCustom config file location .promptguard.jsonNO_COLORDisable colored output false
Examples
# Use environment variable for API key
export PROMPTGUARD_API_KEY = pg_sk_test_xxx
promptguard init
# Custom config path
export PROMPTGUARD_CONFIG_PATH = / path / to / config . json
promptguard status
Next Steps