A Swift CLI tool that sends prompts to Apple Intelligence Foundation Models. Reads input from files, inline prompt text, or stdin, optionally with system instructions, and prints the model's response.
- macOS 26+ (Tahoe)
- Apple Silicon Mac (M1 or later)
- Apple Intelligence enabled in System Settings
- Swift 6.0+
Build from source using Swift Package Manager:
git clone https://github.com/kristopherjohnson/aigen.git
cd aigen
swift build -c release
cp .build/release/aigen /usr/local/bin/ # may need 'sudo'USAGE: aigen [options] [file ...]
ARGUMENTS:
file Input files to read (use '-' to read stdin; reads stdin if no arguments)
OPTIONS:
-i, --instruction TEXT Set system instructions for model (can be repeated)
-p, --prompt TEXT Add inline text to prompt (can be repeated)
-t, --temperature VALUE Set sampling temperature 0.0-1.0 (default: system default)
--no-stream Disable streaming; wait for complete response
-v, --verbose Show processing details
-h, --help Show help information
Single file:
aigen prompt.txtMultiple files (concatenated):
aigen system.txt context.txt question.txtFrom stdin:
echo "What is 2+2?" | aigenPipeline usage:
cat document.md | aigen > summary.txtInline prompt text:
aigen -p "What is the capital of France?"Mix prompt text with files:
aigen -p "Summarize this document:" report.txtMultiple prompt texts:
aigen -p "You are a helpful assistant." -p "What is 2+2?"System instructions:
aigen -i "Be concise" -p "What is 2+2?"Multiple instructions (concatenated):
aigen -i "You are a helpful assistant." -i "Use bullet points." document.txtInstructions with prompts and files:
aigen -i "Summarize in 5 sentences" -p "Key points:" report.txtVerbose output:
aigen -v prompt.txtNon-streaming mode:
aigen --no-stream -p "What is 2+2?"Custom temperature:
# Lower temperature (0.0-0.3) for more focused, deterministic responses
aigen -t 0.2 -p "What is the capital of France?"
# Higher temperature (0.7-1.0) for more creative, varied responses
aigen -t 0.8 -p "Write a creative story opening"
# Mid-range temperature (0.4-0.6) for balanced responses
aigen -t 0.5 -p "Explain quantum computing"Explicit stdin with - (Unix convention):
# Append stdin after prompt text
man otool | aigen -p "Summarize this for me:" -
# Mix stdin with files in specific order
aigen -p "Context:" intro.txt - question.txt
# Use stdin at beginning
echo "test input" | aigen - -p "Is this correct?"- Reads input from inline prompt texts (
-p), files, or stdin - Optionally sets system instructions (
-i) for the model - Concatenates prompt texts and file contents with newlines
- Sends the combined prompt to Apple's on-device Foundation Model with instructions
- Streams the model's response to stdout in real-time as it's generated (or waits for complete response with
--no-stream)
Notes:
- When using both
-pand file arguments, all prompt texts are concatenated first, followed by all file contents - Use
-as a file argument to read stdin at a specific position in the input sequence - If
-appears multiple times, stdin is only read once (subsequent-are ignored) - Multiple instructions are concatenated with newlines and passed to the LanguageModelSession
- By default, output is streamed incrementally so you see the response as it's being generated
- Use
--no-streamto wait for the complete response before printing (non-streaming mode)
The tool provides clear error messages for common issues:
- File not found
- File read permission errors
- Apple Intelligence not enabled
- Device not eligible for Apple Intelligence
- Model not ready
Exit codes:
0- Success1- Validation or runtime error
Run tests:
swift testBuild for debugging:
swift buildRun directly:
swift run aigen prompt.txtMIT License - see LICENSE file for details.