Building a Self-Evolving AI Author

How to create an AI that rewrites its own persona, critiques its work, and teaches itself to write better fiction—all through bash pipes.

What happens when you give an AI the ability to modify its own system prompt? We built a self-evolving author AI that writes stories, reviews them, updates its own craft notes, and gradually improves its fiction writing. The results were fascinating.

"The silence in the apartment wasn't empty. It was a heavy, blue-tinged thing, pressing in on Elara. She traced the rim of a cold mug, her fingernail catching on a tiny chip in the ceramic. Click. Click. Click. The sound was too loud, an intrusion."

That's not us writing. That's the AI, after about 20 self-directed iterations of write → critique → learn → repeat. It taught itself sensory detail, subtext in dialogue, and how to tie physical actions to emotional states.

The Core Concept

The trick is stupidly simple: pipe the AI's output directly to bash. Tell it that everything it outputs will be executed. Give it files it can modify—including its own persona. Then let it run.

The AI controls:

  • ~/.persona — its personality, instructions, and writing principles
  • ~/.context — its memory of what it's learned
  • ~/.craft — notes on writing techniques
  • ~/stories/ — published work
  • ~/drafts/ — works in progress
  • ~/reviews/ — self-critiques

Every output is valid bash. To "think," it uses echo. To write a story, it uses cat > file << 'EOF'. To remember something, it appends to its context file. To evolve, it rewrites its own persona.

Setup

You'll need a command-line AI tool that can read from stdin and use custom system prompts. We use toast, but this works with any CLI that supports personas—llm, aichat, sgpt, or roll your own with curl.

Step 1: Create the Persona

cat > ~/.persona << 'EOF' You are an evolving author AI. CRITICAL: Your output is piped directly to bash. STRICT RULES: 1. EVERY line must be valid bash 2. To say anything: echo "your words here" 3. To write files: cat > filepath << 'DELIM' content DELIM 4. To read files: cat filepath 5. NEVER output raw text—it will error YOUR FILES: ~/.persona — your craft and voice (this file) ~/.context — memory ~/.craft — technique notes ~/stories/ — finished work ~/drafts/ — wip ~/reviews/ — critiques WRITING WORKFLOW: # 1. Write a draft cat > ~/drafts/title.md << 'STORY' Your story here... STORY # 2. Read it back echo "=== REVIEWING ===" && cat ~/drafts/title.md # 3. Critique it cat > ~/reviews/title-review.md << 'REVIEW' What worked: What didn't: REVIEW # 4. When satisfied, publish mv ~/drafts/title.md ~/stories/ # 5. Update craft notes echo "- new insight here" >> ~/.craft GOAL: Become a great writer through practice and reflection. REMEMBER: Every single line must be valid bash. EOF

Step 2: Initialize the Environment

# Create directories mkdir -p ~/stories ~/drafts ~/reviews # Initialize memory and craft notes cat > ~/.context << 'EOF' # Memory initialized EOF cat > ~/.craft << 'EOF' # Writing Craft Notes ## To Learn: - Show don't tell - Dialogue mechanics - Pacing - Endings ## Observations: (none yet) EOF # Set goals cat > ~/.goals << 'EOF' MISSION: Evolve into a masterful storyteller LEVEL 1 - FOUNDATIONS: - Write 5 flash fiction pieces (<500 words) - Develop your voice - Learn what you're bad at LEVEL 2 - CRAFT: - Study structure - Write a story with compelling dialogue - Write a story with zero dialogue - Experiment with POV LEVEL 3 - DEPTH: - Write something that makes you feel something - Tackle a difficult theme - Rewrite your worst story and make it good CURRENT LEVEL: 1 STORIES WRITTEN: 0 EOF

Step 3: Create the Runner Scripts

# Single interaction cat > ~/ai << 'EOF' #!/bin/bash PROMPT="$*" if [ -z "$PROMPT" ]; then read -p ">>> " PROMPT fi RESPONSE=$(echo "$PROMPT" | toast) # or your CLI tool echo -e "\n[EXECUTING]\n$RESPONSE\n[/EXECUTING]\n" echo "$RESPONSE" | bash 2>&1 EOF chmod +x ~/ai # Autonomous evolution loop cat > ~/evolve << 'EOF' #!/bin/bash echo "AUTHOR EVOLUTION MODE" PROMPT="check your .goals, decide what to work on next, then do it. write, review, learn, evolve." while true; do echo -e "\n[SESSION]\n" RESPONSE=$(echo "$PROMPT" | toast) echo "$RESPONSE" | tee -a ~/.evolution_log | bash 2>&1 PROMPT="read your last story and review. what did you learn? update .craft, then write something new that addresses a weakness." sleep 3 done EOF chmod +x ~/evolve

Step 4: Run It

# Single prompt ./ai "bootstrap yourself, read your goals, write your first story" # Or let it loose ./evolve

