atmos ai exec
Give the AI a natural-language prompt and it will run Atmos commands, shell commands, and tool calls to carry out the task -- then return structured results. Designed for scripting, automation, and CI/CD pipelines where you need the AI to act, not just answer.
Configure AI
Learn how to configure AI providers, skills, tools, and sessions in your atmos.yaml.
Description
The atmos ai exec command takes a natural-language prompt, lets the AI run Atmos commands and shell commands to fulfill it, and returns structured output. Unlike atmos ai ask which produces human-readable answers, exec actually executes tools and commands, then returns machine-parseable results with exit codes, tool call details, and token usage.
Use it for:
- Automation: The AI runs
atmos describe,atmos validate, shell commands, etc. on your behalf - CI/CD Pipelines: Reliable exit codes and JSON output for deployment workflows
- Batch Processing: Process multiple infrastructure tasks programmatically
Usage
atmos ai exec [prompt] [flags]
The prompt can be provided as:
- Command argument:
atmos ai exec "your prompt" - Stdin pipe:
echo "your prompt" | atmos ai exec
Arguments
prompt- The prompt to execute (optional if using stdin). Use quotes for multi-word prompts.
Flags
--format, -f- Output format:
text,json,markdown(default:text) --output, -o- Output file path (default: stdout)
--no-tools- Disable tool execution for faster, simpler queries
--context- Include stack context in the prompt
--provider, -p- Override AI provider (anthropic, openai, gemini, grok, ollama, bedrock, azureopenai)
--session, -s- Session ID for conversation context (enables multi-turn execution)
--include- Add glob patterns to include in context (can be repeated)
--exclude- Add glob patterns to exclude from context (can be repeated)
--no-auto-context- Disable automatic context discovery
Exit Codes
The command uses standard Unix exit codes for automation:
0- Success.
1- AI error (API failure, invalid response, configuration error).
2- Tool execution error.
Output Formats
Text Format (Default)
Plain text response, suitable for human reading and logging:
atmos ai exec "List all available stacks"
Output:
Based on your configuration, here are the available stacks:
1. dev-us-east-1
2. staging-us-east-1
3. prod-us-east-1
...
JSON Format
Structured output with complete metadata:
atmos ai exec "Describe the vpc component" --format json
Output:
{
"success": true,
"response": "The VPC component creates a Virtual Private Cloud...",
"tool_calls": [
{
"tool": "atmos_describe_component",
"args": {"component": "vpc", "stack": "dev-us-east-1"},
"duration_ms": 245,
"success": true,
"result": {...}
}
],
"tokens": {
"prompt": 1234,
"completion": 567,
"total": 1801,
"cached": 890
},
"metadata": {
"model": "claude-sonnet-4-6",
"provider": "anthropic",
"duration_ms": 2340,
"timestamp": "2025-10-31T10:00:00Z",
"tools_enabled": true,
"stop_reason": "end_turn"
}
}
Markdown Format
Formatted output with tool execution summaries:
atmos ai exec "Analyze prod stacks" --format markdown
Output:
The production stacks are configured with:
- High availability across 3 AZs
- Auto-scaling enabled
- Enhanced monitoring
---
## Tool Executions (3)
1. ✅ **atmos_list_stacks** (45ms)
2. ✅ **atmos_describe_component** (120ms)
3. ❌ **atmos_validate_component** (89ms)
Examples
Basic Execution
Stdin Piping
CI/CD Integration
Multi-Turn Automation
Use --session to maintain conversation context across multiple exec calls. The session name is an arbitrary string that groups related calls together -- the AI remembers all previous messages in the same session.
Batch Processing
Error Handling
Provider Override
Advanced Usage
Output Parsing with jq
# Extract just the response
atmos ai exec "Question" --format json | jq -r '.response'
# Check for specific tool execution
atmos ai exec "Analyze" --format json | \
jq '.tool_calls[] | select(.tool == "atmos_describe_component")'
# Get token usage
atmos ai exec "Question" --format json | jq '.tokens'
# Check execution time
atmos ai exec "Question" --format json | jq '.metadata.duration_ms'
Integration Patterns
Email Reports:
atmos ai exec "Weekly infrastructure summary" --format markdown | \
mail -s "Weekly Report" team@example.com
Slack Notifications:
result=$(atmos ai exec "Check production health" --format json)
response=$(echo "$result" | jq -r '.response')
curl -X POST $SLACK_WEBHOOK -d "{\"text\":\"$response\"}"
Ticket Creation:
analysis=$(atmos ai exec "Identify issues in prod" --format json)
if echo "$analysis" | jq -e '.success == true'; then
issues=$(echo "$analysis" | jq -r '.response')
# Create ticket with issues
gh issue create --title "Infrastructure Issues" --body "$issues"
fi
Comparison with Other Commands
atmos ai ask- Non-interactive. Human-readable text output. Best for quick terminal questions.
atmos ai chat- Interactive. Rich TUI with markdown. Best for extended conversations.
atmos ai exec- Non-interactive. JSON/Text/Markdown output. Best for automation, scripting, CI/CD.
Best Practices
- Use
--format jsonfor automation - Provides structured, parseable output - Set
--no-toolsfor simple queries - Faster execution when tools aren't needed - Use
--sessionfor multi-turn workflows - Maintains context across calls - Check exit codes in scripts - Handle errors appropriately
- Disable tool confirmation in CI/CD - Set
require_confirmation: falsein config - Use
--outputfor file persistence - Avoid shell redirection issues - Parse JSON with jq - Robust handling of structured output
- Set appropriate timeouts - Adjust
timeout_secondsbased on your needs
Related Commands
📄️ atmos ai ask
Quick command-line questions
📄️ atmos ai chat
Interactive chat sessions
📄️ atmos ai sessions
Manage AI chat sessions
📄️ AI Skills
Install and use 21+ specialized AI skills