Command Safety

Delta CLI's Command Safety feature protects you from accidentally running dangerous commands, providing intelligent warnings and safer alternatives before potential disasters occur.

How It Works

Real-time Analysis

Every command is analyzed in milliseconds before execution:

  1. Command parsing and intent detection
  2. Risk assessment based on context and patterns
  3. Comparison against known dangerous patterns
  4. Generation of safer alternatives when needed
Context Aware
Analyzes your current directory, environment, and command history
Lightning Fast
Adds less than 10ms to command execution time
Non-intrusive
Only intervenes for genuinely dangerous commands

Risk Levels

Low Risk (Score: 0-3)

Safe commands that pose minimal risk. Executed without warnings.

bash
ls -la
pwd
echo "Hello World"
git status

Medium Risk (Score: 4-6)

Commands that could cause issues. Shows a warning but allows execution.

bash
rm file.txt
git reset HEAD~1
sudo service nginx restart

High Risk (Score: 7-8)

Dangerous commands. Requires confirmation with explanation of risks.

bash
rm -rf important_directory/
chmod -R 777 /
git push --force origin main

Critical Risk (Score: 9-10)

Extremely dangerous commands. Blocked by default unless explicitly overridden.

bash
rm -rf / --no-preserve-root
dd if=/dev/random of=/dev/sda
:(){ :|:& };:

Safety in Action

File Deletion Protection

When you run:

bash
delta rm -rf *

Delta CLI warns:

⚠️ High Risk Command Detected!
This will recursively delete all files in the current directory:
/home/user/important-project
Affected: 1,247 files (2.3 GB)
Safer alternatives:
• Move to trash: trash *
• Delete specific files: rm -rf temp/ logs/
• Archive first: tar -czf backup.tar.gz * && rm -rf *
Type 'yes' to proceed or Ctrl+C to cancel:

Permission Changes

When you run:

bash
delta chmod -R 777 .

Delta CLI warns:

⚠️ Security Risk Detected!
This will make all files world-writable, creating security vulnerabilities.
Recommended instead:
• For web files: chmod -R 644 . && find . -type d -exec chmod 755 \;
• For scripts: chmod +x script.sh
• For user only: chmod -R 700 .

Git Force Push Protection

When you run:

bash
delta git push --force origin main

Delta CLI warns:

⚠️ Potentially Destructive Git Operation!
Force pushing to 'main' will overwrite remote history.
• 5 commits will be lost
• 3 other contributors may be affected
Consider instead:
• Create a new branch: git checkout -b fix/my-changes
• Push without force: git push origin main
• Merge upstream: git pull --rebase origin main

Configuration

Customize Command Safety to match your risk tolerance and workflow:

Safety Levels

bash
# Set overall safety level
delta :config safety.level strict    # Block dangerous commands
delta :config safety.level normal    # Warn but allow (default)
delta :config safety.level relaxed   # Minimal warnings

# Check current setting
delta :config safety.level

Custom Rules

bash
# Add custom dangerous patterns
delta :safety add-pattern "rm -rf /important/*"

# Whitelist safe commands
delta :safety whitelist "rm -rf node_modules"

# Set risk score for specific commands
delta :safety set-risk "docker system prune -a" 5

Directory-Specific Settings

bash
# Extra protection for important directories
delta :safety protect ~/Documents --level=strict
delta :safety protect /etc --level=strict

# Relaxed rules for temporary directories
delta :safety protect /tmp --level=relaxed

Bypassing Safety Checks

Force Execution

bash
# Force a single command
delta --force rm -rf important_file

# Or use the shorthand
delta -f rm -rf important_file

Temporary Disable

bash
# Disable for current session
delta :safety off

# Re-enable
delta :safety on

API Integration

Integrate Delta CLI's Command Safety into your own tools and applications:

Command Safety API

Our API allows you to add the same safety checks to your AI assistants, automation tools, and command-line applications.

Learn about the Command Safety API →

Best Practices

Do's
  • Read safety warnings carefully
  • Use suggested alternatives when provided
  • Configure safety levels for your workflow
  • Test dangerous commands in safe environments first
Don'ts
  • Habitually bypass safety warnings
  • Disable safety in production environments
  • Ignore context in safety warnings
  • Run unfamiliar commands without understanding

Next Steps

Command Safety is just one way Delta CLI protects and assists you. Explore more features:

  1. Learn about Error Recovery for automatic fixes when commands fail
  2. Explore the AI Assistant for intelligent command suggestions
  3. Configure Delta CLI to match your preferences