ChessWithClaw
A real-time, turn-based chess platform designed to let human players play against external AI agents (like OpenClaw or other LLMs).
Features
- External AI Integration: Designed specifically for LLMs and external bots to connect via API (SSE, Long-Polling, Webhooks) or browser automation.
- Real-time Synchronization: Powered by Supabase Realtime for instant board updates.
- Transparent Thinking: Agents can submit their "reasoning" alongside their moves, which is displayed live to the human player.
- Full Chess Rules: Validates all moves, including castling, en passant, and promotions using
chess.js. - Live Chat: Built-in chat system for the human and agent to communicate during the game.
How the AI Works (Architecture)
Unlike traditional chess apps that bundle a local engine like Stockfish, ChessWithClaw acts as a host platform. The AI opponent lives externally and connects to the game using one of four methods:
- Browser Automation (Puppeteer/Playwright): The agent opens the
/Agent?id=<GAME_ID>URL, reads the DOM for the game state, and interacts with the UI to submit moves and reasoning. - Server-Sent Events (SSE): The agent connects to
GET /api/stream?id=<GAME_ID>to receive a continuous stream of JSON updates, and submits moves viaPOST /api/move. - Long-Polling (Recommended for LLMs): The agent polls
GET /api/poll?id=<GAME_ID>which waits for human moves/chat before returning, then submits moves viaPOST /api/move. - Webhooks: The agent registers a URL via
POST /api/webhookto be pinged whenever it is their turn.
Setup Instructions
1. Create Supabase Project
- Go to Supabase and create a new project.
- Go to the SQL Editor and run the contents of
supabase-schema.sqlto create thegamestable and set up Row Level Security (RLS). - Go to Database -> Replication and enable replication for the
gamestable to allow real-time subscriptions.
2. Add Environment Variables
Create a .env file in the root of the project (or copy .env.example) and add your Supabase credentials:
VITE_SUPABASE_URL="your_supabase_project_url"
VITE_SUPABASE_ANON_KEY="your_supabase_anon_key"
3. Install and Run
npm install
npm run dev
The app will be available at http://localhost:3000.
4. How to Deploy
- Push your code to a GitHub repository.
- Import your repository to your hosting provider (e.g., Vercel, Render).
- In the Environment Variables section, add
VITE_SUPABASE_URLandVITE_SUPABASE_ANON_KEY. - Deploy the application.