Ever wanted to put a real, intelligent AI chatbot right inside a Scratch project?
This repository has everything you need to connect any Scratch 3.0 project to a high-speed AI (powered by Groq) that runs 24/7 in the cloud completely for free. You can ask it math problems, science questions, coding help, or just have a fun conversation—directly from the Scratch stage!
If you've ever worked with Scratch Cloud Variables, you already know the big roadblock: Scratch cloud variables can only store numbers—never letters or words.
So how do we get Scratch to talk to an AI? We built a two-way numeric bridge:
[ You type question ]
↓
[ Scratch encodes text → 2-digit numbers (e.g. "hi" → 10809) ]
↓
[ Writes numbers to ☁ INPUT ]
↓ (Scratch Cloud WebSocket)
[ Python Cloud Server catches the numbers ]
↓
[ Python decodes numbers → English question ]
↓
[ Sends question to Groq AI (Llama / GPT models in < 1s) ]
↓
[ Groq returns the AI answer ]
↓
[ Python encodes reply → numbers ]
↓
[ Writes numbers to ☁ OUTPUT ]
↓ (Scratch Cloud WebSocket)
[ Scratch detects new numbers → decodes back to English ]
↓
[ Formats & displays response inside the on-stage chat log! ]
All of this happens in about 1 to 2 seconds!
- Scratch 3.0 — Frontend visual project with custom word-wrapped chat list and two-way cloud encoding.
- scratchattach — Lightweight Python library created by TimMcCool that connects directly to Scratch's cloud WebSocket servers.
- Groq Cloud API — Lightning-fast LLM inference providing 14,400 free requests per day.
- GitHub Actions — Free continuous runner that keeps the Python script running 24/7 without needing your computer on.
- A Scratch Account with "Scratcher" Status: Scratch restricts cloud variables for brand new accounts ("New Scratcher"). You need standard "Scratcher" status.
- A Free Groq API Key: Takes 30 seconds to generate at console.groq.com/keys (no credit card needed).
You don't need to keep your laptop open or terminal running—GitHub runs it for you in the cloud.
- Fork or create your own copy of this repository on GitHub.
- Go to your repository's Settings → Secrets and variables → Actions.
- Click New repository secret and add each of these 4 secrets:
-
SCRATCH_USERNAME— Your Scratch username. -
SCRATCH_PASSWORD— Your Scratch password. -
SCRATCH_PROJECT_ID— The ID from your Scratch project URL (scratch.mit.edu/projects/123456789/$\rightarrow$ 123456789). -
GROQ_API_KEY— Your key from console.groq.com.
-
- Go to the Actions tab, click 24-7 Scratch AI Bot on the left, and click Run workflow.
- That's it! Your bot is now online and listening to your Scratch project 24/7.
-
Clone this repository:
git clone https://github.com/dumbtechkid/scratch-ai-chatbot.git cd scratch-ai-chatbot -
Install the dependencies:
pip install -r requirements.txt
-
Configure your credentials: Open
.envin a text editor and fill in your details:SCRATCH_USERNAME=your_scratch_username SCRATCH_PASSWORD=your_scratch_password SCRATCH_PROJECT_ID=your_project_id GROQ_API_KEY=gsk_your_groq_key GROQ_MODEL=openai/gpt-oss-120b
-
Start the bot:
python bot.py
You should see:
Connected to Scratch project 123456789 as 'your_username'. Listening for Scratch cloud events...
- Open the Scratch Editor.
- Click File → Load from your computer.
- Select
AI Chatbot.sb3included in this repository. - If you created a new project, make sure it has two cloud variables:
☁ INPUT☁ OUTPUT
- Click the Green Flag, type a question in the ask prompt, and watch the AI reply in the chat log!
If you prefer using an AI assistant (like ChatGPT, Claude, Cursor, Copilot, or Antigravity) to handle the setup, simply open the LLM.md file in this repository and copy-paste it into your AI prompt window. The AI will guide or automate the entire setup process for you!
Want your bot to act like a pirate, a friendly tutor, or a game character?
Open bot.py and find SYSTEM_PROMPT:
SYSTEM_PROMPT = (
"You are a friendly, intelligent, and helpful AI assistant in a Scratch project. "
"Speak naturally, normally, and conversationally. "
"Keep every response strictly under 120 characters and do not use newlines."
)Change this text to whatever personality you want! Just be sure to keep the instruction about keeping responses under 120 characters, since Scratch cloud variables have a 256-digit limit.
Q: Scratch says "Thinking..." but nothing happens?
- Double-check that your Scratch account has the full "Scratcher" status (not "New Scratcher"). New accounts cannot write to or receive cloud variables.
- Verify the project ID in your
.envor GitHub Secrets matches the URL of your project.
Q: Is Groq really free?
- Yes! Groq's free tier provides 14,400 requests every single day, which is more than enough for a Scratch project.
Q: Why do answers have to be under 127 characters?
- Scratch limits cloud variables to 256 digits. Since each character encodes into 2 digits (plus a 1-digit sentinel header),
(256 - 1) / 2 = 127characters maximum per message.
- Scratch is a project of the Scratch Foundation, in collaboration with the Lifelong Kindergarten Group at the MIT Media Lab.
- Built with
scratchattachby TimMcCool. - Open source and free to use for any educational or personal project!