@willjackson/claude-code-bridge 0.6.0 → 0.6.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 +82 -648
- package/dist/cli.js +12 -3
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,726 +1,160 @@
|
|
|
1
1
|
# Claude Code Bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Extend Claude Code's reach to remote machines, containers, and servers.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Control files and execute tasks on any connected environment—all from your local Claude Code session.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- [Features](#features)
|
|
9
|
-
- [Installation](#installation)
|
|
10
|
-
- [Quick Start](#quick-start)
|
|
11
|
-
- [CLI Reference](#cli-reference)
|
|
12
|
-
- [Configuration](#configuration)
|
|
13
|
-
- [Programmatic Usage](#programmatic-usage)
|
|
14
|
-
- [Troubleshooting](#troubleshooting)
|
|
15
|
-
- [Development](#development)
|
|
16
|
-
- [License](#license)
|
|
7
|
+
## The Problem
|
|
17
8
|
|
|
18
|
-
|
|
9
|
+
You're running Claude Code locally, but your project lives on:
|
|
10
|
+
- A remote development server
|
|
11
|
+
- A Docker container
|
|
12
|
+
- A cloud VM or EC2 instance
|
|
13
|
+
- A different machine on your network
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
Without Bridge, you'd need separate Claude Code sessions, copy files back and forth, or SSH in manually.
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
## The Solution
|
|
18
|
+
|
|
19
|
+
Claude Code Bridge connects your local Claude Code to remote environments via WebSocket. Your local Claude gains the ability to **read, write, list, and delete files** on any connected machine—as if they were local.
|
|
23
20
|
|
|
24
21
|
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
│
|
|
28
|
-
│
|
|
29
|
-
│
|
|
30
|
-
│
|
|
31
|
-
│
|
|
32
|
-
│
|
|
33
|
-
|
|
34
|
-
│ │ port 8766 │ │
|
|
35
|
-
│ └──────────────┬──────────────────┘ │
|
|
36
|
-
└─────────────────┼───────────────────────┘
|
|
37
|
-
│ WebSocket
|
|
38
|
-
┌─────────────────┼───────────────────────┐
|
|
39
|
-
│ CLIENT (Remote Machine) │
|
|
40
|
-
│ ┌──────────────┴──────────────────┐ │
|
|
41
|
-
│ │ Bridge (client mode) │ │
|
|
42
|
-
│ │ --with-handlers │ │
|
|
43
|
-
│ │ Executes: read/write/delete │ │
|
|
44
|
-
│ └─────────────────────────────────┘ │
|
|
45
|
-
└─────────────────────────────────────────┘
|
|
22
|
+
LOCAL MACHINE REMOTE MACHINE
|
|
23
|
+
┌──────────────────────┐ ┌──────────────────────┐
|
|
24
|
+
│ │ │ │
|
|
25
|
+
│ Claude Code │ │ Bridge Client │
|
|
26
|
+
│ + │ WebSocket │ --with-handlers │
|
|
27
|
+
│ Bridge Host ────────────────────► │
|
|
28
|
+
│ (port 8766) │ │ Executes commands │
|
|
29
|
+
│ │ │ on your files │
|
|
30
|
+
└──────────────────────┘ └──────────────────────┘
|
|
46
31
|
```
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- **Remote file editing**: Read, write, and delete files on remote servers from your local Claude Code
|
|
51
|
-
- **Cross-environment development**: Work on a Docker container or VM from your local machine
|
|
52
|
-
- **Server management**: Manage configuration files on remote servers
|
|
53
|
-
- **Multi-machine workflows**: Control multiple remote environments from one Claude Code instance
|
|
54
|
-
|
|
55
|
-
## Features
|
|
56
|
-
|
|
57
|
-
- **Host-Client architecture** - Control remote environments from your local machine
|
|
58
|
-
- **Remote file operations** - read, write, delete, and list files on connected clients
|
|
59
|
-
- **Real-time command logging** - See incoming commands on the client console
|
|
60
|
-
- **WebSocket communication** with automatic reconnection
|
|
61
|
-
- **MCP integration** - Use remote bridge tools directly in Claude Code
|
|
62
|
-
- **Daemon mode** - Run the host bridge in the background
|
|
63
|
-
|
|
64
|
-
## Installation
|
|
33
|
+
## Use Cases
|
|
65
34
|
|
|
66
|
-
|
|
35
|
+
- **Remote Development** — Edit files on a dev server without leaving your local Claude Code
|
|
36
|
+
- **Container Workflows** — Modify code inside Docker containers from outside
|
|
37
|
+
- **Multi-Machine Projects** — Manage microservices across different hosts
|
|
38
|
+
- **Cloud Development** — Work on EC2/cloud VMs from your laptop
|
|
39
|
+
- **CI/CD Debugging** — Inspect and fix files on build servers
|
|
67
40
|
|
|
68
|
-
|
|
69
|
-
- npm or pnpm
|
|
41
|
+
## Quick Start
|
|
70
42
|
|
|
71
|
-
###
|
|
43
|
+
### 1. Install
|
|
72
44
|
|
|
73
45
|
```bash
|
|
74
46
|
npm install -g @willjackson/claude-code-bridge
|
|
75
47
|
```
|
|
76
48
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
### Run Without Installing
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
npx @willjackson/claude-code-bridge start
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Install from Source
|
|
49
|
+
### 2. Setup MCP (one-time)
|
|
86
50
|
|
|
87
51
|
```bash
|
|
88
|
-
|
|
89
|
-
cd claude-code-bridge
|
|
90
|
-
npm install
|
|
91
|
-
npm run build
|
|
92
|
-
npm link # Makes 'claude-bridge' available globally
|
|
52
|
+
claude mcp add bridge -- npx @willjackson/claude-code-bridge mcp-server
|
|
93
53
|
```
|
|
94
54
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
### Step 1: Install
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
npm install -g @willjackson/claude-code-bridge
|
|
101
|
-
```
|
|
55
|
+
### 3. Start Host + Claude Code
|
|
102
56
|
|
|
103
|
-
|
|
57
|
+
On your **local machine**:
|
|
104
58
|
|
|
105
59
|
```bash
|
|
106
|
-
claude
|
|
60
|
+
claude-bridge start --launch-claude
|
|
107
61
|
```
|
|
108
62
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
On your **local machine** (the host):
|
|
63
|
+
Need to skip permissions? Add flags after `--`:
|
|
112
64
|
|
|
113
65
|
```bash
|
|
114
|
-
claude-bridge start --
|
|
66
|
+
claude-bridge start --launch-claude -- --dangerously-skip-permissions
|
|
115
67
|
```
|
|
116
68
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
### Step 4: Start the Client on Remote Machine
|
|
69
|
+
### 4. Connect Remote Machine
|
|
120
70
|
|
|
121
71
|
On the **remote machine** (server, container, VM):
|
|
122
72
|
|
|
123
73
|
```bash
|
|
124
|
-
|
|
125
|
-
claude-bridge start --with-handlers --connect ws://HOST_IP:8766
|
|
74
|
+
claude-bridge start --with-handlers --connect ws://HOST_IP:8765
|
|
126
75
|
```
|
|
127
76
|
|
|
128
|
-
|
|
77
|
+
Replace `HOST_IP` with your local machine's IP address.
|
|
129
78
|
|
|
130
|
-
|
|
131
|
-
┌─────────────────────────────────────────────────────────────
|
|
132
|
-
│ 📥 INCOMING TASK: Read config file
|
|
133
|
-
│ ID: task-123
|
|
134
|
-
│ Scope: execute
|
|
135
|
-
│ Action: read_file
|
|
136
|
-
│ Path: config/settings.json
|
|
137
|
-
└─────────────────────────────────────────────────────────────
|
|
79
|
+
That's it! Claude Code now has access to files on the remote machine.
|
|
138
80
|
|
|
139
|
-
|
|
140
|
-
```
|
|
81
|
+
## What You Can Do
|
|
141
82
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
Once connected, Claude Code on your host has access to these tools:
|
|
83
|
+
Once connected, Claude Code gains these MCP tools:
|
|
145
84
|
|
|
146
85
|
| Tool | Description |
|
|
147
86
|
|------|-------------|
|
|
148
|
-
| `bridge_read_file` | Read
|
|
149
|
-
| `bridge_write_file` |
|
|
150
|
-
| `bridge_delete_file` |
|
|
151
|
-
| `bridge_list_directory` |
|
|
152
|
-
| `bridge_delegate_task` | Delegate a custom task to the client |
|
|
153
|
-
| `bridge_request_context` | Request files matching a query |
|
|
87
|
+
| `bridge_read_file` | Read any file on the remote |
|
|
88
|
+
| `bridge_write_file` | Create or modify files |
|
|
89
|
+
| `bridge_delete_file` | Remove files |
|
|
90
|
+
| `bridge_list_directory` | Browse directories |
|
|
154
91
|
| `bridge_status` | Check connection status |
|
|
155
92
|
|
|
156
|
-
##
|
|
157
|
-
|
|
158
|
-
### Global Options
|
|
93
|
+
## Client Console
|
|
159
94
|
|
|
160
|
-
|
|
161
|
-
Usage: claude-bridge [options] [command]
|
|
95
|
+
The remote client shows all incoming commands in real-time:
|
|
162
96
|
|
|
163
|
-
Options:
|
|
164
|
-
-V, --version Output the version number
|
|
165
|
-
-v, --verbose Enable verbose logging
|
|
166
|
-
--config <path> Path to config file
|
|
167
|
-
-h, --help Display help for command
|
|
168
97
|
```
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
claude-bridge start [options]
|
|
176
|
-
|
|
177
|
-
Options:
|
|
178
|
-
-p, --port <port> Port to listen on (default: 8765)
|
|
179
|
-
-h, --host <host> Host to bind to (default: 0.0.0.0)
|
|
180
|
-
-c, --connect <url> URL to connect to on startup (e.g., ws://localhost:8765)
|
|
181
|
-
-d, --daemon Run in background
|
|
182
|
-
--with-handlers Enable file operations and task handling (read/write/delete files)
|
|
183
|
-
--launch-claude Start bridge daemon and launch Claude Code
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
**Examples:**
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
# Start bridge and launch Claude Code (recommended for local use)
|
|
190
|
-
claude-bridge start --port 8766 --launch-claude
|
|
191
|
-
|
|
192
|
-
# Start with default settings
|
|
193
|
-
claude-bridge start
|
|
194
|
-
|
|
195
|
-
# Start on specific port
|
|
196
|
-
claude-bridge start --port 9000
|
|
197
|
-
|
|
198
|
-
# Start and connect to remote bridge
|
|
199
|
-
claude-bridge start --connect ws://192.168.1.100:8765
|
|
200
|
-
|
|
201
|
-
# Start in daemon mode
|
|
202
|
-
claude-bridge start --daemon
|
|
203
|
-
|
|
204
|
-
# Start with file operation handlers enabled (for remote machines)
|
|
205
|
-
claude-bridge start --with-handlers --connect ws://192.168.1.100:8766
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
### Daemon Mode
|
|
209
|
-
|
|
210
|
-
Daemon mode runs the bridge as a background process, allowing you to close your terminal while the bridge continues running.
|
|
211
|
-
|
|
212
|
-
#### Starting in Daemon Mode
|
|
213
|
-
|
|
214
|
-
```bash
|
|
215
|
-
# Start bridge in background
|
|
216
|
-
claude-bridge start --daemon
|
|
217
|
-
|
|
218
|
-
# Start with additional options
|
|
219
|
-
claude-bridge start --daemon --port 8766 --with-handlers
|
|
220
|
-
|
|
221
|
-
# Start daemon and connect to remote
|
|
222
|
-
claude-bridge start --daemon --connect ws://192.168.1.100:8765
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
When started in daemon mode, the bridge:
|
|
226
|
-
- Detaches from the terminal and runs in the background
|
|
227
|
-
- Writes its PID and status to `~/.claude-bridge/status.json`
|
|
228
|
-
- Continues running until explicitly stopped
|
|
229
|
-
|
|
230
|
-
#### Checking Daemon Status
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
claude-bridge status
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
This shows whether a daemon is running, its PID, listening port, and connected peers.
|
|
237
|
-
|
|
238
|
-
#### Stopping the Daemon
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
claude-bridge stop
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
This reads the PID from the status file and gracefully shuts down the background process.
|
|
245
|
-
|
|
246
|
-
#### Status File
|
|
247
|
-
|
|
248
|
-
The daemon writes its status to `~/.claude-bridge/status.json`:
|
|
249
|
-
|
|
250
|
-
```json
|
|
251
|
-
{
|
|
252
|
-
"running": true,
|
|
253
|
-
"pid": 12345,
|
|
254
|
-
"port": 8766,
|
|
255
|
-
"host": "0.0.0.0",
|
|
256
|
-
"instanceName": "bridge-12345",
|
|
257
|
-
"startedAt": "2024-01-15T10:30:00.000Z",
|
|
258
|
-
"peers": []
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
This file is automatically removed when the daemon stops cleanly.
|
|
263
|
-
|
|
264
|
-
#### `stop` - Stop the Running Bridge
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
claude-bridge stop
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Stops the bridge daemon if running in background mode.
|
|
271
|
-
|
|
272
|
-
#### `status` - Show Bridge Status
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
claude-bridge status [options]
|
|
276
|
-
|
|
277
|
-
Options:
|
|
278
|
-
--port <port> Check status on specific port
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
Shows:
|
|
282
|
-
- Bridge running state
|
|
283
|
-
- Listening port
|
|
284
|
-
- Connected peers
|
|
285
|
-
|
|
286
|
-
#### `connect` - Connect to Remote Bridge
|
|
287
|
-
|
|
288
|
-
```bash
|
|
289
|
-
claude-bridge connect <url>
|
|
290
|
-
|
|
291
|
-
Arguments:
|
|
292
|
-
url WebSocket URL (e.g., ws://localhost:8765)
|
|
98
|
+
┌─────────────────────────────────────────────────────
|
|
99
|
+
│ 📥 INCOMING TASK: Read config file
|
|
100
|
+
│ Action: read_file
|
|
101
|
+
│ Path: src/config.json
|
|
102
|
+
└─────────────────────────────────────────────────────
|
|
103
|
+
✅ RESULT: Read 2048 chars from src/config.json
|
|
293
104
|
```
|
|
294
105
|
|
|
295
|
-
|
|
106
|
+
## CLI Reference
|
|
296
107
|
|
|
297
108
|
```bash
|
|
298
|
-
|
|
299
|
-
claude-bridge
|
|
300
|
-
```
|
|
109
|
+
# Host mode (local machine)
|
|
110
|
+
claude-bridge start [--port 8765] [--launch-claude] [-- claude-args]
|
|
301
111
|
|
|
302
|
-
|
|
112
|
+
# Client mode (remote machine)
|
|
113
|
+
claude-bridge start --with-handlers --connect ws://HOST:PORT
|
|
303
114
|
|
|
304
|
-
|
|
305
|
-
claude-bridge
|
|
115
|
+
# Utilities
|
|
116
|
+
claude-bridge status # Check if bridge is running
|
|
117
|
+
claude-bridge stop # Stop the bridge daemon
|
|
118
|
+
claude-bridge info # Show system info
|
|
306
119
|
```
|
|
307
120
|
|
|
308
|
-
Displays:
|
|
309
|
-
- System information (Node version, OS, platform)
|
|
310
|
-
- Network interfaces
|
|
311
|
-
- Current configuration settings
|
|
312
|
-
|
|
313
121
|
## Configuration
|
|
314
122
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
Create a configuration file at one of these locations:
|
|
318
|
-
|
|
319
|
-
1. `.claude-bridge.yml` (project root)
|
|
320
|
-
2. `~/.claude-bridge/config.yml` (user home)
|
|
321
|
-
|
|
322
|
-
### Configuration Options
|
|
123
|
+
Create `~/.claude-bridge/config.yml` for persistent settings:
|
|
323
124
|
|
|
324
125
|
```yaml
|
|
325
|
-
|
|
326
|
-
instanceName: my-mac-desktop
|
|
327
|
-
mode: host # 'host' for local machine, 'client' for remote
|
|
328
|
-
|
|
329
|
-
# Server settings (host mode)
|
|
126
|
+
instanceName: my-bridge
|
|
330
127
|
listen:
|
|
331
|
-
port:
|
|
128
|
+
port: 8765
|
|
332
129
|
host: 0.0.0.0
|
|
333
|
-
|
|
334
|
-
# Connection to host (client mode)
|
|
335
|
-
connect:
|
|
336
|
-
url: ws://192.168.1.100:8766
|
|
337
|
-
|
|
338
|
-
# Context sharing settings
|
|
339
|
-
contextSharing:
|
|
340
|
-
autoSync: true
|
|
341
|
-
syncInterval: 5000 # milliseconds
|
|
342
|
-
maxChunkTokens: 4000
|
|
343
|
-
includePatterns:
|
|
344
|
-
- "src/**/*.ts"
|
|
345
|
-
- "src/**/*.tsx"
|
|
346
|
-
- "*.json"
|
|
347
|
-
excludePatterns:
|
|
348
|
-
- "node_modules/**"
|
|
349
|
-
- "dist/**"
|
|
350
|
-
- ".git/**"
|
|
351
|
-
|
|
352
|
-
# Interaction settings
|
|
353
130
|
interaction:
|
|
354
|
-
|
|
355
|
-
notifyOnActivity: true
|
|
356
|
-
taskTimeout: 300000 # 5 minutes in milliseconds
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
### Configuration Reference
|
|
360
|
-
|
|
361
|
-
| Setting | Type | Default | Description |
|
|
362
|
-
|---------|------|---------|-------------|
|
|
363
|
-
| `instanceName` | string | - | Unique name for this bridge instance |
|
|
364
|
-
| `mode` | string | - | Operation mode: `host` or `client` |
|
|
365
|
-
| `listen.port` | number | 8765 | Port to listen on (host mode) |
|
|
366
|
-
| `listen.host` | string | 0.0.0.0 | Host to bind to (host mode) |
|
|
367
|
-
| `connect.url` | string | - | WebSocket URL of host (client mode) |
|
|
368
|
-
| `contextSharing.autoSync` | boolean | true | Automatically sync context |
|
|
369
|
-
| `contextSharing.syncInterval` | number | 5000 | Sync interval in ms |
|
|
370
|
-
| `contextSharing.maxChunkTokens` | number | 4000 | Max tokens per context chunk |
|
|
371
|
-
| `contextSharing.includePatterns` | array | [...] | Glob patterns for included files |
|
|
372
|
-
| `contextSharing.excludePatterns` | array | [...] | Glob patterns for excluded files |
|
|
373
|
-
| `interaction.requireConfirmation` | boolean | false | Require user confirmation for tasks |
|
|
374
|
-
| `interaction.notifyOnActivity` | boolean | true | Show notifications on activity |
|
|
375
|
-
| `interaction.taskTimeout` | number | 300000 | Task timeout in ms |
|
|
376
|
-
|
|
377
|
-
## Programmatic Usage
|
|
378
|
-
|
|
379
|
-
### Basic Usage (Host)
|
|
380
|
-
|
|
381
|
-
```typescript
|
|
382
|
-
import { Bridge, BridgeConfig } from 'claude-code-bridge';
|
|
383
|
-
|
|
384
|
-
// Create host bridge configuration
|
|
385
|
-
const config: BridgeConfig = {
|
|
386
|
-
mode: 'host',
|
|
387
|
-
instanceName: 'my-host',
|
|
388
|
-
listen: { port: 8766, host: '0.0.0.0' },
|
|
389
|
-
taskTimeout: 300000,
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
// Create and start bridge
|
|
393
|
-
const bridge = new Bridge(config);
|
|
394
|
-
await bridge.start();
|
|
395
|
-
|
|
396
|
-
// Get connected clients
|
|
397
|
-
const clients = bridge.getPeers();
|
|
398
|
-
console.log('Connected clients:', clients);
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
### Basic Usage (Client)
|
|
402
|
-
|
|
403
|
-
```typescript
|
|
404
|
-
import { Bridge, BridgeConfig } from 'claude-code-bridge';
|
|
405
|
-
|
|
406
|
-
// Create client bridge configuration
|
|
407
|
-
const config: BridgeConfig = {
|
|
408
|
-
mode: 'client',
|
|
409
|
-
instanceName: 'my-client',
|
|
410
|
-
connect: { url: 'ws://192.168.1.100:8766' },
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
// Create and start bridge
|
|
414
|
-
const bridge = new Bridge(config);
|
|
415
|
-
await bridge.start();
|
|
416
|
-
|
|
417
|
-
// Register task handler for file operations
|
|
418
|
-
bridge.onTaskReceived(async (task, peerId) => {
|
|
419
|
-
console.log('Received task:', task.description);
|
|
420
|
-
// Handle the task...
|
|
421
|
-
return { success: true, data: { message: 'Done' } };
|
|
422
|
-
});
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### Context Synchronization
|
|
426
|
-
|
|
427
|
-
```typescript
|
|
428
|
-
// Send context to connected peers
|
|
429
|
-
await bridge.syncContext({
|
|
430
|
-
files: [
|
|
431
|
-
{ path: 'src/api.ts', content: 'export const api = {...}' },
|
|
432
|
-
{ path: 'src/types.ts', content: 'export interface User {...}' },
|
|
433
|
-
],
|
|
434
|
-
summary: 'API client implementation files',
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
// Handle incoming context
|
|
438
|
-
bridge.onContextReceived((context) => {
|
|
439
|
-
console.log('Received context:', context.summary);
|
|
440
|
-
for (const file of context.files || []) {
|
|
441
|
-
console.log(` - ${file.path}`);
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
// Request specific context from peer
|
|
446
|
-
const chunks = await bridge.requestContext('authentication logic');
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
### Task Delegation
|
|
450
|
-
|
|
451
|
-
```typescript
|
|
452
|
-
// Delegate a task to the connected peer
|
|
453
|
-
const result = await bridge.delegateTask({
|
|
454
|
-
id: 'task-001',
|
|
455
|
-
description: 'Refactor the UserService to use dependency injection',
|
|
456
|
-
scope: 'execute', // 'execute', 'analyze', or 'suggest'
|
|
457
|
-
constraints: ['Maintain backward compatibility', 'Add unit tests'],
|
|
458
|
-
timeout: 60000, // 1 minute
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
if (result.success) {
|
|
462
|
-
console.log('Task completed:', result.data);
|
|
463
|
-
for (const artifact of result.artifacts || []) {
|
|
464
|
-
console.log(` ${artifact.action}: ${artifact.path}`);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// Handle incoming tasks
|
|
469
|
-
bridge.onTaskReceived(async (task) => {
|
|
470
|
-
console.log('Received task:', task.description);
|
|
471
|
-
|
|
472
|
-
// Process the task...
|
|
473
|
-
|
|
474
|
-
return {
|
|
475
|
-
success: true,
|
|
476
|
-
data: { message: 'Task completed successfully' },
|
|
477
|
-
artifacts: [
|
|
478
|
-
{ path: 'src/UserService.ts', action: 'modified' },
|
|
479
|
-
],
|
|
480
|
-
};
|
|
481
|
-
});
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
### Remote File Operations
|
|
485
|
-
|
|
486
|
-
When connected to a peer running with `--with-handlers`, you can perform file operations:
|
|
487
|
-
|
|
488
|
-
```typescript
|
|
489
|
-
// Read a file from the remote peer
|
|
490
|
-
const readResult = await bridge.delegateTask({
|
|
491
|
-
id: 'read-1',
|
|
492
|
-
description: 'Read config file',
|
|
493
|
-
scope: 'execute',
|
|
494
|
-
data: {
|
|
495
|
-
action: 'read_file',
|
|
496
|
-
path: 'config/settings.json',
|
|
497
|
-
},
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
if (readResult.success) {
|
|
501
|
-
console.log('File content:', readResult.data.content);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Write a file to the remote peer
|
|
505
|
-
const writeResult = await bridge.delegateTask({
|
|
506
|
-
id: 'write-1',
|
|
507
|
-
description: 'Create new file',
|
|
508
|
-
scope: 'execute',
|
|
509
|
-
data: {
|
|
510
|
-
action: 'write_file',
|
|
511
|
-
path: 'src/newfile.ts',
|
|
512
|
-
content: 'export const hello = "world";',
|
|
513
|
-
},
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
console.log('Bytes written:', writeResult.data.bytesWritten);
|
|
517
|
-
|
|
518
|
-
// Delete a file on the remote peer
|
|
519
|
-
const deleteResult = await bridge.delegateTask({
|
|
520
|
-
id: 'delete-1',
|
|
521
|
-
description: 'Remove temp file',
|
|
522
|
-
scope: 'execute',
|
|
523
|
-
data: {
|
|
524
|
-
action: 'delete_file',
|
|
525
|
-
path: 'temp/cache.json',
|
|
526
|
-
},
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
// Edit a file (read, modify, write back)
|
|
530
|
-
const file = await bridge.delegateTask({
|
|
531
|
-
id: 'edit-read',
|
|
532
|
-
description: 'Read file for editing',
|
|
533
|
-
scope: 'execute',
|
|
534
|
-
data: { action: 'read_file', path: 'README.md' },
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
const newContent = file.data.content.replace('old text', 'new text');
|
|
538
|
-
|
|
539
|
-
await bridge.delegateTask({
|
|
540
|
-
id: 'edit-write',
|
|
541
|
-
description: 'Write edited file',
|
|
542
|
-
scope: 'execute',
|
|
543
|
-
data: { action: 'write_file', path: 'README.md', content: newContent },
|
|
544
|
-
});
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
**Available file operations:**
|
|
548
|
-
|
|
549
|
-
| Action | Data Fields | Description |
|
|
550
|
-
|--------|-------------|-------------|
|
|
551
|
-
| `read_file` | `path` | Read file content from remote |
|
|
552
|
-
| `write_file` | `path`, `content` | Create or overwrite a file |
|
|
553
|
-
| `delete_file` | `path` | Delete a file |
|
|
554
|
-
|
|
555
|
-
> **Security Note:** All file operations are restricted to the project directory where the bridge is running. Paths outside the project root are rejected.
|
|
556
|
-
|
|
557
|
-
### Context Manager
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
import { ContextManager } from 'claude-code-bridge';
|
|
561
|
-
|
|
562
|
-
const contextManager = new ContextManager({
|
|
563
|
-
rootPath: '/path/to/project',
|
|
564
|
-
includePatterns: ['src/**/*.ts', '*.json'],
|
|
565
|
-
excludePatterns: ['node_modules/**', 'dist/**'],
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
// Generate a project snapshot
|
|
569
|
-
const snapshot = await contextManager.generateSnapshot();
|
|
570
|
-
console.log('Project files:', snapshot.keyFiles);
|
|
571
|
-
|
|
572
|
-
// Get relevant context for a task
|
|
573
|
-
const chunks = await contextManager.getRelevantContext(
|
|
574
|
-
'user authentication',
|
|
575
|
-
4000 // max tokens
|
|
576
|
-
);
|
|
577
|
-
|
|
578
|
-
// Get changes since last sync
|
|
579
|
-
const delta = await contextManager.getDelta(previousSnapshotId);
|
|
580
|
-
for (const change of delta.changes) {
|
|
581
|
-
console.log(`${change.action}: ${change.path}`);
|
|
582
|
-
}
|
|
131
|
+
taskTimeout: 300000
|
|
583
132
|
```
|
|
584
133
|
|
|
585
134
|
## Troubleshooting
|
|
586
135
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
136
|
+
**Can't connect?**
|
|
137
|
+
- Verify the host is running: `claude-bridge status`
|
|
138
|
+
- Check firewall allows port 8765
|
|
139
|
+
- Confirm IP is reachable: `ping HOST_IP`
|
|
590
140
|
|
|
591
|
-
**
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
3. Verify the IP address is correct and reachable: `ping HOST_IP`
|
|
595
|
-
4. Ensure you're using the correct WebSocket URL format: `ws://HOST_IP:8766`
|
|
141
|
+
**Commands not executing?**
|
|
142
|
+
- Ensure client uses `--with-handlers`
|
|
143
|
+
- Check client console for errors
|
|
596
144
|
|
|
597
|
-
**
|
|
145
|
+
**Need more detail?**
|
|
146
|
+
- Run with verbose logging: `claude-bridge start -v`
|
|
598
147
|
|
|
599
|
-
|
|
600
|
-
1. Check network stability between host and client
|
|
601
|
-
2. Increase timeout settings in config
|
|
602
|
-
3. Enable verbose logging: `claude-bridge start -v`
|
|
603
|
-
|
|
604
|
-
**Problem:** Commands not showing on client
|
|
605
|
-
|
|
606
|
-
**Solutions:**
|
|
607
|
-
1. Ensure client is started with `--with-handlers` flag
|
|
608
|
-
2. Check the client console for connection status
|
|
609
|
-
3. Verify the host shows the client as connected: `claude-bridge status`
|
|
610
|
-
|
|
611
|
-
### Port Conflicts
|
|
612
|
-
|
|
613
|
-
**Problem:** Port already in use
|
|
614
|
-
|
|
615
|
-
**Solutions:**
|
|
616
|
-
1. Use a different port: `claude-bridge start --port 9000`
|
|
617
|
-
2. Find and stop the process using the port:
|
|
618
|
-
```bash
|
|
619
|
-
lsof -i :8765
|
|
620
|
-
kill <PID>
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
### Debugging
|
|
624
|
-
|
|
625
|
-
Enable verbose logging for detailed output:
|
|
626
|
-
|
|
627
|
-
```bash
|
|
628
|
-
claude-bridge start -v
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
Or set the log level via environment variable:
|
|
632
|
-
|
|
633
|
-
```bash
|
|
634
|
-
LOG_LEVEL=debug claude-bridge start
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
## Development
|
|
638
|
-
|
|
639
|
-
### Prerequisites
|
|
148
|
+
## Requirements
|
|
640
149
|
|
|
641
150
|
- Node.js 20+
|
|
642
|
-
-
|
|
643
|
-
|
|
644
|
-
### Setup
|
|
645
|
-
|
|
646
|
-
```bash
|
|
647
|
-
# Clone the repository
|
|
648
|
-
git clone https://github.com/willjackson/claude-code-bridge.git
|
|
649
|
-
cd claude-code-bridge
|
|
650
|
-
|
|
651
|
-
# Install dependencies
|
|
652
|
-
npm install
|
|
653
|
-
|
|
654
|
-
# Build
|
|
655
|
-
npm run build
|
|
656
|
-
|
|
657
|
-
# Run tests
|
|
658
|
-
npm test
|
|
659
|
-
|
|
660
|
-
# Run tests in watch mode
|
|
661
|
-
npm run test:watch
|
|
662
|
-
|
|
663
|
-
# Type checking
|
|
664
|
-
npm run lint
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
### Project Structure
|
|
668
|
-
|
|
669
|
-
```
|
|
670
|
-
claude-code-bridge/
|
|
671
|
-
├── src/
|
|
672
|
-
│ ├── index.ts # Main exports
|
|
673
|
-
│ ├── bridge/
|
|
674
|
-
│ │ ├── core.ts # Bridge class
|
|
675
|
-
│ │ ├── protocol.ts # Message types & validation
|
|
676
|
-
│ │ ├── messages.ts # Message builders
|
|
677
|
-
│ │ └── context.ts # Context manager
|
|
678
|
-
│ ├── transport/
|
|
679
|
-
│ │ ├── interface.ts # Transport abstraction
|
|
680
|
-
│ │ └── websocket.ts # WebSocket implementation
|
|
681
|
-
│ ├── cli/
|
|
682
|
-
│ │ ├── index.ts # CLI entry point
|
|
683
|
-
│ │ └── commands/ # CLI commands
|
|
684
|
-
│ └── utils/
|
|
685
|
-
│ ├── logger.ts # Logging utility
|
|
686
|
-
│ ├── config.ts # Configuration loading
|
|
687
|
-
│ └── tokens.ts # Token estimation
|
|
688
|
-
├── tests/
|
|
689
|
-
│ ├── unit/ # Unit tests
|
|
690
|
-
│ ├── integration/ # Integration tests
|
|
691
|
-
│ └── e2e/ # End-to-end tests
|
|
692
|
-
```
|
|
693
|
-
|
|
694
|
-
### Running Tests
|
|
695
|
-
|
|
696
|
-
```bash
|
|
697
|
-
# Run all tests
|
|
698
|
-
npm test
|
|
699
|
-
|
|
700
|
-
# Run with coverage
|
|
701
|
-
npm run test:coverage
|
|
702
|
-
|
|
703
|
-
# Run specific test file
|
|
704
|
-
npm test -- tests/unit/bridge/protocol.test.ts
|
|
705
|
-
|
|
706
|
-
# Run tests matching pattern
|
|
707
|
-
npm test -- --grep "WebSocket"
|
|
708
|
-
```
|
|
151
|
+
- Claude Code with MCP support
|
|
709
152
|
|
|
710
153
|
## License
|
|
711
154
|
|
|
712
|
-
MIT
|
|
713
|
-
|
|
714
|
-
## Contributing
|
|
715
|
-
|
|
716
|
-
1. Fork the repository
|
|
717
|
-
2. Create a feature branch: `git checkout -b feature/my-feature`
|
|
718
|
-
3. Make your changes
|
|
719
|
-
4. Run tests: `npm test`
|
|
720
|
-
5. Commit: `git commit -m 'Add my feature'`
|
|
721
|
-
6. Push: `git push origin feature/my-feature`
|
|
722
|
-
7. Open a Pull Request
|
|
155
|
+
MIT
|
|
723
156
|
|
|
724
|
-
##
|
|
157
|
+
## Links
|
|
725
158
|
|
|
726
|
-
-
|
|
159
|
+
- [npm package](https://www.npmjs.com/package/@willjackson/claude-code-bridge)
|
|
160
|
+
- [Report issues](https://github.com/willjackson/claude-code-bridge/issues)
|