Skip to main content

Overview

The --yolo (or -y) option runs Qwen Code in YOLO mode (You Only Live Once), automatically approving all tool executions without prompting for confirmation. This is useful for automation, trusted environments, and when you want maximum speed.
YOLO mode automatically executes all file modifications, shell commands, and other operations without confirmation. Use with caution, especially in production environments.

Syntax

qwen --yolo
qwen -y
qwen --approval-mode yolo  # Equivalent

What It Does

With --yolo enabled: Auto-approves all file writes and edits
Auto-executes shell commands
Skips confirmation prompts
Maximizes execution speed
Continues without pausing

Basic Usage

Interactive Mode

qwen --yolo
All operations execute immediately:
> Create a REST API with authentication

✓ Creating src/api/routes.ts...
✓ Creating src/api/auth.ts...
✓ Installing dependencies...
✓ Running tests...

All done! API created successfully.

Headless Mode

qwen --yolo --prompt "Fix all linting errors in the project"
Executes without any confirmation:
# Auto-runs:
# 1. npm run lint -- --fix
# 2. Edits all files with errors
# 3. Verifies fixes

When to Use YOLO Mode

Trusted Environments

# Development environment
qwen --yolo --prompt "Update dependencies"

# CI/CD pipeline
qwen --yolo --prompt "Generate documentation"

# Personal projects
qwen --yolo --prompt "Refactor this module"

Automation Scripts

#!/bin/bash
# Automated code generation
qwen --yolo --prompt "Generate CRUD endpoints for User model"

Batch Operations

# Process multiple files
for file in src/**/*.ts; do
  qwen --yolo --prompt "Add JSDoc comments to $file"
done

Time-Sensitive Tasks

# Quick fixes
qwen --yolo --prompt "Fix the broken build ASAP"

When NOT to Use YOLO Mode

Production Environments

# DON'T DO THIS
qwen --yolo --prompt "Update production database schema"

# Instead:
qwen --prompt "Generate migration for database schema"
# Review the migration before applying

Unfamiliar Codebases

# DON'T DO THIS
cd new-project
qwen --yolo --prompt "Refactor everything"

# Instead:
qwen --prompt "Analyze the codebase structure"
# Understand before making changes

Destructive Operations

# DON'T DO THIS
qwen --yolo --prompt "Delete all unused code"

# Instead:
qwen --approval-mode plan --prompt "Identify unused code"
# Review before deleting

Shared Repositories

# DON'T DO THIS on main branch
git checkout main
qwen --yolo --prompt "Update APIs"

# Instead: work on a branch
git checkout -b feature/api-update
qwen --yolo --prompt "Update APIs"
# Review and test before merging

Combining with Other Options

With Model Selection

# Use powerful model + auto-approve
qwen --model qwen-coder-plus --yolo --prompt "Refactor entire codebase"

With Output Format

# Automation with JSON output
qwen --yolo --prompt "Fix bugs" --output-format json

With Session Management

# Continue previous session with auto-approve
qwen --continue --yolo --prompt "Now implement the remaining features"

Safety Considerations

Use Version Control

Always use Git when running YOLO mode:
# Create a checkpoint
git add .
git commit -m "Before YOLO mode changes"

# Run YOLO mode
qwen --yolo --prompt "Refactor the codebase"

# Review changes
git diff

# Undo if needed
git reset --hard HEAD

Backup Important Files

# Backup before YOLO mode
cp -r src src.backup

# Run YOLO mode
qwen --yolo --prompt "Major refactoring"

# Restore if needed
rm -rf src
mv src.backup src

Use Sandboxes

# Run in isolated environment
qwen --yolo --sandbox --prompt "Test destructive operations"

Review Logs

# Enable logging
qwen --yolo --prompt "Task" 2>&1 | tee yolo-session.log

# Review what was executed
cat yolo-session.log

YOLO Mode vs Other Approval Modes

ModeFile EditsShell CommandsUse Case
yoloAuto-approveAuto-approveAutomation, trusted env
auto-editAuto-approvePromptSafe file changes
defaultPromptPromptInteractive development
planNo executionNo executionReview before executing

Choosing the Right Mode

# Maximum automation
qwen --yolo  # or --approval-mode yolo

# Safe automation (only edits)
qwen --approval-mode auto-edit

# Review before executing
qwen --approval-mode plan

# Interactive (default)
qwen  # or --approval-mode default

Examples

Code Generation

qwen --yolo --prompt "Create a complete authentication system"
Generates and writes:
  • src/auth/login.ts
  • src/auth/register.ts
  • src/auth/middleware.ts
  • tests/auth.test.ts
Without any confirmation prompts.

Bug Fixes

# Auto-fix all issues
qwen --yolo --prompt "Fix all TypeScript errors in the project"

Code Refactoring

