How Shebang Scripts Work
A shebang (#!) at the start of a file tells the operating system which interpreter to use. AIRun uses #!/usr/bin/env ai to run markdown files as AI prompts:
ai task.md.
The -S Flag Requirement
Standard env only accepts one argument. If you want to pass flags to ai in your shebang, you must use env -S to split the string into multiple arguments:
Shebang Examples from the Repository
Basic Hello World
Fromexamples/hello.md:
--haiku flag selects a fast, cost-effective model for simple tasks.
Code Analysis
Fromexamples/analyze-code.md:
--sonnet: Balanced model for code analysis--skip: Shortcut for--dangerously-skip-permissions— allows the AI to read files without prompting
Live Streaming Report
Fromexamples/live-report.md:
--live flag streams output in real-time as the AI works, showing progress incrementally.
Test Automation
Fromexamples/run-tests.md:
Stdin Processing
Fromexamples/analyze-stdin.md:
Script with Variables
Fromexamples/summarize-topic.md:
Permission Modes for Automation
Read-only scripts (default) can analyze code but won’t modify anything:Flag Precedence
When you run a script, flags are resolved in this order (highest priority first):
Example precedence in action:
Given a script with this shebang:
ai --vertex --set-default:
CLI flags always override shebang flags, and shebang flags always override saved defaults. This lets you keep scripts with sensible defaults while overriding them when needed.
Passthrough Flags
AIRun handles its own flags (--aws, --opus, --live, --skip, etc.) and passes unrecognized flags directly to Claude Code:
--skip: AIRun flag (permission mode)--chrome: Claude Code flag (browser automation)--max-turns 10: Claude Code flag (limit iterations)
Running Scripts
There are three ways to run executable markdown:- Direct Execution
- Via ai Command
- Piped Execution
Combining with Other Features
Shebang scripts work seamlessly with other AIRun features: Provider switching:Unix Pipes
Chain scripts together and process data streams
Provider Switching
Switch between cloud providers and models