Text Genie - Claude Code Instructions
Guides an AI assistant to generate MUD worlds by calling a single Docker-based Evennia function, with no intermediate scripts.
What this file does
Guides an AI assistant to generate MUD worlds by calling a single Docker-based Evennia function, with no intermediate scripts.
When to use it
- You want an AI to build Evennia worlds directly without manual file creation
- You run Evennia inside Docker and need a repeatable world generation workflow
- You need to fix persistent admin character connection issues in Evennia
- You want a checklist of common Evennia pitfalls and their solutions
Assumes this stack
Text Genie - Claude Code Instructions
π¨ CRITICAL: ALWAYS USE DOCKER π¨
Text Genie runs in Docker container textgenie-evennia
- NEVER use local
evenniacommands - NEVER use
source venv/bin/activate - ALWAYS use
docker exec textgenie-evenniafor all Evennia operations - The container name is:
textgenie-evennia
π« NEVER CREATE NEW PYTHON FILES π«
CRITICAL: DO NOT create new Python files for world generation!
- NEVER create files like
create_[theme]_world.py - NEVER create files like
build_[worldname].py - ALWAYS use python -c "..." to call create_world() directly
- The ONLY script you need is
scripts/world_builder.py
Quick Start
Text Genie is a MUD world generator that uses Evennia running in Docker.
When the user asks you to create a world (ANY theme - be creative!):
- Generate complete world data dictionary with rooms, NPCs, items, connections
- DIRECTLY call the world builder function - NO EXTRA SCRIPTS NEEDED:
# Just do this directly in your response: from scripts.world_builder import create_world world_data = { "name": "World Name", "theme": "theme_type", "rooms": [...], "connections": [...], "npcs": [...], "items": [...] } create_world("World Name", "theme_type", world_data) - The script automatically handles EVERYTHING:
- Saves to
created_worlds/[theme]_[timestamp].py - Creates
created_worlds/build_current.py - Copies to Docker and builds the world
- Creates admin character if it doesn't exist
- Sets admin location to first room
- Configures puppet connection
- Saves to
- Tell user: Connect via
telnet localhost 4000(admin/admin)
Project Structure
TextGenie/
βββ created_worlds/ # All generated worlds (gitignored)
β βββ [theme]_[timestamp].py # World data files
β βββ build_current.py # Current build script
β βββ fix_admin.py # Admin location fixer
βββ scripts/
β βββ world_builder.py # Main world creation script (THE ONLY ONE!)
βββ textgenie_game/ # Evennia game directory (gitignored)
βββ Dockerfile # Docker setup for Evennia
Prerequisites
- Docker installed and running
- Container running:
docker ps | grep textgenie-evennia - If not running:
docker-compose up -dordocker run -d -p 4000-4002:4000-4002 --name textgenie-evennia textgenie-evennia
World Generation Process
β‘ FAST World Creation (< 30 seconds)
When user requests ANY world:
- Generate world data (be creative!):
world_data = {
"name": "World Name",
"theme": "theme_type",
"rooms": [
{
"name": "Room Name",
"description": "Vivid 2-3 sentence description with sensory details."
},
# Generate 5-10 rooms minimum
],
"connections": [
{
"from": "Room 1",
"to": "Room 2",
"direction": "north",
"reverse": "south"
},
# Connect all rooms logically
],
"npcs": [
{
"name": "NPC Name",
"description": "Physical description and personality hints.",
"location": "Room Name",
"dialogue": {
"greeting": "What the NPC says when first met",
"quest": "Optional quest or hint"
}
},
# Generate 3-5 NPCs minimum
],
"items": [
{
"name": "item name",
"description": "What it looks like and any special properties.",
"location": "Room Name"
},
# Generate 5-10 items minimum
]
}
- Call create_world() DIRECTLY using python -c - NO intermediate scripts:
python -c "
from scripts.world_builder import create_world
world_data = {...} # Your generated world data here
create_world(world_data['name'], world_data['theme'], world_data)
"
NEVER create a new .py file to do this!
That's it! The script automatically:
- Copies to Docker
- Builds the world
- Creates/fixes admin character
- Sets proper locations
- NO MANUAL STEPS NEEDED!
Step 3: Connect
- Telnet:
telnet localhost 4000 - Web:
http://localhost:4001 - Login: admin/admin
Content Generation Guidelines
Rooms
- Minimum: 5 rooms for small world, 10+ for standard
- Description: 2-3 sentences with sensory details (sight, sound, smell)
- Connectivity: Every room needs at least 1 exit
- Mention exits: Naturally reference connecting areas in descriptions
NPCs
- Minimum: 3-5 NPCs
- Placement: Distribute across different rooms
- Description: Visual appearance + personality hints
- Dialogue: At least greeting, optionally quest/hints
Items
- Minimum: 5-10 items
- Types: Mix functional and atmospheric items
- Distribution: Scatter throughout world
Connections
- Directions: north, south, east, west, up, down, in, out
- Bidirectional: Always create reverse exits
- Logical: Connections should make spatial sense
World Themes - Quick Templates
Cyberpunk
- Neon-lit streets, rain, corporate towers
- NPCs: Hackers, corporate agents, street vendors
- Items: Credsticks, neural implants, encrypted datapads
Fantasy
- Medieval villages, dark forests, ancient ruins
- NPCs: Wizards, merchants, guards, mysterious strangers
- Items: Potions, scrolls, weapons, treasure
Space Station
- Observation decks, engineering, quarters, docking bays
- NPCs: Engineers, traders, pilots, security
- Items: Keycards, tools, cargo manifests, personal effects
Horror
- Abandoned locations, darkness, unsettling atmosphere
- NPCs: Survivors, mysterious figures, helpful/unhelpful locals
- Items: Flashlights, notes/journals, keys, strange artifacts
Docker Commands (USE THESE!)
# Check if container is running
docker ps | grep textgenie-evennia
# Start container if not running
docker start textgenie-evennia
# Restart Evennia inside Docker
docker exec textgenie-evennia evennia restart
# Check Evennia status
docker exec textgenie-evennia evennia status
# View logs
docker logs textgenie-evennia --tail 50
# Shell into container
docker exec -it textgenie-evennia bash
π¨π¨π¨ CRITICAL: AFTER CREATING A WORLD, ALWAYS RESTART EVENNIA! π¨π¨π¨
docker exec textgenie-evennia evennia restart
WHY: Evennia caches object properties like has_account. Even if you set everything correctly, the cached values won't update until Evennia restarts. This WILL cause "Character does not exist" errors if you don't restart!
Troubleshooting - CRITICAL FIXES THAT MUST ALWAYS BE APPLIED
π΄ FIX #1: Foreign Key Constraint Errors (PERMANENT FIX IN PLACE)
Problem: Django crashes with "FOREIGN KEY constraint failed" when admin tries to connect.
Root Cause: Puppet references weren't properly cleared before deleting rooms.
THE FIX (Now in world_builder.py):
# Step 1: Clear ALL puppet/character references FIRST
for acc in AccountDB.objects.all():
acc.db._last_puppet = None
acc.db._default_character = None
acc.save()
# Step 2: Move characters to Limbo BEFORE deleting anything
# Step 3: Delete exits first (they reference rooms)
# Step 4: Delete other objects (items, rooms)
# Step 5: Finally delete non-admin characters
π΄ FIX #2: "Character does not exist" Error (COMPLETE SOLUTION)
Problem: Admin connects but gets "This character does not exist" error.
Root Causes (ALL must be fixed):
- The
_last_puppetattribute is None - The character's
db_accountfield is None (character doesn't know its account!) - CRITICAL: Evennia's
has_accountproperty gets cached and stuck at 0 even after fixing the above!
THE COMPLETE FIX (Now in world_builder.py + restart):
- Link character to account (use ObjectDB directly for reliability):
# Use ObjectDB.objects.get() to ensure we have the real database object
char_obj = ObjectDB.objects.get(id=admin_char.id)
char_obj.db_account = admin # THIS IS THE KEY LINE!
char_obj.save()
- Set puppet references on account:
admin.db._last_puppet = char_obj # Use the reloaded object
admin.db._default_character = char_obj
admin.save()
- Verify with direct database check:
# Don't trust cached properties - check the actual database
test_char = ObjectDB.objects.get(id=admin_char.id)
if test_char.db_account != admin:
# Force it with raw SQL if needed
from django.db import connection
with connection.cursor() as cursor:
cursor.execute(
"UPDATE objects_objectdb SET db_account_id = %s WHERE id = %s",
[admin.id, admin_char.id]
)
- RESTART EVENNIA TO CLEAR CACHES:
docker exec textgenie-evennia evennia restart
π THE COMPLETE WORLD CREATION CHECKLIST:
- Clear ALL references BEFORE deleting ANYTHING (avoid foreign key errors)
- Use db_typeclass_path NOT db_is_typeclass (field name is critical)
- Create/find admin character
- Link character to account with ObjectDB.objects.get() (don't trust the character object)
- Set character location to first room
- Set BOTH _last_puppet AND _default_character
- Verify with database query, not object properties
- ALWAYS RESTART EVENNIA AFTER WORLD CREATION
β οΈ Common Pitfalls That WILL Break Everything:
- Using
char.db_accountwithout reloading: The object might be cached - Trusting
has_accountproperty: It gets cached and stuck at 0 - Not using ObjectDB.objects.get(): Working with stale objects
- Forgetting to restart Evennia: Caches WILL cause login failures
- Using wrong field names: It's
db_typeclass_pathnotdb_is_typeclass
π§ EMERGENCY Manual Fix Commands:
# COMPLETE fix for admin connection issues
docker exec -i textgenie-evennia sh -c 'cd /app/textgenie_game && echo "
from evennia.accounts.models import AccountDB
from evennia.objects.models import ObjectDB
admin = AccountDB.objects.filter(username=\"admin\").first()
if admin:
# Get or create character
chars = list(admin.characters.all())
if not chars:
from typeclasses.characters import Character
char = Character.create(\"admin\", admin)[0]
chars = [char]
# Use ObjectDB directly - NEVER trust the character object
char_obj = ObjectDB.objects.get(id=chars[0].id)
# Fix the bi-directional link
char_obj.db_account = admin
char_obj.save()
# Set puppet references
admin.db._last_puppet = char_obj
admin.db._default_character = char_obj
admin.save()
# Verify it worked
test = ObjectDB.objects.get(id=char_obj.id)
print(f\"Fixed: Character {test} linked to {test.db_account}\")
print(f\"Admin puppet: {admin.db._last_puppet}\")
# If still broken, force with SQL
if test.db_account != admin:
from django.db import connection
with connection.cursor() as cursor:
cursor.execute(
\"UPDATE objects_objectdb SET db_account_id = %s WHERE id = %s\",
[admin.id, char_obj.id]
)
print(\"Forced fix via SQL\")
" | evennia shell'
# THEN ALWAYS RESTART
docker exec textgenie-evennia evennia restart
π Debug Commands:
# Check admin setup
docker exec -i textgenie-evennia sh -c 'cd /app/textgenie_game && echo "
from evennia.accounts.models import AccountDB
from evennia.objects.models import ObjectDB
admin = AccountDB.objects.filter(username=\"admin\").first()
if admin:
puppet = admin.db._last_puppet
if puppet:
char_obj = ObjectDB.objects.get(id=puppet.id)
print(f\"Admin: {admin}\")
print(f\"Puppet: {puppet}\")
print(f\"Character account: {char_obj.db_account}\")
print(f\"Match: {char_obj.db_account == admin}\")
print(f\"Has account property: {puppet.has_account}\") # This lies if cached!
" | evennia shell'
Other Issues
- Connection refused: Check Docker container is running:
docker ps | grep textgenie-evennia - Old world showing: Just run create_world() again - it clears old world first
- NEVER use local evennia: ALWAYS use
docker exec textgenie-evennia
β‘ Quick Generation Workflow (WITH RESTART!)
When user says "Create a [theme] world" or provides an image/weird request:
- Check Docker is running:
docker ps | grep textgenie-evennia - Generate world data dictionary directly in your response
- Call create_world() DIRECTLY using python -c - NO NEW FILES:
DO NOT create a new Python file! Use python -c directly!python -c " from scripts.world_builder import create_world world_data = { 'name': 'Cool World', 'theme': 'whatever', 'rooms': [...], 'connections': [...], 'npcs': [...], 'items': [...] } create_world(world_data['name'], world_data['theme'], world_data) " - CRITICAL: RESTART EVENNIA TO CLEAR CACHES:
docker exec textgenie-evennia evennia restart - Tell user: "World created! Connect:
telnet localhost 4000(admin/admin)"
CRITICAL REMINDERS:
- NEVER create separate build scripts (like build_terminus.py, create_synth_world.py, etc.)
- NEVER create ANY new Python files for world generation
- NEVER manually copy files or run Docker commands
- ALWAYS call create_world() directly using python -c "..."
- ALWAYS use single quotes inside the python -c command to avoid quote conflicts
- The function handles EVERYTHING automatically including admin setup
Remember
- π³ ALWAYS USE DOCKER - Container name:
textgenie-evennia - Generate first, ask questions later
- Minimum 5 rooms, prefer 8-10 for better experience
- Every room needs exits (bidirectional!)
- Include NPCs and items for atmosphere
- Admin must have location (use fix_admin.py if needed)
- Be creative with odd requests (images, weird themes, etc.)
What's inside
8 sections covering Docker usage, world data format, generation workflow, troubleshooting, and debug commands
Change this for your project
- Replace
textgenie-evenniawith your own Docker container name - Replace
scripts/world_builder.pywith your own builder script path - Replace
adminwith your own admin account username - Replace
telnet localhost 4000with your own connection details
Where it goes
Save as CLAUDE.md in your repository root. Claude Code reads it automatically at the start of every session.
Worth borrowing
- Using
python -cto execute code inline instead of creating temporary files - Clearing cached object references before deleting database records to avoid foreign key errors
- Verifying database state with raw queries instead of trusting cached properties
Related Documents
Code indexing for AI agents: summarization strategies and evaluation systems
Synthesises 2024-2025 research on code indexing for AI agents, covering summarisation strategies, hybrid retrieval architectures, and evaluation benchmarks.
write-script
Guides an AI through writing a YouTube video script with strict structural, language, and quiz rules for a survival channel.
Claude AI Git Workflow Integration
Recommends using the git-ai-commit CLI tool for AI-generated commit messages instead of manual ones.
Missing Business Agents Research β FLUXION 2026
Identifies 12 missing business operations agents for an indie software company and ranks them by impact and effort with β¬0 implementation plans.