claude-code-runner 0.1.0

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.
Files changed (51) hide show
  1. package/README.md +559 -0
  2. package/README.zh-Hans.md +559 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +377 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config.d.ts +4 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +50 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/container.d.ts +23 -0
  12. package/dist/container.d.ts.map +1 -0
  13. package/dist/container.js +971 -0
  14. package/dist/container.js.map +1 -0
  15. package/dist/credentials.d.ts +8 -0
  16. package/dist/credentials.d.ts.map +1 -0
  17. package/dist/credentials.js +145 -0
  18. package/dist/credentials.js.map +1 -0
  19. package/dist/docker-config.d.ts +19 -0
  20. package/dist/docker-config.d.ts.map +1 -0
  21. package/dist/docker-config.js +101 -0
  22. package/dist/docker-config.js.map +1 -0
  23. package/dist/git/shadow-repository.d.ts +30 -0
  24. package/dist/git/shadow-repository.d.ts.map +1 -0
  25. package/dist/git/shadow-repository.js +645 -0
  26. package/dist/git/shadow-repository.js.map +1 -0
  27. package/dist/git-monitor.d.ts +15 -0
  28. package/dist/git-monitor.d.ts.map +1 -0
  29. package/dist/git-monitor.js +94 -0
  30. package/dist/git-monitor.js.map +1 -0
  31. package/dist/index.d.ts +22 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +221 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/types.d.ts +49 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +3 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/ui.d.ts +12 -0
  40. package/dist/ui.d.ts.map +1 -0
  41. package/dist/ui.js +82 -0
  42. package/dist/ui.js.map +1 -0
  43. package/dist/web-server-attach.d.ts +16 -0
  44. package/dist/web-server-attach.d.ts.map +1 -0
  45. package/dist/web-server-attach.js +249 -0
  46. package/dist/web-server-attach.js.map +1 -0
  47. package/dist/web-server.d.ts +27 -0
  48. package/dist/web-server.d.ts.map +1 -0
  49. package/dist/web-server.js +812 -0
  50. package/dist/web-server.js.map +1 -0
  51. package/package.json +77 -0
