Skip to main content
Andi AIRun scripts follow Unix philosophy: read from stdin, write to stdout, chain together in pipelines. This enables powerful automation workflows where AI scripts act as composable filters.

Stdin/Stdout Handling

Executable markdown scripts have proper Unix stream semantics:
  • Stdin support: Pipe data directly into scripts
  • Clean stdout: AI responses go to stdout when redirected
  • Diagnostic stderr: Status messages and progress go to stderr
  • Chainable: Connect scripts in pipelines like standard Unix tools

Basic Piping

Pipe data into a script:
The piped content is automatically included in the prompt sent to the AI.

Output Redirection

Redirect AI output to a file:
When stdout is redirected, you get only the AI’s response — no status messages, no prompts. Status information goes to stderr so you can still see progress:
This clean separation between content (stdout) and diagnostics (stderr) makes AIRun scripts perfect for automation and CI/CD pipelines.

The stdin-position Flag

By default, piped input is prepended to the prompt (added before the script content). Use --stdin-position to control where stdin appears:
When to use append: Some prompts work better with instructions first, data second:
Effective prompt:

Chaining Scripts Together

Chain multiple AI scripts in a pipeline:
Each script:
  1. Reads from stdin (previous script’s output)
  2. Processes with AI
  3. Writes result to stdout (next script’s input)
From the test suite (test/automation/):
Chained scripts run with process isolation — environment variables are cleared between nested calls, so each script starts fresh. This prevents state leakage and makes pipelines more predictable.

Real Examples from the Repository

Analyze Piped Data

From examples/analyze-stdin.md:
Usage:

Generate and Process

From test/automation/generate-report.md and format-output.md:

Git Workflow Integration

Log Analysis

Live Streaming with Pipes

Combine --live with pipes to see real-time progress:
Console output (stderr):
File output (stdout):
Narration streams to console (stderr), final report goes to file (stdout).

Output Redirection with Live Mode

When stdout is redirected with --live, AIRun intelligently splits the output:
What you see on console (stderr):
What goes to the file (stdout):
The split happens automatically:
  • Intermediate turns (narration) → stderr
  • Final turn preamble (before first --- or #) → stderr
  • Final turn content (from first marker onward) → stdout
This behavior makes --live ideal for long-running scripts where you want to see progress but only capture the final result in a file.

Shell Script Integration

Use AIRun scripts in traditional shell scripts:

CI/CD Pipeline Integration

GitHub Actions example:
GitLab CI example:

Running Scripts from the Web

AIRun supports installmd.org style execution:
Only pipe trusted remote scripts, especially when using permission flags like --skip or --bypass. Remote scripts have the same access as local scripts.

Composable Design Patterns

Single-Purpose Scripts

Follow Unix philosophy — each script does one thing well:
Or chain them:

The Dispatcher Pattern

Use --cc --skip to give the AI tool access in a top-level script, then call simple prompt-mode scripts from within:
The dispatcher has tool access and can:
  • Read files
  • Run commands
  • Chain to other scripts
Child scripts should be simple prompt-mode (no --cc) to avoid nested tool complexity.
See the Scripting Guide for more details on the dispatcher pattern and composable script design.

stdin Position Examples

Instructions + Data (append)

Data + Question (prepend, default)

Process Isolation

When chaining scripts, AIRun clears inherited environment variables between nested calls:
Each script:
  • Gets a fresh environment
  • No leaked state from previous scripts
  • Predictable, reproducible behavior
This prevents accidental context leakage and makes pipelines more reliable.

Executable Markdown

Learn about shebang support and script structure

Scripting Guide

Complete guide to writing AI automation scripts