Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

promptplay

Transform natural language prompts into playable games using Claude

License: MIT Python 3.10+ PRs Welcome

What is promptplay?

promptplay is a creative playground that leverages the Claude Agent SDK to turn natural language descriptions into fully functional games. Describe the game you want to buildโ€”a Snake game, Flappy Bird, a puzzle gameโ€”and Claude will write the complete implementation for you.

How It Works

Web Interface (Recommended)

Your Game Idea
    โ†“
Web Form (index.html)
    โ†“
/generate endpoint (server.py)
    โ†“
Claude Agent SDK generates HTML/CSS/JS
    โ†“
Saved to output.html
    โ†“
Rendered in iframe on page ๐ŸŽฎ

CLI Mode

Edit agent.py with your game idea
    โ†“
python agent.py
    โ†“
Claude generates complete game code
    โ†“
Saved to output.html
    โ†“
Open in browser ๐ŸŽฎ

The agent automatically wraps your game idea with strict instructions to ensure Claude returns only clean HTML/CSS/JavaScript code without explanations or tool usage.

Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/sausi-7/promptplay.git
cd promptplay

# Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set up your API key
cp .env.example .env
# Edit .env and paste your ANTHROPIC_API_KEY

Running

Option 1: Web Server (Recommended)

Start the FastAPI server:

python server.py
# Server runs on http://localhost:8000

Open your browser and describe your game idea. The generated game will render instantly in the page.

Option 2a: Command Line - Quick Mode

Pass a game idea directly or use the default tic-tac-toe prompt:

python agent.py "A cozy memory card game with three difficulty levels" --output output.html
# Streams progress and generated code, then saves output.html
open output.html

Use --verbose to include detailed stream logs while Claude is generating.

Option 2b: Command Line - Conversational Mode (Recommended)

For better games with clarifications:

python conversation_agent.py
# Interactive mode:
# 1. Describe your game idea
# 2. Answer Claude's clarifying questions  
# 3. Get a tailored game
# 4. Request refinements if needed
# 5. Save with full conversation memory

Game Generation Modes

One-Shot Mode (agent.py)

  • โšก Fast: 5-10 seconds
  • ๐ŸŽฏ Simple: Just edit and run
  • ๐Ÿ“ก Streaming: Shows progress and generated code as it arrives
  • ๐Ÿ“ Use when: You have a clear idea and want it quickly
  • ๐Ÿ”„ Can't iterate: One generation per run

Conversational Mode (conversation_agent.py) โญ Recommended

  • ๐Ÿ’ฌ Interactive: Claude asks clarifying questions
  • ๐ŸŽฎ Better quality: Games tailored to your specs
  • ๐Ÿ”ง Refinable: Ask for changes, get improved versions
  • ๐Ÿ“š Memory: Full conversation saved as JSON
  • โฑ๏ธ Takes: 30-60 seconds + optional refinements

Example Conversational Flow:

You: "Make a puzzle game"
Claude: "What type of puzzle? (sliding, matching, word, logic?)"
You: "Matching cards with difficulty levels"
Claude: "Generated! Try it."
You: "Make it harder - fewer cards to match"
Claude: "Refined! Check it out."

Examples

Try these prompts by editing the game_idea string in agent.py (one-shot) or describing them to conversation_agent.py (conversational):

Prompt Output
"Build me a snake game in single index.html" Classic Snake with keyboard controls
"Create a Flappy Bird-style game" Bird dodging obstacles
"Build a memory matching card game" Click-to-flip matching game
"Make a simple Pong game" Two-player paddle game

Architecture

Key Components

  • agent.py - Core game generation using Claude Agent SDK

    • build_prompt() - Wraps user ideas with strict instructions to ensure HTML-only output
    • generate_game_html() - Calls Claude to generate complete game code
    • htmlParser() - Extracts clean HTML from Claude's response
  • server.py - FastAPI web server with two endpoints

    • POST /generate - Accepts a game idea, runs the agent, returns success/failure
    • GET /game - Serves the generated output.html file
    • GET / - Serves the web UI
  • index.html - Web interface for submitting game ideas

    • Form for entering game descriptions
    • Iframe rendering of generated games
    • Error handling and loading states

Customization

Change the Game Idea (CLI)

Edit the game_idea in agent.py:

game_idea = "Your detailed game description here"
html = await generate_game_html(game_idea)

Adjust the Model

Change the model parameter in agent.py:

model="claude-opus-4-8"      # For complex/3D games
model="claude-sonnet-4-6"    # Balanced performance
model="claude-haiku-4-5-20251001"  # Fast, lightweight

Modify Prompt Instructions

Edit build_prompt() in agent.py to customize how game ideas are converted to instructions.

Roadmap

  • Web UI to input prompts and play games directly
  • FastAPI server with endpoints for game generation
  • Iframe-based game rendering (no popup blockers)
  • Multi-file game support (separate HTML, CSS, JS)
  • Prompt gallery: community-submitted game ideas
  • CLI flags to customize model, effort, and output
  • Game examples directory with pre-generated games
  • Streaming output for real-time generation feedback
  • Game save/download functionality
  • Share generated games via URL

Contributing

We love contributions! Whether you're fixing bugs, adding features, or sharing cool game promptsโ€”all are welcome.

Getting Started

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-game-idea)
  3. Make your changes
  4. Commit with a clear message (git commit -m "Add support for X")
  5. Push to your fork and open a PR

See CONTRIBUTING.md for detailed guidelines.

Good First Issues

  • Add a new example prompt to the README
  • Create a prompt template for different game genres
  • Add error handling for API failures
  • Write tests for the agent module
  • Improve documentation

License

This project is licensed under the MIT Licenseโ€”see LICENSE for details.

Questions?

Open an issue on GitHub or reach out to @sausi-7.


Built with โค๏ธ and the Claude Agent SDK

About

Transform natural language prompts into playable games using Claude. Describe your game idea and get complete HTML/JS code instantly. Build, test, and share games in minutes. ๐ŸŽฎ

Topics

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages