Hey there! Thanks so much for reaching out and sharing the issue you’re facing. I actually ran into the exact same problem with the App Prototyper throwing this error:
[GoogleGenerativeAI Error]: Error fetching from https://monospace-pa.googleapis.com/v1/models/gemini-2.5-pro-preview-03-25:streamGenerateContent?alt=sse: [400 Bad Request] The input token count (1049106) exceeds the maximum number of tokens allowed (1048575).
You’re totally right — it doesn’t seem like the command itself is the problem. The issue comes from how Firebase Studio saves all our conversation history in a file that grows over time. Once it goes over the model’s token limit, everything breaks.
Here’s how I solved it, and hopefully it helps you too:
Problem
Firebase Studio’s App Prototyper agent stores all chat history in a file: capra-context-state.json. Each time you send a prompt, the entire history is sent along — and if it’s too large, you get a token error like the one you saw.
Solution Summary
We trim down the stored conversation history to bring it below the token limit. The key is to keep the most important parts — the start (to preserve context) and the end (recent progress).
Step-by-Step Fix
- Open your workspace in Firebase Studio
From [My Workspaces], open the one where the issue happens
Click Switch to Code
1. Open Terminal
Press `Ctrl + `` (backtick) or click Terminal at the bottom
1. Backup the JSON files (IMPORTANT)
Do this step-by-step in the terminal:
a. Create a backup folder:
mkdir -p /home/user/studio/context_backup/
b. Backup the context file:
cp /home/user/.idx/ai/capra-context-state.json /home/user/studio/context_backup/capra-context-state-$(date +%Y%m%d%H%M%S).json
c. Backup the thread file:
cp /home/user/.idx/ai/capra-thread.json /home/user/studio/context_backup/capra-thread-$(date +%Y%m%d%H%M%S).json
1. Add the backup folder to .gitignore
Open .gitignore and add:
prototyper
/context_backup
.gitignore
1. Open the context file
code /home/user/.idx/ai/capra-context-state.json
1. Format the JSON
In the editor: Right-click > Format Document
- Locate this section:
"app-prototyping-agent": {
"edit-app-agent": [ ... ]
}
1. Delete middle history entries
Keep:
The first ~20 conversations (optional number, worked for me)
The last ~10 conversations (also optional, tweak as needed)
Delete everything in between.
DO NOT delete outside the edit-app-agent: [ … ] array.
1. Save the file (Ctrl + S)
2. Switch back to Prototyper and test
Use a new prompt, not “Try Again” (as it uses the old cached version).
Reusable Prompt
If you want to ask someone else to help you clean the file, here’s a prompt you can send(
For the prompt, please mention that I copied the entire JSON file into a new file and gave that file to Google AI Studio Flash 2, then sent the prompt along with that file. ):
Blockquote
Please help clean this capra-context-state.json file.
Inside the field:
"app-prototyping-agent": {
"edit-app-agent": [ ... ]
}
Please keep the first 20 and last 10 conversation entries in the array. You can delete the middle ones to reduce token size. The numbers 20 and 10 are just what worked for me — feel free to adjust if needed. Just make sure only to delete inside the edit-app-agent array and keep the structure intact.
Still not working?
Try refreshing with Ctrl + R
Reset workspace from Firebase Studio
Recheck that history was reduced properly
Want to Restore Your Backup?
Use the terminal to copy the backup back:
cp /home/user/studio/context_backup/capra-context-state-.json /home/user/.idx/ai/capra-context-state.json
Replace <timestamp>
with the actual timestamp from your backup file.
Share Your Fix!
If this worked for you, definitely reply and let others know. And don’t worry — the number of kept messages isn’t fixed, tweak it to your case.
Hope this helps! And fingers crossed Firebase adds context management tools soon 