# Refactor without interruption
qwen --yolo --prompt "Convert all class components to functional components"

Dependency Updates

# Update and test
qwen --yolo --prompt "Update all dependencies and run tests"

Automation Scripts

Daily Code Maintenance

#!/bin/bash
# daily-maintenance.sh

set -e

echo "Starting daily maintenance..."

# Create backup
git stash

# Run maintenance tasks
qwen --yolo --prompt "Fix linting errors"
qwen --yolo --prompt "Update outdated dependencies"
qwen --yolo --prompt "Optimize imports"
qwen --yolo --prompt "Run tests and fix failures"

# Commit changes
git add .
git commit -m "Daily maintenance: $(date +%Y-%m-%d)"

echo "Maintenance complete!"

CI/CD Integration

# .github/workflows/ai-fixes.yml
name: AI Auto-fixes

on:
  push:
    branches: [develop]

jobs:
  auto-fix:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Install Qwen Code
        run: npm install -g @qwen/cli
      
      - name: Run auto-fixes
        env:
          DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }}
        run: |
          qwen --yolo --prompt "Fix all linting errors" \
               --output-format json > fixes.json
      
      - name: Commit fixes
        if: success()
        run: |
          git config user.name "AI Bot"
          git config user.email "[email protected]"
          git add .
          git commit -m "AI: Auto-fix linting errors"
          git push

Bulk Code Updates

#!/bin/bash
# bulk-update.sh

FILES=$(find src -name '*.ts')

for file in $FILES; do
  echo "Processing $file..."
  qwen --yolo --prompt "Modernize $file: use ES6+ features, add type annotations"
done

echo "Bulk update complete!"

Monitoring YOLO Executions

Log All Actions

# Log everything
qwen --yolo --prompt "Task" 2>&1 | tee -a yolo-audit.log

# Review later
grep "Executing" yolo-audit.log

Track Changes

# Before
git rev-parse HEAD > before.txt

# Execute
qwen --yolo --prompt "Make changes"

# After
git diff $(cat before.txt) > yolo-changes.diff

Cost Tracking

qwen --yolo --prompt "Task" --output-format json | \
  jq '.usage.totalTokens' >> token-usage.log

Troubleshooting

Unexpected Changes

If YOLO mode made unwanted changes:
# Undo with Git
git reset --hard HEAD~1

# Or restore specific files
git checkout -- path/to/file

# Review what changed
git diff HEAD~1

Failed Executions

If a YOLO command fails midway:
# Check what was completed
qwen --prompt "/stats tools"

# Review error logs
qwen --debug --yolo --prompt "Task"

# Clean up partial changes
git reset --hard

Prompt Too Broad

If YOLO mode attempts too many changes:
# Don't do this:
qwen --yolo --prompt "Improve the codebase"

# Be specific:
qwen --yolo --prompt "Add error handling to all API routes"

Best Practices

Always work in a version-controlled environment:
# Verify Git repo
git status

# Create checkpoint
git add . && git commit -m "Before YOLO changes"

# Run YOLO mode
qwen --yolo --prompt "Task"

# Review and commit or revert
git diff
Test YOLO mode with small tasks first:
# Start with safe operations
qwen --yolo --prompt "Add comments to this function"

# Build confidence
qwen --yolo --prompt "Refactor this single file"

# Then scale up
qwen --yolo --prompt "Refactor the module"
Vague prompts are dangerous in YOLO mode:
# Bad (too vague)
qwen --yolo --prompt "Fix the code"

# Good (specific)
qwen --yolo --prompt "Fix TypeScript errors in src/auth.ts"
Never deploy YOLO changes directly:
# Development workflow
git checkout -b feature/ai-changes
qwen --yolo --prompt "Implement feature"
git add . && git commit -m "AI: Feature implementation"

# Review
git diff main
npm test

# Then merge
git checkout main
git merge feature/ai-changes

Advanced Usage

Conditional YOLO

#!/bin/bash
# Use YOLO only in dev environment

if [ "$ENV" = "development" ]; then
  APPROVAL_FLAG="--yolo"
else
  APPROVAL_FLAG=""  # Prompt in production
fi

qwen $APPROVAL_FLAG --prompt "Deploy updates"

Sandboxed YOLO

# Test changes in sandbox first
qwen --yolo --sandbox --prompt "Risky operation"

# If successful, apply to real environment
qwen --yolo --prompt "Risky operation"

Rate-Limited YOLO

#!/bin/bash
# Prevent runaway automation

for task in "${TASKS[@]}"; do
  qwen --yolo --prompt "$task"
  sleep 5  # Pause between operations
done

See Also

--plan Option

Plan-only mode for reviewing before execution

Approval Modes

Understanding different approval modes

Safety Guidelines

Best practices for safe AI usage

Automation

Complete automation guide