openclaw run — Execute AI Tasks
The primary command for running AI agent tasks from the command line. Accepts any natural language description and executes it autonomously.
Synopsis
openclaw run [OPTIONS] "<task description>"The run command is the most frequently used command in the OpenClaw CLI. It accepts a natural language task description, sets up an autonomous agent, and executes the task step by step. The agent can read and write files, run shell commands, call APIs, and interact with your system within configurable boundaries.
Description
When you invoke openclaw run, the following happens internally:
- The task description is parsed and sent to the configured LLM provider.
- The agent creates an execution plan broken into discrete steps.
- Each step is executed using the available tools (filesystem, shell, web, etc.).
- Results are evaluated and the plan is adjusted as needed.
- Final output is returned to stdout or written to the specified file.
By default, OpenClaw has access to the current working directory. Use --context to specify a different path or limit the scope to a specific file or folder.
Options & Flags
| Flag | Type | Default | Description |
|---|---|---|---|
--provider | string | openai | LLM provider: openai, claude, ollama, gemini |
--model | string | gpt-4o | Model name to use for this task |
--max-steps | int | 20 | Maximum number of agent execution steps |
--timeout | int | 300 | Timeout in seconds before aborting |
--dry-run | flag | false | Preview planned actions without executing them |
--verbose | flag | false | Show detailed step-by-step execution logs |
--quiet | flag | false | Suppress all output except the final result |
--output | string | stdout | Write result to this file path |
--format | string | text | Output format: text, json, markdown |
--context | path | none | File or directory to provide as agent context |
--profile | string | default | Configuration profile name to use |
--no-confirm | flag | false | Skip all confirmation prompts automatically |
Usage Examples
1. Basic File Summarization
Summarize all text files in a directory:
openclaw run "Summarize all .txt files in ~/docs"Expected output:
Found 12 .txt files in ~/docs.
report.txt (2.3 KB): Monthly sales report covering Q4 2025...
notes.txt (1.1 KB): Meeting notes from Dec 15 standup...
[...]
Summary complete. 12 files processed.2. Contextual Code Review
Review source code for security issues and output a markdown report:
openclaw run --context ./src "Review this code for security issues" --format markdown --output security-report.md3. Dry Run Preview
Preview what actions would be taken without actually executing them:
openclaw run --dry-run "Delete all .tmp files older than 30 days in /tmp"[DRY RUN] Planned actions:
1. Scan /tmp for .tmp files
2. Filter files older than 30 days
3. [WOULD DELETE] /tmp/cache_a1b2.tmp (45 days old, 2.1 MB)
4. [WOULD DELETE] /tmp/session_xy99.tmp (32 days old, 0.3 MB)
No changes made. Re-run without --dry-run to execute.4. Custom Provider & Model
Use Claude Sonnet instead of the default OpenAI provider:
openclaw run --provider claude --model claude-3-5-sonnet "Explain this codebase architecture" --context .5. JSON Output for Scripting
Output structured JSON for use in automation pipelines:
openclaw run "List all Python functions in project" --format json --output functions.json --context ./src{
"task": "List all Python functions in project",
"status": "completed",
"steps_used": 8,
"result": {
"functions": [
{"name": "parse_config", "file": "config.py", "line": 12},
{"name": "run_agent", "file": "agent.py", "line": 47}
],
"total": 2
}
}Exit Codes
| Code | Meaning |
|---|---|
0 | Task completed successfully |
1 | Error — task failed due to agent or tool error |
2 | Timeout — task exceeded the configured timeout |
3 | Aborted — user cancelled with Ctrl+C or confirmation rejected |
Check exit codes in shell scripts with $? (bash) or $LASTEXITCODE (PowerShell) to detect failures and implement error handling in automated pipelines.
- openclaw start — launch as a persistent service
- openclaw config — manage configuration settings
- AI Coding Use Cases — real-world examples
- CLI Commands Overview