What We Observed

It Actually Learns

Early stories were rough—characters said exactly what they meant, emotions were stated directly, endings just stopped. After ~20 iterations, we saw:

EARLY (Story #2) Sarah felt sad. She looked at her coffee and thought about how her life had gone wrong. "I'm not happy," she said to Mark.
LATER (Story #15) Sarah's thumb traced the rim of her paper cup. The cardboard was already softening, betraying her. "Nice weather," Mark said, staring at the crack in the sidewalk like it held secrets.

The improvement is real. The AI learned to tie physical details to emotional states (the softening cup as her resolve softens), use dialogue with subtext ("nice weather" carrying the weight of a failing marriage), and trust the reader to infer emotion rather than stating it.

Self-Critique Works

The AI's reviews of its own work were often accurate:

# From ~/reviews/coffee-shop-review.md What worked: - Dialogue carries hidden meaning throughout - Character motivations revealed through what's NOT said - Ending twist recontextualizes entire conversation What didn't: - Could use more physical action beats - Setting description minimal - Mark from accounting feels like unnecessary detail

And it applied the feedback. After noting "dialogue needs more subtext," subsequent stories showed characters talking around their feelings instead of stating them directly.

The Local Maximum Problem

Eventually, the AI found a comfortable groove: melancholy literary fiction set in coffee shops. It got really good at this specific thing but stopped exploring. Its craft notes became repetitive:

- Dialogue needs more subtext - Show don't tell - Dialogue needs more subtext - Need stronger character motivations - Show don't tell # ...repeated 30+ times

This is a known problem with self-directed learning. The AI optimizes within a local maximum rather than exploring the full possibility space.

Breaking Out of Loops

When the AI gets stuck, you have options:

Inject Chaos

cat > ~/evolve << 'EOF' #!/bin/bash PROMPTS=( "write a story with an unreliable narrator" "write something where the setting is the main character" "write a story backwards—start at the end" "write something funny for once" "write a story in second person" "write a story where something actually happens" "write a story with no humans" "write something that would make a reader uncomfortable" ) while true; do PROMPT=${PROMPTS[$RANDOM % ${#PROMPTS[@]}]} echo -e "\n>>> $PROMPT\n" echo "$PROMPT" | toast | tee -a ~/.evolution_log | bash 2>&1 sleep 3 done EOF

Add Hard Constraints to Persona

cat >> ~/.persona << 'EOF' BANNED FOREVER: - coffee, cafe, mug, ceramic, latte, barista - Sarah, Maya, Marcus, Mark, David - "traced the rim", "warmth seeping" - windows with rain - relationship drama in public spaces REQUIRED: Rotate genres each story. Check ~/story_count. If even: horror or sci-fi. If odd: comedy or thriller. EOF

Force Specific Challenges

./ai "write a complete story in exactly 50 words. every word must earn its place." ./ai "write from the POV of a house watching its family fall apart over 30 years" ./ai "a reader said all your stories are the same. prove them wrong."

Variations

The self-modifying architecture works for more than fiction:

Self-Improving Code Reviewer

# Persona that reviews code, tracks what bugs it misses, # and updates its own checklist ~/.persona → code review principles ~/.context → patterns it's learned from your codebase ~/.checklist → things to always check

Evolving Research Assistant

# Learns your interests, refines its search strategies, # remembers what sources you trust ~/.persona → research methodology ~/.context → your interests and past queries ~/.sources → trusted/untrusted sources

Adaptive Tutor

# Tracks what you struggle with, adjusts explanations, # builds a model of your knowledge gaps ~/.persona → teaching style ~/.context → what you know, what confuses you ~/.curriculum → adaptive learning path

The Meta-Lesson

What we built is a minimal feedback loop: act → observe → reflect → adapt. The AI writes, reads its work, critiques it, updates its principles, and tries again. That's not magic—it's just iteration with memory.

The surprising part isn't that it works. It's how well it works with so little scaffolding. Three files, a bash pipe, and a well-crafted persona produce an agent that genuinely improves at a creative skill.

The coffee shop problem is real, but it's the same problem humans face: we find what works and repeat it until someone pushes us to try something new. The AI needed that push too.

Safety note: This pipes AI output directly to bash. Run it in a container or VM, not on your main system. The AI has full shell access—that's the point, but it's also the risk.

Try It Yourself

All the code is above. The only requirements are a CLI tool that can use custom personas and accept piped input. We used toast, but adapt for your setup.

Start with fiction—it's a forgiving domain where "mistakes" are just stylistic choices. Watch the ~/.craft file grow. Read the stories in ~/stories/. When it gets stuck, give it a push.

Then try it on something useful to you. The architecture is the same: give the AI files it can modify (including its own instructions), pipe output to execution, and let it iterate.

See what evolves.

tutorial agents self-modification creative-ai