package/README.md ADDED
@@ -0,0 +1,559 @@
1
+ [English](#) | [简体中文](./README.zh-Hans.md)
2
+
3
+ # Claude Code Runner
4
+
5
+ > [!WARNING]
6
+ >
7
+ > - This work is alpha and might have security issues, use at your own risk.
8
+ > - Email [admin@soraharu.com](mailto:admin@soraharu.com) for inquiries.
9
+
10
+ Run Claude Code as an autonomous agent inside Docker containers with automatic GitHub integration. Bypass all permissions safely.
11
+
12
+ ## Why Claude Code Runner?
13
+
14
+ The primary goal of Claude Code Runner is to enable **full async agentic workflows** by allowing Claude Code to execute without permission prompts. By running Claude in an isolated Docker container with the `--dangerously-skip-permissions` flag, Claude can:
15
+
16
+ - Execute any command instantly without asking for permission
17
+ - Make code changes autonomously
18
+ - Run build tools, tests, and development servers
19
+ - Create commits and manage git operations
20
+ - Work continuously without interrupting the user
21
+
22
+ Access Claude through a **browser-based terminal** that lets you monitor and interact with the AI assistant while you work on other tasks. This creates a truly autonomous development assistant, similar to [OpenAI Codex](https://chatgpt.com/codex) or [Google Jules](https://jules.dev), but running locally on your machine with full control.
23
+
24
+ ## Overview
25
+
26
+ Claude Code Runner allows you to run Claude Code in isolated Docker containers, providing a safe environment for AI-assisted development. It automatically:
27
+
28
+ - Creates a new git branch for each session
29
+ - Monitors for commits made by Claude
30
+ - Provides interactive review of changes
31
+ - Handles credential forwarding securely
32
+ - Enables push/PR creation workflows
33
+ - Runs custom setup commands for environment initialization
34
+
35
+ ## Installation
36
+
37
+ Install Claude Code Runner globally from npm:
38
+
39
+ ```bash
40
+ npm install -g @yanranxiaoxi/claude-code-runner
41
+ ```
42
+
43
+ ### Prerequisites
44
+
45
+ - Node.js >= 22.13.0
46
+ - Docker or Podman
47
+ - Git
48
+
49
+ ## Usage
50
+
51
+ ### Quick Start
52
+
53
+ > **Tip**: For the fastest setup with pre-built image, use the official image by setting `buildImage: false` and `dockerImage: registry.gitlab.soraharu.com/xiaoxi/claude-code-runner:latest` in your config.
54
+
55
+ Simply run in any git repository:
56
+
57
+ ```bash
58
+ claude-run
59
+ ```
60
+
61
+ This will:
62
+
63
+ 1. Create a new branch (`claude/[timestamp]`)
64
+ 2. Start a Docker container with Claude Code
65
+ 3. Launch a web UI at `http://localhost:3456`
66
+ 4. Open your browser automatically
67
+
68
+ ### Commands
69
+
70
+ #### `claude-run` (default)
71
+
72
+ Start a new container with web UI (recommended):
73
+
74
+ ```bash
75
+ claude-run
76
+ ```
77
+
78
+ #### `claude-run start`
79
+
80
+ Explicitly start a new container with options:
81
+
82
+ ```bash
83
+ claude-run start [options]
84
+
85
+ Options:
86
+ -c, --config <path> Configuration file (default: ./claude-run.config.json)
87
+ -n, --name <name> Container name prefix
88
+ --no-web Disable web UI (use terminal attach)
89
+ --no-push Disable automatic branch pushing
90
+ --no-pr Disable automatic PR creation
91
+ ```
92
+
93
+ #### `claude-run attach [container-id]`
94
+
95
+ Attach to an existing container:
96
+
97
+ ```bash
98
+ # Interactive selection
99
+ claude-run attach
100
+
101
+ # Specific container
102
+ claude-run attach abc123def456
103
+
104
+ Options:
105
+ --no-web Use terminal attach instead of web UI
106
+ ```
107
+
108
+ #### `claude-run list`
109
+
110
+ List all Claude Runner containers:
111
+
112
+ ```bash
113
+ claude-run list
114
+ claude-run ls # alias
115
+
116
+ Options:
117
+ -a, --all Show all containers (including stopped)
118
+ ```
119
+
120
+ #### `claude-run stop [container-id]`
121
+
122
+ Stop containers:
123
+
124
+ ```bash
125
+ # Interactive selection
126
+ claude-run stop
127
+
128
+ # Specific container
129
+ claude-run stop abc123def456
130
+
131
+ # Stop all
132
+ claude-run stop --all
133
+ ```
134
+
135
+ #### `claude-run logs [container-id]`
136
+
137
+ View container logs:
138
+
139
+ ```bash
140
+ claude-run logs
141
+ claude-run logs abc123def456
142
+
143
+ Options:
144
+ -f, --follow Follow log output
145
+ -n, --tail <lines> Number of lines to show (default: 50)
146
+ ```
147
+
148
+ #### `claude-run clean`
149
+
150
+ Remove stopped containers:
151
+
152
+ ```bash
153
+ claude-run clean
154
+ claude-run clean --force # Remove all containers
155
+ ```
156
+
157
+ #### `claude-run config`
158
+
159
+ Show current configuration:
160
+
161
+ ```bash
162
+ claude-run config
163
+ ```
164
+
165
+ ### Configuration
166
+
167
+ Create a `claude-run.config.json` file (see `claude-run.config.example.json` for reference):
168
+
169
+ ```json
170
+ {
171
+ "dockerImage": "claude-code-runner:latest",
172
+ "dockerfile": "./custom.Dockerfile",
173
+ "detached": false,
174
+ "autoPush": true,
175
+ "autoCreatePR": true,
176
+ "autoStartClaude": true,
177
+ "envFile": ".env",
178
+ "environment": {
179
+ "NODE_ENV": "development"
180
+ },
181
+ "setupCommands": ["npm install", "npm run build"],
182
+ "volumes": ["/host/path:/container/path:ro"],
183
+ "mounts": [
184
+ {
185
+ "source": "./data",
186
+ "target": "/workspace/data",
187
+ "readonly": false
188
+ },
189
+ {
190
+ "source": "/home/user/configs",
191
+ "target": "/configs",
192
+ "readonly": true
193
+ }
194
+ ],
195
+ "allowedTools": ["*"],
196
+ "maxThinkingTokens": 100000,
197
+ "bashTimeout": 600000,
198
+ "containerPrefix": "my-project",
199
+ "claudeConfigPath": "~/.claude.json"
200
+ }
201
+ ```
202
+
203
+ #### Configuration Options
204
+
205
+ - `dockerImage`: Base Docker image to use (default: `claude-code-runner:latest`)
206
+ - `buildImage`: Build the image locally (default: true) or pull from registry (set to false)
207
+ - `dockerfile`: Path to custom Dockerfile (optional)
208
+ - `detached`: Run container in detached mode
209
+ - `autoPush`: Automatically push branches after commits
210
+ - `autoCreatePR`: Automatically create pull requests
211
+ - `autoStartClaude`: Start Claude Code automatically (default: true)
212
+ - `envFile`: Load environment variables from file (e.g., `.env`)
213
+ - `environment`: Additional environment variables
214
+ - `setupCommands`: Commands to run after container starts (e.g., install dependencies)
215
+ - `volumes`: Legacy volume mounts (string format)
216
+ - `mounts`: Modern mount configuration (object format)
217
+ - `allowedTools`: Claude tool permissions (default: all)
218
+ - `maxThinkingTokens`: Maximum thinking tokens for Claude
219
+ - `bashTimeout`: Timeout for bash commands in milliseconds
220
+ - `containerPrefix`: Custom prefix for container names
221
+ - `claudeConfigPath`: Path to Claude configuration file
222
+ - `dockerSocketPath`: Custom Docker/Podman socket path (auto-detected by default)
223
+
224
+ #### Mount Configuration
225
+
226
+ The `mounts` array allows you to mount files or directories into the container:
227
+
228
+ - `source`: Path on the host (relative paths are resolved from current directory)
229
+ - `target`: Path in the container (relative paths are resolved from /workspace)
230
+ - `readonly`: Optional boolean to make the mount read-only (default: false)
231
+
232
+ Example use cases:
233
+
234
+ - Mount data directories that shouldn't be in git
235
+ - Share configuration files between host and container
236
+ - Mount build artifacts or dependencies
237
+ - Access host system resources (use with caution)
238
+
239
+ #### Using Pre-built Container Images
240
+
241
+ By default, Claude Code Runner builds the Docker image locally. If you prefer to pull a pre-built image from a registry instead:
242
+
243
+ **Option 1: Use the Official Pre-built Image (Recommended)**
244
+
245
+ The easiest way is to use the official maintained image. Just set `buildImage: false`:
246
+
247
+ ```json
248
+ {
249
+ "buildImage": false
250
+ }
251
+ ```
252
+
253
+ The official image `registry.gitlab.soraharu.com/xiaoxi/claude-code-runner:latest` will be used automatically.
254
+
255
+ Then run:
256
+
257
+ ```bash
258
+ claude-run
259
+ ```
260
+
261
+ The official image is:
262
+ - ✅ Regularly maintained and updated
263
+ - ✅ Pre-configured and tested
264
+ - ✅ Ready to use out of the box
265
+ - ✅ Faster startup time
266
+ - ✅ No need to specify the full image URL
267
+
268
+ **Option 2: Use Your Own Custom Image**
269
+
270
+ If you maintain your own image in a registry:
271
+
272
+ ```json
273
+ {
274
+ "dockerImage": "myregistry.com/claude-code-runner:latest",
275
+ "buildImage": false
276
+ }
277
+ ```
278
+
279
+ **Option 3: Build Locally (Default)**
280
+
281
+ Build the image from the Dockerfile in your repository:
282
+
283
+ ```json
284
+ {
285
+ "dockerImage": "claude-code-runner:latest",
286
+ "buildImage": true
287
+ }
288
+ ```
289
+
290
+ This is useful for:
291
+
292
+ - **Development**: Customizing the image locally
293
+ - **Team workflows**: Building consistent environments
294
+ - **CI/CD pipelines**: Generating custom versions
295
+
296
+ ## Features
297
+
298
+ ### Podman Support
299
+
300
+ Claude Code Runner now supports Podman as an alternative to Docker. The tool automatically detects whether you're using Docker or Podman by checking for available socket paths:
301
+
302
+ - **Automatic detection**: The tool checks for Docker and Podman sockets in standard locations
303
+ - **Custom socket paths**: Use the `dockerSocketPath` configuration option to specify a custom socket
304
+ - **Environment variable**: Set `DOCKER_HOST` to override socket detection
305
+
306
+ > **Important**: If you're using Podman in rootless mode, you need to enable the Podman socket service:
307
+ >
308
+ > ```bash
309
+ > systemctl --user enable --now podman.socket
310
+ > ```
311
+ >
312
+ > Verify the socket is running:
313
+ >
314
+ > ```bash
315
+ > systemctl --user status podman.socket
316
+ > ```
317
+
318
+ Example configuration for Podman:
319
+
320
+ ```json
321
+ {
322
+ "dockerSocketPath": "/run/user/1000/podman/podman.sock"
323
+ }
324
+ ```
325
+
326
+ The tool will automatically detect and use Podman if:
327
+
328
+ - Docker socket is not available
329
+ - Podman socket is found at standard locations (`/run/podman/podman.sock` or `$XDG_RUNTIME_DIR/podman/podman.sock`)
330
+
331
+ ### Web UI Terminal
332
+
333
+ Launch a browser-based terminal interface to interact with Claude Code:
334
+
335
+ ```bash
336
+ claude-run --web
337
+ ```
338
+
339
+ This will:
340
+
341
+ - Start the container in detached mode
342
+ - Launch a web server on `http://localhost:3456`
343
+ - Open your browser automatically
344
+ - Provide a full terminal interface with:
345
+ - Real-time terminal streaming
346
+ - Copy/paste support
347
+ - Terminal resizing
348
+ - Reconnection capabilities
349
+
350
+ Perfect for when you want to monitor Claude's work while doing other tasks.
351
+
352
+ ### Automatic Credential Discovery
353
+
354
+ Claude Code Runner automatically discovers and forwards:
355
+
356
+ **Claude Credentials:**
357
+
358
+ - Anthropic API keys (`ANTHROPIC_API_KEY`)
359
+ - macOS Keychain credentials (Claude Code)
360
+ - AWS Bedrock credentials
361
+ - Google Vertex credentials
362
+ - Claude configuration files (`.claude.json`, `.claude/`)
363
+
364
+ **GitHub Credentials:**
365
+
366
+ - GitHub CLI authentication (`gh auth`)
367
+ - GitHub tokens (`GITHUB_TOKEN`, `GH_TOKEN`)
368
+ - Git configuration (`.gitconfig`)
369
+
370
+ ### Sandboxed Execution
371
+
372
+ - Claude runs with `--dangerously-skip-permissions` flag (safe in container)
373
+ - Creates isolated branch for each session
374
+ - Full access to run any command within the container
375
+ - Files are copied into container (not mounted) for true isolation
376
+ - Git history preserved for proper version control
377
+
378
+ ### Commit Monitoring
379
+
380
+ When Claude makes a commit:
381
+
382
+ 1. Real-time notification appears
383
+ 2. Full diff is displayed with syntax highlighting
384
+ 3. Interactive menu offers options:
385
+ - Continue working
386
+ - Push branch to remote
387
+ - Push branch and create PR
388
+ - Exit
389
+
390
+ ### Working with Multiple Containers
391
+
392
+ Run multiple Claude instances simultaneously:
393
+
394
+ ```bash
395
+ # Terminal 1: Start main development
396
+ claude-run start --name main-dev
397
+
398
+ # Terminal 2: Start feature branch work
399
+ claude-run start --name feature-auth
400
+
401
+ # Terminal 3: List all running containers
402
+ claude-run list
403
+
404
+ # Terminal 4: Attach to any container
405
+ claude-run attach
406
+ ```
407
+
408
+ ## Docker Environment
409
+
410
+ ### Default Image
411
+
412
+ The default Docker image includes:
413
+
414
+ - Ubuntu 22.04
415
+ - Git, GitHub CLI
416
+ - Node.js, npm
417
+ - Python 3
418
+ - Claude Code (latest)
419
+ - Build essentials
420
+
421
+ ### Custom Dockerfile
422
+
423
+ Create a custom environment:
424
+
425
+ ```dockerfile
426
+ FROM claude-code-runner:latest
427
+
428
+ # Add your tools
429
+ RUN apt-get update && apt-get install -y \
430
+ rust \
431
+ cargo \
432
+ postgresql-client
433
+
434
+ # Install project dependencies
435
+ COPY package.json /tmp/
436
+ RUN cd /tmp && npm install
437
+
438
+ # Custom configuration
439
+ ENV CUSTOM_VAR=value
440
+ ```
441
+
442
+ Reference in config:
443
+
444
+ ```json
445
+ {
446
+ "dockerfile": "./my-custom.Dockerfile"
447
+ }
448
+ ```
449
+
450
+ ## Workflow Example
451
+
452
+ 1. **Start Claude Runner:**
453
+
454
+ ```bash
455
+ cd my-project
456
+ claude-run
457
+ ```
458
+
459
+ 2. **Interact with Claude:**
460
+
461
+ ```
462
+ > Help me refactor the authentication module to use JWT tokens
463
+ ```
464
+
465
+ 3. **Claude works autonomously:**
466
+
467
+ - Explores codebase
468
+ - Makes changes
469
+ - Runs tests
470
+ - Commits changes
471
+
472
+ 4. **Review and push:**
473
+ - See commit notification
474
+ - Review syntax-highlighted diff
475
+ - Choose to push and create PR
476
+
477
+ ## Security Considerations
478
+
479
+ - Credentials are mounted read-only
480
+ - Containers are isolated from host
481
+ - Branch restrictions prevent accidental main branch modifications
482
+ - All changes require explicit user approval before pushing
483
+
484
+ ## Troubleshooting
485
+
486
+ ### Docker permission issues
487
+
488
+ Add your user to the docker group:
489
+
490
+ ```bash
491
+ sudo usermod -aG docker $USER
492
+ # Log out and back in for changes to take effect
493
+ ```
494
+
495
+ ### Container cleanup
496
+
497
+ Remove all Claude Runner containers and images:
498
+
499
+ ```bash
500
+ npm run purge-containers
501
+ ```
502
+
503
+ ### Credential discovery fails
504
+
505
+ Set credentials explicitly:
506
+
507
+ ```bash
508
+ export ANTHROPIC_API_KEY=your-key
509
+ export GITHUB_TOKEN=your-token
510
+ ```
511
+
512
+ Or use an `.env` file with `envFile` config option.
513
+
514
+ ### Build errors
515
+
516
+ Ensure you're using Node.js >= 22.13.0:
517
+
518
+ ```bash
519
+ node --version
520
+ ```
521
+
522
+ ## Development
523
+
524
+ ### Building from Source
525
+
526
+ To build and develop Claude Code Runner from source:
527
+
528
+ ```bash
529
+ git clone https://gitlab.soraharu.com/XiaoXi/claude-code-runner.git
530
+ cd claude-code-runner
531
+ npm install
532
+ npm run build
533
+ npm link # Creates global 'claude-run' command
534
+ ```
535
+
536
+ ### Available Scripts
537
+
538
+ - `npm run build` - Build TypeScript to JavaScript
539
+ - `npm run dev` - Watch mode for development
540
+ - `npm start` - Build and run the CLI
541
+ - `npm run lint` - Run ESLint
542
+ - `npm run fix` - Run ESLint and fix formatting errors
543
+ - `npm run purge-containers` - Clean up all containers
544
+
545
+ ## Contributing
546
+
547
+ 1. Fork the repository
548
+ 2. Create a feature branch
549
+ 3. Make your changes
550
+ 4. Run linter: `npm run lint`
551
+ 5. Submit a pull request
552
+
553
+ ## Acknowledgments
554
+
555
+ [claude-code-sandbox](https://github.com/textcortex/claude-code-sandbox)
556
+
557
+ ## License
558
+
559
+ MIT