---
title: "Prompt Runner"
---

# 06 — The Prompt Runner

## What We're Building

The prompt runner is the simplest tool in our toolkit: take a `prompt.txt` from a directory, feed it to Ollama, save the output.

But even this simple tool introduces an important pattern: **each prompt lives in its own directory** with everything it produces. This keeps your work organized and reproducible.

## The Script

This is the `run_prompt.sh` generated by our one-shot prompt (plan1.md). Copy and save it:

```bash
#!/bin/bash

# Prompt Runner — feeds prompt.txt to Ollama and saves output

# Check for directory argument
if [ -z "$1" ]; then
    echo "Usage: $0 <directory>"
    echo "Example: $0 ./my-prompt"
    exit 1
fi

DIR="$1"
PROMPT_FILE="$DIR/prompt.txt"
OUTPUT_FILE="$DIR/output.txt"
MODEL="gemma4:26b"

# Check that prompt.txt exists
if [ ! -f "$PROMPT_FILE" ]; then
    echo "Error: $PROMPT_FILE not found."
    echo "Create a prompt.txt file in $DIR"
    exit 1
fi

# Run the prompt through Ollama and save output
echo "Running prompt in $DIR using $MODEL..."
cat "$PROMPT_FILE" | ollama run "$MODEL" --nowordwrap > "$OUTPUT_FILE"
echo "Done! Output saved to $OUTPUT_FILE"
```

## Setup

```bash
# Save the script
nano run_prompt.sh
# (paste the code above, save and exit)

# Make it executable
chmod +x run_prompt.sh
```

## Usage

Create a directory with a `prompt.txt` file:

```bash
mkdir -p my-first-prompt
echo "Write a haiku about programming" > my-first-prompt/prompt.txt
```

Run it:

```bash
./run_prompt.sh my-first-prompt
```

Output:

```
Running prompt in my-first-prompt using gemma4:26b...
Done! Output saved to my-first-prompt/output.txt
```

Check what the model wrote:

```bash
cat my-first-prompt/output.txt
```

## Key Design Decisions

Why this approach?

1. **Bash, not Python** — zero dependencies. Works on any Mac out of the box.
2. **One directory per prompt** — keeps inputs and outputs together
3. **Overwrite, don't version** — (simple! YAGNI!) — we want the latest output, not a collection of old ones
4. **Error handling** — checks that the directory and prompt file exist before running

## The `--nowordwrap` Flag

You'll notice `ollama run model --nowordwrap`. Without this flag, Ollama may wrap the model's output at a fixed width, which can break code formatting. The `--nowordwrap` flag preserves the model's original formatting.

## What You've Learned

- A simple bash script can run prompts through Ollama
- Keeping each prompt in its own directory organizes your work
- Error handling prevents confusing failures
- `--nowordwrap` preserves code formatting

**Next: [07 — Self-Improving →](/run-ai-locally/03-automation/07-self-improving/)**
