PromptShield logo PromptShield
PromptShield CLI

CLI Commands

Detailed reference for PromptShield CLI commands.

The @promptshield/cli package provides a suite of commands to run the scanning engine across your workspace, fix issues automatically, and enforce deterministic sanitization.

All commands support resolving configuration from a promptshield.config.json file in your workspace root.

🔍 scan

The primary command for detecting threats in your codebase.

Usage:

promptshield scan [patterns...]

By default, without patterns, it scans **/*.

Options:

FlagTypeDescription
-c, --config <path>stringPath to a custom configuration file.
--min-severity <level>LOW | MEDIUM | HIGH | CRITICALOnly report threats at or above this severity.
--no-inline-ignorebooleanIgnore promptshield-ignore directives in source files.
--concurrency <num>numberNumber of files to process simultaneously.
--cache <mode>auto | single | split | noneControl the caching strategy. Default is auto.
--forcebooleanIgnore cache and force a full workspace rescan.
--jsonbooleanOutput results as a machine-readable JSON array.

Exit Codes:

  • 0: Scan completed, no threats found above the min-severity threshold.
  • 1: Scan completed, threats were found. This intentionally breaks CI/CD pipelines.

🛠 fix

The fix command runs the scanner and attempts to automatically resolve non-destructive issues (like removing invisible characters or un-smuggling Base64 payloads) using the deterministic rules in @promptshield/sanitizer.

Usage:

promptshield fix [patterns...]

Options:

Supports all the options of the scan command, plus:

FlagTypeDescription
-w, --writebooleanPersist the fixed files back to disk. If omitted, fix runs in a "dry-run" mode.

Exit Codes:

  • 0: Completed successfully. If --write is specified, files were modified.
  • 1: Scan found threats that could not be automatically fixed.

🚿 sanitize

The sanitize command is a lower-level utility that runs the entire sanitization pipeline over the matched files, ignoring the detection engine entirely.

It is idempotent and guarantees a clean state, regardless of whether a specific threat was detected.

Usage:

promptshield sanitize [patterns...]

Options:

FlagTypeDescription
-w, --writebooleanPersist the sanitized files back to disk. If omitted, sanitize runs in a "dry-run" mode.
--strictbooleanApply NFKC Unicode normalization. Warning: This can be destructive to intentional typography or mathematical symbols.
--concurrency <num>numberNumber of files to process simultaneously.

Exit Codes:

  • 0: Completed successfully.

Example Workflows

CI/CD Pipeline (Fail on HIGH/CRITICAL):

promptshield scan --min-severity HIGH

Pre-commit Hook Setup (Fix automatically):

promptshield fix "**/*.ts" "**/*.md" --write

Aggressive Content Cleanup:

promptshield sanitize content/**/*.md --write --strict

On this page