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