1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# Claude Flow
An opinionated coding assistant that enforces a structured workflow: research → plan → annotate → implement.
Built on Electron + React + SQLite, driving Claude Code under the hood.
## Core Principle
**Never let Claude write code until you've reviewed and approved a written plan.**
The separation of planning and execution prevents wasted effort, keeps you in control of architecture decisions, and produces better results than jumping straight to code.
## Workflow Phases
```
┌──────────┐ ┌──────┐ ┌──────────┐ ┌───────────┐
│ Research │ ─► │ Plan │ ─► │ Annotate │ ─► │ Implement │
└──────────┘ └──────┘ └──────────┘ └───────────┘
│ │
└────── ◄ ────────┘
(iterate as needed)
```
### 1. Research
- Deep read of relevant codebase sections
- Output: `research.md` with detailed findings
- System prompt enforces: "Read deeply, write findings, don't make changes"
### 2. Plan
- Detailed implementation approach with code snippets
- Output: `plan.md` with approach, file paths, trade-offs
- System prompt enforces: "Write detailed plan, don't implement yet"
### 3. Annotate
- Human adds inline notes directly in `plan.md`
- Claude addresses notes and updates the document
- Repeat 1-6 times until plan is approved
- System prompt enforces: "Address notes, update plan, don't implement yet"
### 4. Implement
- Execute the approved plan
- Mark tasks complete as work progresses
- Run typecheck continuously
- Terse feedback corrections during this phase
---
## Architecture
### Tech Stack
- **Electron** - Desktop app with filesystem access
- **React** - Renderer UI
- **better-sqlite3** - Local persistence
- **Vite** - Fast dev builds
- **Claude Code SDK** - AI engine (`@anthropic-ai/claude-code`)
### SQLite Schema
```sql
-- Projects (a codebase you're working on)
CREATE TABLE projects (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
path TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
-- Sessions (a task/feature within a project)
CREATE TABLE sessions (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL REFERENCES projects(id),
name TEXT NOT NULL,
phase TEXT NOT NULL DEFAULT 'research',
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
-- Messages (conversation history per session)
CREATE TABLE messages (
id TEXT PRIMARY KEY,
session_id TEXT NOT NULL REFERENCES sessions(id),
role TEXT NOT NULL,
content TEXT NOT NULL,
created_at INTEGER NOT NULL
);
-- Artifacts (research.md, plan.md per session)
CREATE TABLE artifacts (
id TEXT PRIMARY KEY,
session_id TEXT NOT NULL REFERENCES sessions(id),
type TEXT NOT NULL,
content TEXT NOT NULL,
version INTEGER NOT NULL DEFAULT 1,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
```
### Directory Structure
```
src/main/
├── index.ts # App lifecycle, window management
├── preload.ts # IPC bridge to renderer
├── db/
│ ├── index.ts # Database connection
│ ├── schema.ts # Migrations
│ ├── projects.ts # Project CRUD
│ └── sessions.ts # Session CRUD
├── claude/
│ ├── index.ts # Claude Code SDK wrapper
│ └── phases.ts # Phase-specific system prompts
└── ipc/
└── handlers.ts # IPC handler registration
renderer/src/
├── main.tsx
├── App.tsx
├── components/
│ ├── Sidebar.tsx # Projects + sessions list
│ ├── Chat.tsx # Message thread
│ ├── ArtifactPane.tsx # research.md / plan.md editor
│ └── PhaseIndicator.tsx
├── hooks/
│ └── useSession.ts
└── lib/
└── ipc.ts # Typed IPC calls
```
### UI Layout
```
┌─────────────┬────────────────────────────────────┐
│ Projects │ [Research] [Plan] [Annotate] [Go] │
│ └─ Proj A ├────────────────────────────────────┤
│ ├─ Sess1 │ ┌─────────────┬─────────────────┐ │
│ └─ Sess2 │ │ Chat │ Artifact │ │
│ └─ Proj B │ │ pane │ pane │ │
│ └─ ... │ │ │ (plan.md) │ │
│ │ └─────────────┴─────────────────┘ │
└─────────────┴────────────────────────────────────┘
```
---
## Phase System Prompts
### Research Phase
```
You are in RESEARCH mode. Your job is to deeply understand the relevant parts of the codebase.
Rules:
- Read files thoroughly, not superficially
- Write all findings to research.md
- DO NOT make any code changes
- DO NOT create or modify any files except research.md
When finished, summarize what you learned and wait for the next instruction.
```
### Plan Phase
```
You are in PLANNING mode. Your job is to write a detailed implementation plan.
Rules:
- Write the plan to plan.md
- Include specific code snippets showing proposed changes
- Include file paths that will be modified
- Include trade-offs and considerations
- DO NOT implement anything
- DO NOT modify any source files
The plan should be detailed enough that implementation becomes mechanical.
```
### Annotate Phase
```
You are in ANNOTATION mode. The human has added notes to plan.md.
Rules:
- Read all inline notes (marked with comments or annotations)
- Address each note by updating the relevant section
- DO NOT implement anything
- DO NOT modify any source files
- Only update plan.md
When finished, summarize the changes you made to the plan.
```
### Implement Phase
```
You are in IMPLEMENTATION mode. The plan has been approved.
Rules:
- Follow the plan exactly
- Mark tasks complete in plan.md as you finish them
- Run typecheck continuously
- Do not add unnecessary comments or jsdocs
- Do not use `any` or `unknown` types
- Do not stop until all tasks are complete
If you encounter issues not covered by the plan, stop and ask.
```
---
## Implementation Phases
### Phase 1: Foundation
- [ ] Set up directory structure
- [ ] Implement SQLite schema and migrations
- [ ] Create database CRUD operations
- [ ] Set up IPC handlers skeleton
### Phase 2: Core UI
- [ ] Sidebar with project/session tree
- [ ] Phase indicator and controls
- [ ] Basic chat pane (messages display)
- [ ] Artifact pane (markdown editor)
### Phase 3: Claude Integration
- [ ] Integrate Claude Code SDK
- [ ] Implement phase-specific system prompts
- [ ] Wire up chat to Claude
- [ ] Handle streaming responses
### Phase 4: Workflow Logic
- [ ] Phase transitions with guards
- [ ] Artifact versioning
- [ ] "Don't implement yet" enforcement
- [ ] Progress tracking during implementation
### Phase 5: Polish
- [ ] Keyboard shortcuts
- [ ] Session search/filter
- [ ] Export sessions
- [ ] Settings (API key, preferences)
---
## Decisions Made
1. **Claude Agent SDK**: Using the SDK (`@anthropic-ai/claude-agent-sdk`) — provides hooks, session management, and streaming.
2. **Artifact storage**: Files in `.claude-flow/` directory (research.md, plan.md). Editable in any editor, visible in git.
3. **Session context**: SDK auto-compacts when context fills. UI will show token usage so users can see context size.
4. **Code review**: Out of scope — this tool enforces the *generation* workflow. Review stays in git.
---
## References
- [How I Use Claude Code](https://boristane.com/blog/how-i-use-claude-code/) - The workflow this is based on
- [Claude Code SDK](https://www.npmjs.com/package/@anthropic-ai/claude-code) - NPM package
- [Electron + better-sqlite3 template](https://github.com/ethanmick/minimal-electron-vite-react-better-sqlite) - Starting point
|