Overview
The--prompt (or -p) option runs Qwen Code in non-interactive mode, executing a single prompt and exiting. This is ideal for automation, scripting, and CI/CD pipelines.
Syntax
Basic Usage
Single Command
Code Generation
Code Review
Piping Input
Combine stdin with the prompt:Output Formats
Text Output (Default)
Human-readable output:JSON Output
Structured output for parsing:Stream JSON Output
Real-time streaming events:Combining with Other Options
With Model Selection
With YOLO Mode
Auto-approve all actions:With Session Management
With Approval Mode
Slash Commands in Prompts
You can use slash commands in headless mode:Only certain slash commands work in non-interactive mode. Commands requiring user interaction (like
/auth, /model) are not supported.Automation Examples
CI/CD Pipeline
Code Generation Script
Documentation Generator
Error Analyzer
Interactive vs Non-Interactive
Use --prompt When:
✅ Running in scripts or CI/CD✅ One-shot commands
✅ Automated workflows
✅ Piping data through Qwen Code
✅ Need programmatic output (JSON)
Use Interactive Mode When:
✅ Exploratory work✅ Complex, multi-step tasks
✅ Need to approve actions
✅ Iterative development
✅ Want conversation history
Prompt Engineering
Be Specific
Provide Context
Use Clear Instructions
Error Handling
Check Exit Codes
Parse JSON Errors
Advanced Usage
Multi-line Prompts
Prompt from File
Chaining Commands
Conditional Execution
Output Processing
Extract Code Blocks
Parse JSON Output
Stream Processing
Performance Tips
Use Faster Models
For simple tasks:Limit Output
Parallel Execution
Limitations
No Interactive Features
These features don’t work in headless mode: ❌ Model selection dialog (/model)❌ Authentication dialog (
/auth)❌ Session picker (
--resume without ID)❌ Manual approval prompts
❌ Terminal UI navigation
Workarounds
Troubleshooting
No Output
If there’s no output:Hanging
If the command hangs:Encoding Issues
See Also
--prompt-interactive
Execute prompt then continue interactively
--yolo
Auto-approve all actions
Headless Mode
Complete guide to headless mode
Output Formats
Working with different output formats
