qwen --prompt "Refactor this code" --output stream-json
Each line is a JSON event:
{"type":"system_message","timestamp":"...","content":"Session initialized"}{"type":"user_message","timestamp":"...","content":"Refactor this code"}{"type":"assistant_message_start","timestamp":"..."}{"type":"content","value":"I'll refactor this code..."}{"type":"tool_call","name":"edit","args":{"filePath":"..."}}{"type":"tool_result","success":true}{"type":"assistant_message_end"}{"type":"result","isError":false,"durationMs":3421}
# Pipe content to qwencat requirements.txt | qwen --prompt "Create a project from these requirements"# Use heredocqwen --prompt "Review this code" <<EOFfunction add(a, b) { return a + b;}EOF
# Set API keyexport GOOGLE_API_KEY="your-key-here"# Configure modelexport QWEN_MODEL="gemini-2.5-pro"# Set working directoryexport QWEN_WORKDIR="/path/to/project"# Disable telemetryexport QWEN_TELEMETRY=false# Set approval modeexport QWEN_APPROVAL_MODE=yolo
#!/bin/bash# Daily maintenance scriptset -e# Update dependenciesqwen -p "Update package.json dependencies to latest versions" --approval-mode yolo# Run testsqwen -p "Run the test suite and fix any failures" --approval-mode yolo# Generate reportqwen -p "Create a summary of changes" --output json > daily-report.jsonecho "Maintenance complete!"
Tools that require user input (like ask_user_question) will fail in headless mode.Workaround: Use YOLO mode to skip confirmations, or provide input upfront.
Limited to single prompt
Each invocation processes one prompt. For multi-turn conversations, use interactive mode.Workaround: Chain multiple invocations or use the ACP protocol for stateful sessions.
No visual feedback
Progress indicators and rich formatting aren’t available.Workaround: Use stream-json output to implement your own progress tracking.
Session not persisted by default
Headless sessions aren’t saved to disk unless explicitly configured.Workaround: Use --save-session flag or export output to a file.