bonsai
Bonsai is a tool for creating interactive fiction through a mix of manual authoring and AI-assisted generation.
Author your story
Write directly in the script editor using markup, or playtest and click on any text to edit it permanently.
Play to explore
Navigate your story as a player. Your input will match defined choices, or the AI will generate new branches. Other players can explore too!
Prune your branches
Review AI-generated changes, edit them, then approve or discard. Only the latest unresolved branch can be discarded, so work through them in order.
Check the guidebook
The guidebook automatically learns your preferences from edits. Check it occasionally to ensure it's on track, or edit it directly.
Scenes are marked with @. They define locations or states in your story. Add [allows: new|link|text] to control AI generation.
@HOME You're in a cozy room. @GARDEN [allows: new] The flowers sway gently. (AI can create new scenes from here) @HUB [allows: text] What do you want to do? (AI can only add flavor text, no scene changes)
new = AI can create scenes (default), link = only existing scenes, text = flavor only
Use if to define player choices. Separate synonyms with |.
if go outside | leave | exit
You step out into the garden.
goto @GARDENgoto @SCENE moves the player to another scene.
if open the door
The door creaks open.
goto @HALLWAYVariables are counters. Use +var to increment (add 1), -var to decrement (subtract 1). Use & ?var after a choice to require it.
if buy sword
-gold
+sword
You got a sword!
if buy another sword
-gold
+sword
Now you have two swords!
if attack & ?sword
You swing your blade.Display: sword (count=1), sword (2) (count=2), etc.
Use when var (true if ≥1), when !var (true if 0), or when var >= N for threshold checks.
@SHOP
when gold >= 10
You can afford the sword!
when !gold
Your pockets are empty.
@BATTLE
when sword >= 2
You dual-wield your blades!
when sword
You swing your sword.
when !sword
You fight with your fists.A turn variable auto-increments on each player input. Add global conditions before any scene to create time limits or pacing.
when turn >= 10
Time is running out...
when turn >= 20
goto @GAME_OVER
@START
You begin your adventure.
if explore
goto @FOREST
@GAME_OVER
Your time has run out.
goto @ENDAdd images with [image: url].
@GARDEN [image: https://example.com/garden.png] The garden is beautiful.
Use tabs to nest content under choices and conditions. Everything indented under an if or when belongs to that block.
when !key
Oh lookee, there's a key!
if take it | yes
+key
Yoink!
if leave it | no
You step back.@END as a special scene to end the story.when turn >= N in the global preamble for time limits or pacing events.+var for inventory, XP, or resource systems.[allows: text] on hub scenes to force explicit branches, letting AI extend within paths.