Build an Interactive Fiction Tool with Claude Code and Crazyrouter
Building an Interactive Fiction Tool with Claude Code and Crazyrouter
Interactive fiction is a strong practical example for LLM application design. It is small enough to prototype quickly, but complex enough to expose real product problems: state management, branching, context drift, editing, retries, and user control.
The basic workflow is simple. A writer enters a title and a short opening. The app sends that context to a model through Crazyrouter and asks for several possible next branches. The writer chooses one branch, and the app expands it into a full scene. The selected scene becomes part of the active story path, and the process repeats.
The important design choice is to keep the story state in the application, not only in the prompt. Each story node should have an id, parent id, summary, full text, selected branch, timestamp, and model metadata. That gives the app a reliable timeline or tree view, and it lets the writer resume, edit, or regenerate specific parts of the story.
Claude Code is useful because this is not just a single API call. It can help implement the data model, API wrapper, UI states, local persistence, and error handling across multiple files. A structured prompt works better than a vague request: describe the screens, the branch behavior, the model calls, and how generated text should be edited before the next continuation.
Crazyrouter endpoint configuration also matters. Claude Code and Anthropic-native clients should use https://cn.crazyrouter.com. OpenAI-compatible SDKs and regular HTTP applications should use https://cn.crazyrouter.com/v1. Keeping those separate avoids the common /v1/v1/... mistake.
A first version can store stories and settings locally. A production version should move API key handling to a backend, add rate limits, and preserve model metadata for debugging. Streaming output is useful, but the UI should handle cancellation and partial results cleanly.
The full series repository is here: claude-code-guide.














