claude-b 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,877 @@
1
+ <p align="center">
2
+ <img src="assets/Claude-B.png" alt="Claude-B Logo" width="991" height="555">
3
+ </p>
4
+
5
+ # Claude-B
6
+
7
+ > Run Claude Code in the background. Send prompts, do other work, check results later.
8
+
9
+ Claude-B is a background-capable wrapper around [Claude Code](https://claude.ai/code) that enables:
10
+
11
+ - **Async workflows** - Send prompts, continue working, check results when ready
12
+ - **Session management** - Multiple concurrent AI sessions with conversation continuity
13
+ - **Fire-and-forget** - Launch background tasks, get notified when done
14
+ - **Notification inbox** - Interactive TUI to browse completed tasks with markdown rendering
15
+ - **Telegram integration** - Get notifications, voice input, TTS summaries, and reply to sessions from Telegram
16
+ - **Tmux bridge** - Notifications for live Claude Code sessions in tmux panes via Stop hook
17
+ - **Foreground attach** - Like `fg` in Linux, attach to see live output
18
+ - **Auto-watch streaming** - Automatically streams output after sending prompts
19
+ - **REST API** - Control sessions remotely via HTTP/WebSocket
20
+ - **Hooks** - Shell hooks and webhooks for notifications and automation
21
+ - **Multi-host orchestration** - Distribute work across multiple Claude-B instances
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ # One-line install (auto-detects npm or docker)
27
+ curl -fsSL https://cb.danielmoya.cv | bash
28
+
29
+ # Or via npm
30
+ npm i -g claude-b
31
+
32
+ # Or via Docker
33
+ docker run -d \
34
+ -v ~/.claude-b:/root/.claude-b \
35
+ --env-file ~/.claude-b/.env \
36
+ ghcr.io/danimoya/claude-b:latest
37
+ ```
38
+
39
+ Then configure everything interactively:
40
+
41
+ ```bash
42
+ cb init
43
+ ```
44
+
45
+ `cb init` walks you through BotFather, auto-captures your Telegram chat id,
46
+ and writes `~/.claude-b/.env`. Re-run it any time to update settings.
47
+
48
+ ### Configuration
49
+
50
+ Claude-B reads from environment variables with this precedence:
51
+ **process env** > `~/.claude-b/.env` > `./.env`
52
+
53
+ | Variable | Required | Purpose |
54
+ |----------|----------|---------|
55
+ | `ANTHROPIC_API_KEY` | yes | Claude Code authentication |
56
+ | `TELEGRAM_BOT_TOKEN` | no | Enables Telegram remote control |
57
+ | `TELEGRAM_ALLOWED_CHAT_IDS` | no | Comma-separated chat ids allowed to use the bot |
58
+ | `OPENAI_API_KEY` | no | Whisper STT + TTS for voice notes |
59
+ | `SPEECHMATICS_API_KEY` / `DEEPGRAM_API_KEY` | no | Alternative STT providers |
60
+ | `CB_DATA_DIR` | no | Override `~/.claude-b` (useful in containers) |
61
+ | `CB_REST_HOST` / `CB_REST_PORT` | no | REST API bind address (defaults `127.0.0.1:3847`) |
62
+ | `CB_REST_API_KEY` | no | Pre-set REST API key (auto-generated otherwise) |
63
+
64
+ See `.env.example` for a starter template.
65
+
66
+ ### Prerequisites
67
+
68
+ - Node.js 20+ (if installing via npm) or Docker
69
+ - [Claude Code](https://claude.ai/code) installed and configured
70
+
71
+ ### From source
72
+
73
+ ```bash
74
+ git clone https://github.com/danimoya/Claude-B.git
75
+ cd Claude-B
76
+ pnpm install && pnpm build && pnpm link --global
77
+ ```
78
+
79
+ ## Quick Start
80
+
81
+ ```bash
82
+ # Send a prompt (creates session if needed)
83
+ cb "Explain this codebase"
84
+
85
+ # Check last result
86
+ cb -l
87
+
88
+ # Watch live output
89
+ cb -w
90
+
91
+ # List sessions
92
+ cb -s
93
+
94
+ # Attach to session (interactive mode)
95
+ cb -a main
96
+ ```
97
+
98
+ ## Commands
99
+
100
+ ### Sessions & Prompts
101
+
102
+ | Command | Short | Description |
103
+ |---------|-------|-------------|
104
+ | `cb <prompt>` | | Send prompt to current session |
105
+ | `cb -- <prompt>` | | Explicit prompt (if starts with `-`) |
106
+ | `cb < file` | | Send file as prompt |
107
+ | `cb --last` | `-l` | Show last prompt result |
108
+ | `cb --sess` | `-s` | List all sessions |
109
+ | `cb --attach <id>` | `-a` | Attach to session (fg-style) |
110
+ | `cb --detach` | `-d` | Detach from session |
111
+ | `cb --new [name]` | `-n` | Create new session |
112
+ | `cb --model <model>` | `-m` | Claude model (with `--new`) |
113
+ | `cb --kill <id>` | `-k` | Terminate session |
114
+ | `cb --watch` | `-w` | Watch live output |
115
+ | `cb --select <id>` | `-x` | Select session for commands |
116
+ | `cb --current` | `-c` | Show current session |
117
+
118
+ ### Fire-and-Forget & Inbox
119
+
120
+ | Command | Short | Description |
121
+ |---------|-------|-------------|
122
+ | `cb -f <prompt>` | | Launch task in background |
123
+ | `cb -f -g "goal" <prompt>` | | Fire-and-forget with goal description |
124
+ | `cb --inbox` | `-i` | Interactive notification inbox |
125
+ | `cb --inbox-count` | | Show unread notification count |
126
+ | `cb --inbox-clear` | | Mark all notifications as read |
127
+
128
+ ### Telegram & Voice
129
+
130
+ | Command | Description |
131
+ |---------|-------------|
132
+ | `cb --telegram <token>` | Set up Telegram bot with token |
133
+ | `cb --telegram-status` | Show Telegram bot status |
134
+ | `cb --telegram-stop` | Disable Telegram notifications |
135
+ | `cb --voice-setup <provider> <key>` | Configure STT/TTS: `openai`, `speechmatics`, or `deepgram` |
136
+ | `cb --ai-provider <provider> <key>` | Configure AI prompt optimizer: `anthropic` or `openrouter` |
137
+ | `cb --voice-status` | Show voice pipeline status |
138
+
139
+ ### REST API & Hooks
140
+
141
+ | Command | Short | Description |
142
+ |---------|-------|-------------|
143
+ | `cb --rest [port]` | `-r` | Start REST API server |
144
+ | `cb --rest-stop` | | Stop REST API server |
145
+ | `cb --api-key` | | Show REST API key |
146
+ | `cb --status` | | Daemon status and health |
147
+ | `cb --hook <event> <cmd>` | | Register shell hook |
148
+ | `cb --unhook <id>` | | Remove shell hook |
149
+ | `cb --hooks` | | List shell hooks |
150
+ | `cb --webhook <url>` | | Register webhook |
151
+ | `cb --unwebhook <id>` | | Remove webhook |
152
+ | `cb --webhooks` | | List webhooks |
153
+
154
+ ### Multi-Host Orchestration
155
+
156
+ | Command | Description |
157
+ |---------|-------------|
158
+ | `cb --remote-add <url>` | Add remote host (with `--remote-key`) |
159
+ | `cb --remote-hosts` | List remote hosts |
160
+ | `cb --remote-health` | Health status of all hosts |
161
+ | `cb --remote <hostId> <prompt>` | Send prompt to remote host |
162
+ | `cb --remote-fire <hostId> <prompt>` | Fire-and-forget to remote host |
163
+ | `cb --remote-stats` | Orchestration statistics |
164
+
165
+ ## Guides
166
+
167
+ ### Quick Start: Fire-and-Forget
168
+
169
+ Launch tasks that run in the background and notify you when done:
170
+
171
+ ```bash
172
+ # Fire a task
173
+ cb -f "Refactor the authentication module"
174
+
175
+ # Fire with a descriptive goal
176
+ cb -f -g "Add input validation to all API endpoints" "Review every route handler in src/routes/ and add zod validation"
177
+
178
+ # Check your inbox for results
179
+ cb -i
180
+ ```
181
+
182
+ When tasks complete, you'll get a terminal bell notification. Use `cb -i` to browse results interactively.
183
+
184
+ ### Quick Start: Interactive Inbox
185
+
186
+ The inbox (`cb -i`) is a full-screen TUI for browsing completed tasks:
187
+
188
+ ```
189
+ ── Inbox (1/3) * unread ──────────────────────────────
190
+
191
+ OK deploy-nginx 14:32 12.3s $0.004
192
+ Goal: Deploy nginx config and verify
193
+
194
+ Configuration updated successfully.
195
+ • nginx.conf validated
196
+ • Service reloaded with zero downtime
197
+
198
+ Resume: cb "your follow-up here"
199
+
200
+ ── n=next p=prev r=read d=delete q=quit ──────────
201
+ ```
202
+
203
+ **Keys:**
204
+ - `n` / `j` / `→` / `↓` — Next notification
205
+ - `p` / `k` / `←` / `↑` — Previous notification
206
+ - `r` — Mark current as read
207
+ - `d` — Delete current notification
208
+ - `q` / `Esc` / `Ctrl+C` — Quit
209
+
210
+ The inbox renders markdown output (headers, bold, code blocks, lists, quotes) and shows a resume command for continuing the conversation.
211
+
212
+ ### Quick Start: Telegram Integration
213
+
214
+ Get notifications on your phone and reply to sessions from Telegram.
215
+
216
+ **Step 1: Create a Telegram bot**
217
+
218
+ 1. Open Telegram and message [@BotFather](https://t.me/BotFather)
219
+ 2. Send `/newbot`
220
+ 3. Choose a name (e.g., "My Claude-B")
221
+ 4. Choose a username (e.g., `my_claudeb_bot`)
222
+ 5. Copy the token BotFather gives you (looks like `123456789:ABCdef...`)
223
+
224
+ **Step 2: Connect to Claude-B**
225
+
226
+ ```bash
227
+ cb --telegram 123456789:ABCdefGHIjklMNO
228
+
229
+ # Output:
230
+ # Telegram bot started!
231
+ # Bot: @my_claudeb_bot
232
+ # Send /start to your bot in Telegram to register.
233
+ ```
234
+
235
+ **Step 3: Register in Telegram**
236
+
237
+ Open your bot in Telegram and send `/start`. You're now registered for notifications.
238
+
239
+ **Step 4: Use it**
240
+
241
+ ```bash
242
+ # Fire a task — notification will arrive in Telegram
243
+ cb -f "Analyze the codebase for security issues"
244
+ ```
245
+
246
+ When the task completes, you'll get a Telegram message like:
247
+
248
+ > ✅ **task-a1b2** completed (45.2s)
249
+ >
250
+ > ```
251
+ > Found 3 potential issues in auth module...
252
+ > ```
253
+ >
254
+ > Reply to this message to follow up, or /select a1b2 to switch sessions.
255
+
256
+ **Telegram commands:**
257
+ - `/start` — Register for notifications
258
+ - `/sessions` — List active sessions
259
+ - `/select <id>` — Select session for replies
260
+ - `/inbox` — Show inbox summary
261
+ - `/help` — Show all commands
262
+ - **Any text** — Send as prompt to selected session
263
+ - **Reply to notification** — Follow up on that specific session
264
+
265
+ **Manage Telegram:**
266
+ ```bash
267
+ cb --telegram-status # Check if running
268
+ cb --telegram-stop # Disable and clear token
269
+ ```
270
+
271
+ ### Voice Pipeline Setup
272
+
273
+ Enable voice messages in Telegram: dictate prompts from your phone, get AI-optimized rewrites grounded in session context, and listen to audio summaries of completed tasks.
274
+
275
+ The voice pipeline has three components — **STT** (speech-to-text), **AI** (prompt optimizer), and **TTS** (text-to-speech). Each is configured independently.
276
+
277
+ **Step 1: Configure STT provider**
278
+
279
+ Choose one of three providers. The same provider handles both STT (transcription of your voice messages) and TTS (audio playback of results).
280
+
281
+ ```bash
282
+ # OpenAI — Whisper STT + gpt-4o-mini-tts (recommended)
283
+ cb --voice-setup openai sk-proj-YOUR_OPENAI_KEY
284
+
285
+ # Speechmatics — enhanced accuracy, batch API
286
+ cb --voice-setup speechmatics YOUR_SPEECHMATICS_KEY
287
+
288
+ # Deepgram — Nova-3 STT + Aura TTS, no ffmpeg needed
289
+ cb --voice-setup deepgram YOUR_DEEPGRAM_KEY
290
+ ```
291
+
292
+ **Step 2: Configure AI provider for prompt optimization**
293
+
294
+ When you send a voice message, the raw transcript is rewritten into a well-structured prompt by an AI model. This step uses a separate provider from STT/TTS.
295
+
296
+ ```bash
297
+ # Anthropic Claude (recommended — best at prompt rewriting)
298
+ cb --ai-provider anthropic sk-ant-YOUR_ANTHROPIC_KEY
299
+
300
+ # OpenRouter (access to multiple models)
301
+ cb --ai-provider openrouter YOUR_OPENROUTER_KEY
302
+ ```
303
+
304
+ **Step 3: Verify**
305
+
306
+ ```bash
307
+ cb --voice-status
308
+
309
+ # Output:
310
+ # Voice Pipeline:
311
+ # STT Provider: openai
312
+ # AI Provider: anthropic (default)
313
+ # Pipeline: active
314
+ ```
315
+
316
+ **Step 4: Use it**
317
+
318
+ In Telegram, send a voice message to the bot. You'll see:
319
+
320
+ 1. `🎤 Transcribing...` — your audio is converted to text
321
+ 2. `🎤 Transcribed. Optimizing prompt...` — the AI rewrites it using session context
322
+ 3. A confirmation with the raw transcript and the optimized prompt:
323
+ - **✅ Send** — submit the prompt to the selected session
324
+ - **✏️ Edit** — type a corrected version manually
325
+ - **❌ Cancel** — discard
326
+
327
+ After a session completes, each notification includes a **🔊 Listen** button that generates an audio summary using TTS.
328
+
329
+ **Customizing TTS model and voice**
330
+
331
+ The TTS model and voice are stored in `~/.claude-b/telegram.json` and can be changed without a code rebuild:
332
+
333
+ ```bash
334
+ # Switch to a different model and voice
335
+ jq '.sttProvider.ttsModel = "tts-1" | .sttProvider.ttsVoice = "nova"' \
336
+ ~/.claude-b/telegram.json > /tmp/tg.json && mv /tmp/tg.json ~/.claude-b/telegram.json
337
+
338
+ # Restart the daemon to apply
339
+ sudo systemctl restart cb-daemon.service # if using systemd
340
+ # or: kill the daemon process and re-run cb to restart it
341
+ ```
342
+
343
+ | Model | Price | Latency | Notes |
344
+ |-------|-------|---------|-------|
345
+ | `gpt-4o-mini-tts` | ~$12/1M chars | ~500ms | Newest, cheapest, supports tone instructions |
346
+ | `tts-1` | $15/1M chars | ~400ms | Fastest, battle-tested |
347
+ | `tts-1-hd` | $30/1M chars | ~800ms | Highest quality |
348
+
349
+ Available voices: `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, `shimmer`, `verse`.
350
+
351
+ ### Tmux Session Notifications
352
+
353
+ If you run Claude Code interactively in tmux panes, Claude-B can bridge those sessions to Telegram — get notified when any pane finishes a response, listen to audio summaries, select sessions, and reply from your phone.
354
+
355
+ This works alongside (not instead of) Claude-B's own session management. Your tmux panes keep running as-is; Claude-B just observes them.
356
+
357
+ **Prerequisites:**
358
+ - Telegram bot already configured (see above)
359
+ - REST API running (`cb -r`)
360
+ - tmux sessions with `claude` processes
361
+
362
+ **Step 1: Install the Stop hook**
363
+
364
+ Add this to `~/.claude/settings.json` (create it if it doesn't exist):
365
+
366
+ ```json
367
+ {
368
+ "hooks": {
369
+ "Stop": [
370
+ {
371
+ "hooks": [
372
+ {
373
+ "type": "command",
374
+ "command": "$HOME/Claude-B/bin/cb-notify.sh"
375
+ }
376
+ ]
377
+ }
378
+ ]
379
+ }
380
+ }
381
+ ```
382
+
383
+ The hook fires after every top-level Claude Code response. It reads the session transcript, extracts the last assistant text, and POSTs it to Claude-B's REST API.
384
+
385
+ > **Note:** Claude Code reads `settings.json` at startup. Panes that were already running won't pick up the hook until restarted. Either `/exit` + relaunch `claude` in each pane, or let them turn over naturally.
386
+
387
+ **Step 2: Start the REST API**
388
+
389
+ The hook script sends notifications to the REST API on `localhost:3847`:
390
+
391
+ ```bash
392
+ cb -r 3847
393
+ ```
394
+
395
+ If you use systemd, the `start-daemon.sh` script handles this automatically.
396
+
397
+ **Step 3: Use it from Telegram**
398
+
399
+ Once the hook is active:
400
+
401
+ - **Automatic notifications** — every time a tmux pane's Claude session finishes a response, you receive a Telegram message with the result text, duration, and a 🔊 Listen button.
402
+ - **`/sessions`** — shows all active tmux panes (with idle/busy status) alongside Claude-B's own sessions. Tap one to select it.
403
+ - **`/select`** — pick a tmux session by name or target (e.g. `/select general:2.0`).
404
+ - **Reply to a notification** — your text is typed directly into the originating tmux pane via `tmux send-keys`.
405
+ - **Voice messages** — dictate a prompt, get an AI-optimized rewrite grounded in the session's recent conversation history (last 3 turns), confirm, and it's typed into the pane.
406
+
407
+ **How it works under the hood:**
408
+
409
+ ```
410
+ tmux pane (claude) ──Stop hook──> bin/cb-notify.sh
411
+
412
+ │ parses transcript JSONL
413
+ │ resolves tmux target + title
414
+
415
+ POST /api/notify
416
+
417
+
418
+ Claude-B daemon
419
+ ├── broadcastNotification → Telegram
420
+ ├── cache transcriptPath (for voice context)
421
+ └── persist to notification inbox
422
+ ```
423
+
424
+ Reply path:
425
+ ```
426
+ Telegram reply ──> bot.onPrompt("tmux:general:2.0", text)
427
+
428
+
429
+ daemon recognises tmux: prefix
430
+
431
+
432
+ tmux send-keys -t general:2.0 -l "text" Enter
433
+ ```
434
+
435
+ **Troubleshooting:**
436
+
437
+ ```bash
438
+ # Check if the hook is firing
439
+ tail -f ~/.claude-b/cb-notify.log
440
+
441
+ # Check REST API is reachable
442
+ curl http://127.0.0.1:3847/api/health
443
+
444
+ # Check Telegram bot is connected
445
+ cb --telegram-status
446
+
447
+ # Check voice pipeline
448
+ cb --voice-status
449
+ ```
450
+
451
+ ### Quick Start: Conversation Continuity
452
+
453
+ Sessions maintain conversation context across prompts — Claude remembers previous interactions:
454
+
455
+ ```bash
456
+ # First prompt creates a conversation
457
+ cb "Explain the authentication flow in this codebase"
458
+
459
+ # Follow-up prompt continues the same conversation
460
+ cb "Now add rate limiting to the login endpoint"
461
+
462
+ # Claude remembers the auth flow discussion
463
+ cb "Add tests for what you just implemented"
464
+ ```
465
+
466
+ ### Quick Start: Multiple Sessions
467
+
468
+ ```bash
469
+ # Create named sessions for different workstreams
470
+ cb -n backend
471
+ cb -n frontend
472
+
473
+ # Switch and work
474
+ cb -x backend
475
+ cb "Add rate limiting to API"
476
+
477
+ cb -x frontend
478
+ cb "Implement dark mode"
479
+
480
+ # Check all sessions
481
+ cb -s
482
+
483
+ # Watch a specific session's live output
484
+ cb -x backend
485
+ cb -w
486
+ ```
487
+
488
+ ### Quick Start: Hooks & Webhooks
489
+
490
+ ```bash
491
+ # Get a desktop notification when any prompt completes
492
+ cb --hook "prompt.completed" "notify-send 'Claude-B' 'Task done'"
493
+
494
+ # Send a webhook to Slack on completion
495
+ cb --webhook "https://hooks.slack.com/services/T.../B.../xxx" --webhook-event "prompt.completed"
496
+
497
+ # List active hooks
498
+ cb --hooks
499
+ cb --webhooks
500
+ ```
501
+
502
+ ### Quick Start: REST API
503
+
504
+ ```bash
505
+ # Start REST server
506
+ cb -r 3847
507
+
508
+ # Get API key
509
+ cb --api-key
510
+
511
+ # Use from any HTTP client
512
+ TOKEN=$(curl -s -X POST http://localhost:3847/api/auth/token \
513
+ -H "Content-Type: application/json" \
514
+ -d '{"api_key": "YOUR_KEY"}' | jq -r '.access_token')
515
+
516
+ curl http://localhost:3847/api/sessions -H "Authorization: Bearer $TOKEN"
517
+ ```
518
+
519
+ ### Quick Start: Multi-Host Orchestration
520
+
521
+ Distribute work across multiple servers running Claude-B:
522
+
523
+ ```bash
524
+ # Each server needs REST API running
525
+ # On server1: cb -r
526
+ # On server2: cb -r
527
+
528
+ # From your local machine, add remote hosts
529
+ cb --remote-add http://server2:3847 --remote-key <api-key> --remote-name server2
530
+
531
+ # Send work to specific hosts
532
+ cb --remote server2 "Analyze the database schema"
533
+
534
+ # Or fire-and-forget to remote hosts
535
+ cb --remote-fire server2 "Run the full test suite"
536
+
537
+ # Monitor health
538
+ cb --remote-health
539
+ cb --remote-stats
540
+ ```
541
+
542
+ ### Piped Input
543
+
544
+ ```bash
545
+ # Send file contents as prompt
546
+ cb < requirements.txt
547
+
548
+ # Pipe from other commands
549
+ echo "Fix the bug in auth.ts" | cb
550
+
551
+ # Combine with fire-and-forget
552
+ echo "Analyze this log for errors" | cb -f
553
+ ```
554
+
555
+ ## Architecture
556
+
557
+ ```
558
+ ┌──────────────┐ ┌────────────────┐
559
+ │ cb CLI │ │ Telegram Bot │
560
+ └──────┬───────┘ └───────┬────────┘
561
+ │ Unix Socket │
562
+ ┌──────▼────────────────────▼──┐
563
+ │ Daemon │
564
+ │ │
565
+ │ ┌──────────┐ ┌───────────┐ │
566
+ │ │ Session │ │ Hooks │ │ ┌─────────────┐
567
+ │ │ Pool │ │ Engine │ │────▶│ Webhooks │
568
+ │ └────┬─────┘ └───────────┘ │ └─────────────┘
569
+ │ │ ┌───────────┐ │
570
+ │ │ │ Inbox │ │
571
+ │ │ └───────────┘ │ ┌─────────────┐
572
+ │ │ ┌───────────┐ │────▶│ Remote Host │
573
+ │ │ │ Orch. │ │ │ Remote Host │
574
+ │ │ └───────────┘ │ └─────────────┘
575
+ │ │ │
576
+ │ ┌────▼─────┐ ┌───────────┐ │
577
+ │ │ Claude │ │ REST API │◀─────── HTTP clients
578
+ │ │ Code │ └───────────┘ │
579
+ │ └──────────┘ │
580
+ └──────────────────────────────┘
581
+ ```
582
+
583
+ ### Components
584
+
585
+ - **CLI** (`cb`) - Thin client with interactive inbox TUI
586
+ - **Daemon** - Long-running process managing sessions, hooks, notifications, and integrations
587
+ - **Session** - Wraps Claude Code subprocess with conversation continuity
588
+ - **Notification Inbox** - JSONL-based store for completion notifications
589
+ - **Telegram Bot** - Sends notifications, receives prompts via Telegram
590
+ - **Hooks Engine** - Shell hooks and webhooks triggered by events
591
+ - **Orchestration** - Multi-host coordination with health checks and failover
592
+ - **REST API** - HTTP/WebSocket API for remote control
593
+ - **IPC** - Unix socket for local CLI-daemon communication
594
+
595
+ ## Configuration
596
+
597
+ Config file: `~/.claude-b/config.json`
598
+
599
+ ```json
600
+ {
601
+ "sessions": {
602
+ "maxConcurrent": 10,
603
+ "defaultTimeout": 3600000
604
+ },
605
+ "notifications": {
606
+ "shell": true,
607
+ "command": "notify-send 'Claude-B' '$MESSAGE'"
608
+ }
609
+ }
610
+ ```
611
+
612
+ ## Data Storage
613
+
614
+ ```
615
+ ~/.claude-b/
616
+ ├── config.json # Configuration
617
+ ├── daemon.pid # Daemon PID file
618
+ ├── daemon.sock # Unix socket
619
+ ├── daemon.log # Daemon logs
620
+ ├── cb-notify.log # Stop hook delivery log
621
+ ├── api.key # REST API key (mode 600)
622
+ ├── notifications.jsonl # Notification inbox (append-only)
623
+ ├── telegram.json # Telegram bot config, session map, voice settings
624
+ ├── sessions/
625
+ │ ├── index.json # Session index
626
+ │ └── <session-id>/ # Per-session data
627
+ │ └── history.jsonl # Prompt/response history
628
+ └── hooks.json # Shell hooks & webhook definitions
629
+ ```
630
+
631
+ ## Docker
632
+
633
+ ### Multi-Host Orchestration Testing
634
+
635
+ Run multiple Claude-B instances for testing orchestration features:
636
+
637
+ ```bash
638
+ # Set your API key
639
+ export ANTHROPIC_API_KEY=your-key-here
640
+
641
+ # Start 3 instances
642
+ docker-compose up -d
643
+
644
+ # Instances available at:
645
+ # host1: http://localhost:3847
646
+ # host2: http://localhost:3848
647
+ # host3: http://localhost:3849
648
+
649
+ # Configure orchestration from primary host
650
+ cb -r # Start REST API
651
+ cb --remote-add http://localhost:3848 --remote-key <api-key> --remote-name host2
652
+ cb --remote-add http://localhost:3849 --remote-key <api-key> --remote-name host3
653
+
654
+ # Send prompts to remote hosts
655
+ cb --remote host2 "Analyze this codebase"
656
+ cb --remote-health # Check health status
657
+
658
+ # Stop containers
659
+ docker-compose down
660
+ ```
661
+
662
+ ### Single Instance
663
+
664
+ ```bash
665
+ # Build image
666
+ docker build -t claude-b .
667
+
668
+ # Run container
669
+ docker run -d \
670
+ -e ANTHROPIC_API_KEY=your-key \
671
+ -p 3847:3847 \
672
+ --name claude-b \
673
+ claude-b
674
+ ```
675
+
676
+ ### Testing REST API and Hooks
677
+
678
+ Build and run a test container:
679
+
680
+ ```bash
681
+ # Build the image
682
+ docker build -t claudeb-test:latest .
683
+
684
+ # Run container with API key
685
+ docker run -d \
686
+ --name claudeb-test \
687
+ -e ANTHROPIC_API_KEY=your-key-here \
688
+ -p 3850:3847 \
689
+ claudeb-test:latest
690
+
691
+ # Wait for startup and get API key from logs
692
+ sleep 3
693
+ docker logs claudeb-test
694
+ # Look for: API Key: cb_xxxxx...
695
+ ```
696
+
697
+ Test the REST API:
698
+
699
+ ```bash
700
+ # Set your API key (from docker logs output)
701
+ API_KEY="cb_your_api_key_here"
702
+
703
+ # Get JWT token
704
+ TOKEN=$(curl -4 -s -X POST http://127.0.0.1:3850/api/auth/token \
705
+ -H "Content-Type: application/json" \
706
+ -d "{\"api_key\": \"$API_KEY\"}" | jq -r '.access_token')
707
+
708
+ # Test health endpoint
709
+ curl -4 -s http://127.0.0.1:3850/api/health | jq
710
+
711
+ # List sessions
712
+ curl -4 -s http://127.0.0.1:3850/api/sessions \
713
+ -H "Authorization: Bearer $TOKEN" | jq
714
+
715
+ # Create a session with model selection
716
+ curl -4 -s -X POST http://127.0.0.1:3850/api/sessions \
717
+ -H "Authorization: Bearer $TOKEN" \
718
+ -H "Content-Type: application/json" \
719
+ -d '{"name": "test-session", "model": "sonnet"}' | jq
720
+
721
+ # Add a shell hook
722
+ curl -4 -s -X POST http://127.0.0.1:3850/api/hooks/shell \
723
+ -H "Authorization: Bearer $TOKEN" \
724
+ -H "Content-Type: application/json" \
725
+ -d '{"event": "prompt.completed", "command": "echo Done!"}' | jq
726
+
727
+ # Add a webhook with session filter
728
+ curl -4 -s -X POST http://127.0.0.1:3850/api/hooks/webhook \
729
+ -H "Authorization: Bearer $TOKEN" \
730
+ -H "Content-Type: application/json" \
731
+ -d '{"event": "session.created", "url": "https://httpbin.org/post", "sessionFilter": "test-session"}' | jq
732
+
733
+ # List all hooks
734
+ curl -4 -s http://127.0.0.1:3850/api/hooks/shell -H "Authorization: Bearer $TOKEN" | jq
735
+ curl -4 -s http://127.0.0.1:3850/api/hooks/webhook -H "Authorization: Bearer $TOKEN" | jq
736
+
737
+ # Cleanup
738
+ docker stop claudeb-test && docker rm claudeb-test
739
+ ```
740
+
741
+ ## Development
742
+
743
+ ```bash
744
+ # Install dependencies
745
+ pnpm install
746
+
747
+ # Development mode (watch)
748
+ pnpm dev
749
+
750
+ # Build for production
751
+ pnpm build
752
+
753
+ # Type check
754
+ pnpm typecheck
755
+
756
+ # Run tests
757
+ pnpm test
758
+ ```
759
+
760
+ ## Potential Features
761
+
762
+ ### Workflow Pipelines
763
+ Chain AI tasks together like GitHub Actions for AI. Define multi-step workflows where output flows between sessions.
764
+
765
+ ```yaml
766
+ # .claude-b/workflows/code-review.yml
767
+ name: code-review
768
+ steps:
769
+ - session: analyze
770
+ prompt: "Analyze {{file}} for potential issues"
771
+ - session: suggest
772
+ prompt: "Based on: {{steps.analyze.output}}, suggest improvements"
773
+ - session: implement
774
+ prompt: "Implement the top suggestion"
775
+ requires_approval: true
776
+ ```
777
+
778
+ ```bash
779
+ cb workflow run code-review --file src/api.ts
780
+ ```
781
+
782
+ ### Session Templates
783
+ Pre-configured session setups with custom system prompts, model selection, and hooks. One command to start specialized workflows.
784
+
785
+ ```bash
786
+ # Create from template
787
+ cb -n myreview --template code-review
788
+
789
+ # Templates include: code-review, bug-fix, refactor, test-writer, docs
790
+ cb template list
791
+ cb template create my-custom --from current
792
+ ```
793
+
794
+ ### Prompt Queues & Scheduling
795
+ Queue prompts for batch processing. Schedule recurring AI tasks.
796
+
797
+ ```bash
798
+ # Queue multiple prompts
799
+ cb queue add "Analyze auth.ts"
800
+ cb queue add "Analyze api.ts"
801
+ cb queue add "Summarize all findings"
802
+ cb queue run # Process sequentially
803
+
804
+ # Schedule recurring tasks
805
+ cb schedule "Review open PRs" --cron "0 9 * * *"
806
+ cb schedule "Update docs" --every 24h
807
+ ```
808
+
809
+ ### Cross-Session Context
810
+ Sessions that share context and reference each other's outputs.
811
+
812
+ ```bash
813
+ # Create a context pool
814
+ cb context create myproject
815
+
816
+ # Sessions share the pool
817
+ cb -n backend --context myproject
818
+ cb -n frontend --context myproject
819
+
820
+ # Reference other sessions
821
+ cb -x frontend "Use the API schema from @backend to generate TypeScript types"
822
+ ```
823
+
824
+ ### Cost & Usage Analytics
825
+ Track token usage, set budgets, and monitor spending.
826
+
827
+ ```bash
828
+ cb usage # Current session stats
829
+ cb usage --all # All sessions
830
+ cb usage --report weekly # Usage report
831
+
832
+ cb budget set 10.00 --daily # Daily spending limit
833
+ cb budget set 100.00 --session # Per-session limit
834
+ ```
835
+
836
+ ### Session Snapshots & Branching
837
+ Git-like version control for AI sessions. Save state, branch, compare approaches.
838
+
839
+ ```bash
840
+ cb snapshot create "before-refactor"
841
+ cb snapshot list
842
+ cb snapshot restore abc123
843
+
844
+ # Branch a session
845
+ cb branch myfeature --from main-session
846
+ cb branch compare main-session myfeature
847
+ ```
848
+
849
+ ### Smart Fallbacks & Retries
850
+ Automatic retry on failures with model fallback chains.
851
+
852
+ ```bash
853
+ # Configure fallback chain
854
+ cb config set fallback-chain "opus,sonnet,haiku"
855
+
856
+ # Auto-retry with exponential backoff
857
+ cb config set auto-retry true
858
+ cb config set max-retries 3
859
+ ```
860
+
861
+ ### Output Transformers
862
+ Post-process AI output with built-in or custom transformers.
863
+
864
+ ```bash
865
+ # Extract code blocks
866
+ cb "Generate a function" | cb transform extract-code
867
+
868
+ # Parse structured output
869
+ cb "List files as JSON" | cb transform json
870
+
871
+ # Custom transformer
872
+ cb transform register my-parser --script ./parse.js
873
+ ```
874
+
875
+ ## License
876
+
877
+ AGPL-3.0 - See [LICENSE](LICENSE) for details.