Skip to main content
The ai command is the primary entry point for Andi AIRun. It supports multiple AI runtimes (Claude Code, Codex CLI), runs AI prompts as scripts, provides executable markdown with shebang support, and enables cross-cloud provider switching.

Syntax

Usage Modes

Interactive Mode

Run ai with no arguments to start an interactive session:
Interactive mode launches Claude Code with your selected provider and model configuration. The session is automatically restored to your original settings on exit.

Script File Mode

Execute a markdown file as a prompt:
Script files can contain a shebang line for direct execution:

Stdin Mode

Pipe content directly to ai:
By default, piped content is prepended to file content. Use --stdin-position append to place it after.

Common Options

These are the AI Runner-specific options. See individual reference pages for detailed documentation:

Provider Flags

Switch between Claude subscriptions and cloud providers

Model Flags

Select model tiers or specific model IDs

Permission Flags

Control file access and command execution permissions

Output Flags

Configure output format and streaming behavior

Flag Precedence

When the same configuration is specified in multiple places, AI Runner uses this precedence order (highest to lowest):
  1. CLI flags - ai --aws --opus file.md
  2. Shebang flags - #!/usr/bin/env -S ai --aws --opus
  3. Saved defaults - ai --aws --opus --set-default
  4. Auto-detection - Current Claude subscription
CLI flags always override shebang flags, which override saved defaults.

Real Examples

Basic Script Execution

Provider Switching

Unix Pipeline Automation

Agent Teams

Persistent Defaults

Script Variables

Declare variables with defaults in YAML front-matter:
Override from CLI (hyphens normalize to underscores):

Other Commands

command
Update AI Runner to the latest version:
Pulls the latest version from the configured GitHub repository and re-runs the setup script.
flag
Save current runtime+provider+model as persistent default:
flag
Remove saved defaults:
flag
Resume the most recent conversation:
Picks up your previous conversation exactly where you left off. Works across provider switches - useful when you hit rate limits.
flag
Enable agent teams (interactive mode only):
Enables Claude Code’s agent teams feature. Multiple AI agents collaborate on tasks with one lead coordinator.Short form: --teams
flag
Select the underlying AI runtime:
Auto-detects if not specified: tries Claude Code first, falls back to Codex.
flag
Shorthand for --tool codex (Codex CLI):
flag
Set reasoning effort level:
Works with both runtimes. See Tool Flags for the mapping table.
flag
Select a Codex CLI config profile (Codex only):
See Tool Flags for configuration details.
flag
Smart auto-approve (AI classifier for Claude Code, sandbox for Codex):
Short form for: Claude Code: --permission-mode auto, Codex: --full-auto
flag
Show version information:
flag
Show help message:

Session Behavior

AI Runner uses session-scoped configuration:
  • On exit, your original Claude settings are automatically restored
  • Plain claude in another terminal is completely unaffected
  • No global configuration is changed
  • Each invocation starts fresh (nested scripts don’t inherit parent env vars)

Passthrough Flags

Any flag not recognized by AI Runner is forwarded to the underlying runtime unchanged:

Exit Codes

ai exits with the same code as the underlying runtime. A non-zero exit means the runtime reported an error.

ai-status

Show current configuration

ai-sessions

List active sessions

ai update

Update to latest version