;
+
+
+
+ Make it blue
+ `
+});
+
+resetAllFileModifications(); // Clear tracking
+
+// STEP 6: Claude responds with new
+
+ export default function App() {
+ return
Hello World
;
+ }
+
+
+// File overwritten in WebContainer
+// Editor reloads with new content
+// #modifiedFiles is EMPTY again (reset after last message)
+```
+
+---
+
+### 11. Key Differences: Creation vs Editing
+
+| Aspect | New File Creation | File Editing |
+|--------|-------------------|--------------|
+| **Triggered By** | Claude's `` | User typing in editor |
+| **API Call** | `webcontainer.fs.writeFile()` | `webcontainer.fs.writeFile()` |
+| **Tracked in `#modifiedFiles`** | ❌ No | ✅ Yes (on save) |
+| **Sent Back to Claude** | ❌ No | ✅ Yes (as diff or full content) |
+| **Appears in `unsavedFiles`** | ❌ No | ✅ Yes (until saved) |
+| **Diff Calculated** | ❌ N/A | ✅ Yes (against original) |
+| **Baseline Established** | Immediately | On first save after Claude message |
+
+---
+
+### 12. Binary File Handling
+
+```typescript
+// Files like images, PDFs are detected
+const isBinary = isBinaryFile(buffer); // Uses 'istextorbinary' npm package
+
+if (isBinary) {
+ this.files.setKey(filePath, {
+ type: 'file',
+ content: '', // Empty string (not displayable)
+ isBinary: true
+ });
+}
+```
+
+**Result**:
+- Binary files don't open in editor
+- Not included in modifications sent to Claude
+- Still tracked in file tree
+
+---
+
+### 13. Hot Module Reload (HMR) Persistence
+
+```typescript
+// Persist state across HMR reloads during development
+#modifiedFiles: Map =
+ import.meta.hot?.data.modifiedFiles ?? new Map();
+
+files: MapStore =
+ import.meta.hot?.data.files ?? map({});
+
+if (import.meta.hot) {
+ import.meta.hot.data.files = this.files;
+ import.meta.hot.data.modifiedFiles = this.#modifiedFiles;
+}
+```
+
+**Benefit**: Developer experience - file state survives code hot-reloads.
+
+---
+
+### Summary: The Modification System
+
+Bolt.new implements a **dual-tracking system**:
+
+1. **`unsavedFiles`**: Tracks editor changes not yet written to WebContainer
+2. **`#modifiedFiles`**: Tracks saved changes not yet sent to Claude
+
+This enables:
+- **Context-aware AI**: Claude knows exactly what changed without re-reading entire projects
+- **Token efficiency**: Only diffs are sent, not full files
+- **User control**: Users can edit freely; changes only sent when they message Claude
+- **Baseline management**: System resets tracking after each Claude response
+
+The system uses the **same file operation** (`writeFile`) for both creation and editing, but the **tracking layer** intelligently distinguishes between them to provide Claude with the perfect amount of context.
+
+---
+
+## Summary
+
+The Bolt.new agent architecture is a **parser-driven autonomous execution system** that creates an illusion of an AI agent building applications. The key components are:
+
+1. **StreamingMessageParser**: Extracts XML-wrapped instructions from Claude's streaming response
+2. **ActionRunner**: Executes file and shell operations sequentially in WebContainer
+3. **Workbench Store**: Manages state with reactive Nanostores
+4. **UI Components**: Display real-time progress and allow user interaction
+5. **WebContainer**: Provides browser-based Node.js runtime for code execution
+
+**The Magic**: Claude is instructed via system prompt to format all solutions as XML with `` and `` tags. The application parses this XML as it streams in and automatically executes the actions, creating the autonomous "agent" experience.
+
+**Key Innovation**: No separate agent framework needed - it's pure prompt engineering + streaming parser + sequential execution engine.
+
+---
+
+## Additional Resources
+
+- **WebContainer Docs**: https://webcontainers.io/
+- **Nanostores Docs**: https://github.com/nanostores/nanostores
+- **Claude API Docs**: https://docs.anthropic.com/
+- **Remix Framework**: https://remix.run/ (the app framework used)
+- **Monaco Editor**: https://microsoft.github.io/monaco-editor/
+
+---
+
+*Document created: 2025-11-05*
+*Bolt.new Version: Based on codebase analysis*
\ No newline at end of file