@radnine/claude-session-daemon 0.2.4 → 0.2.7

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,119 @@
1
+ # @radnine/claude-session-daemon
2
+
3
+ Node.js daemon that manages Claude CLI sessions over WebSocket. Pairs with [@radnine/storybook-addon-claude](https://www.npmjs.com/package/@radnine/storybook-addon-claude) to give designers and developers an AI chat panel inside Storybook.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @radnine/storybook-addon-claude @radnine/claude-session-daemon
9
+ ```
10
+
11
+ ## Configure Storybook
12
+
13
+ In your `.storybook/main.js`:
14
+
15
+ ```js
16
+ export default {
17
+ addons: [
18
+ '@radnine/storybook-addon-claude',
19
+ // ... other addons
20
+ ],
21
+ };
22
+ ```
23
+
24
+ ## Run the Daemon
25
+
26
+ ### Option A: Docker (recommended)
27
+
28
+ Docker runs Claude inside a container with filesystem isolation. Claude can only access your mounted project directory, so file edits happen automatically without permission prompts.
29
+
30
+ 1. Create a `docker-compose.yml` in your project root:
31
+
32
+ ```yaml
33
+ services:
34
+ claude-daemon:
35
+ image: ghcr.io/radixhound/claude-daemon:latest
36
+ build:
37
+ context: ./node_modules/@radnine/claude-session-daemon
38
+ ports:
39
+ - "${CLAUDE_DAEMON_PORT:-3001}:3001"
40
+ volumes:
41
+ - .:/workspace
42
+ environment:
43
+ - ANTHROPIC_API_KEY
44
+ - CLAUDE_DAEMON_MODE=standalone
45
+ - CLAUDE_WORKING_DIR=/workspace
46
+ - CLAUDE_DAEMON_PORT=3001
47
+ - CLAUDE_SKIP_PERMISSIONS=true
48
+ - CLAUDE_DISABLE_AUTH=true
49
+ stop_grace_period: 10s
50
+ restart: unless-stopped
51
+ ```
52
+
53
+ 2. Add your API key to a `.env` file:
54
+
55
+ ```
56
+ ANTHROPIC_API_KEY=sk-ant-...
57
+ ```
58
+
59
+ Get an API key from https://console.anthropic.com/settings/keys
60
+
61
+ 3. Start it:
62
+
63
+ ```bash
64
+ docker compose up -d
65
+ ```
66
+
67
+ Stop with `docker compose down`.
68
+
69
+ ### Option B: Host mode
70
+
71
+ Runs the daemon directly on your machine. Claude will prompt for permission on each file edit since there's no filesystem isolation.
72
+
73
+ ```bash
74
+ npx @radnine/claude-session-daemon start
75
+ ```
76
+
77
+ Or add to your `package.json` scripts:
78
+
79
+ ```json
80
+ {
81
+ "scripts": {
82
+ "claude-daemon": "claude-session-daemon start",
83
+ "claude-daemon:stop": "claude-session-daemon stop",
84
+ "claude-daemon:restart": "claude-session-daemon restart",
85
+ "claude-daemon:status": "claude-session-daemon status"
86
+ }
87
+ }
88
+ ```
89
+
90
+ The daemon manages a `.claude-daemon.pid` file in your project root. Add it to your `.gitignore`.
91
+
92
+ ### Authentication (host mode only)
93
+
94
+ Docker mode uses the `ANTHROPIC_API_KEY` environment variable. For host mode, choose one:
95
+
96
+ **API Key** — Set `ANTHROPIC_API_KEY` before starting the daemon, or add it to a `.env` file.
97
+
98
+ **Claude Login** — If you have a Claude Pro, Team, or Enterprise subscription:
99
+
100
+ ```bash
101
+ npx @anthropic-ai/claude-code login
102
+ ```
103
+
104
+ This authenticates via your browser. Credentials are stored locally and the daemon uses them automatically.
105
+
106
+ ## Environment Variables
107
+
108
+ | Variable | Default | Description |
109
+ |---|---|---|
110
+ | `ANTHROPIC_API_KEY` | — | Required for Docker mode |
111
+ | `CLAUDE_DAEMON_PORT` | `3001` | WebSocket server port |
112
+ | `CLAUDE_MAX_SESSIONS` | `10` | Max concurrent Claude sessions |
113
+ | `CLAUDE_LOG_LEVEL` | `info` | Log level (`debug`, `info`, `warn`, `error`) |
114
+ | `CLAUDE_SKIP_PERMISSIONS` | `false` | Skip Claude CLI permission prompts (Docker only) |
115
+ | `CLAUDE_DISABLE_AUTH` | `false` | Disable WebSocket auth (Docker only) |
116
+
117
+ ## License
118
+
119
+ Proprietary. See [LICENSE](./LICENSE) for terms.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radnine/claude-session-daemon",
3
- "version": "0.2.4",
3
+ "version": "0.2.7",
4
4
  "description": "Node.js daemon for managing Claude CLI sessions",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -25,6 +25,7 @@ class ClaudeProcess extends EventEmitter {
25
25
  * @param {string} [options.claudeSessionId] - UUID for --session-id flag
26
26
  * @param {object} [options.logger] - Logger instance
27
27
  * @param {string} [options.claudeCommand] - Path to claude binary
28
+ * @param {boolean} [options.skipPermissions] - Pass --dangerously-skip-permissions (only safe in Docker)
28
29
  * @param {Function} [options._spawnFn] - For testing: replacement for child_process.spawn
29
30
  */
30
31
  constructor(sessionId, options = {}) {
@@ -35,6 +36,7 @@ class ClaudeProcess extends EventEmitter {
35
36
  this._workingDir = options.workingDir || process.cwd();
36
37
  this._logger = options.logger || _defaultLogger();
37
38
  this._claudeCommand = options.claudeCommand || 'claude';
39
+ this._skipPermissions = options.skipPermissions || false;
38
40
  this._spawnFn = options._spawnFn || defaultSpawn;
39
41
 
40
42
  this._state = 'idle';
@@ -64,9 +66,12 @@ class ClaudeProcess extends EventEmitter {
64
66
  '--output-format', 'stream-json',
65
67
  '--session-id', this._claudeSessionId,
66
68
  '--replay-user-messages',
67
- '--dangerously-skip-permissions',
68
69
  ];
69
70
 
71
+ if (this._skipPermissions) {
72
+ args.push('--dangerously-skip-permissions');
73
+ }
74
+
70
75
  const env = { ...process.env, CLAUDE_SESSION_ID: this._sessionId };
71
76
  delete env.CLAUDECODE; // Prevent nested session detection
72
77
 
package/src/config.js CHANGED
@@ -51,6 +51,9 @@ function loadConfig() {
51
51
 
52
52
  // Daemon identifier (generated at runtime if not set)
53
53
  daemonId: env.CLAUDE_DAEMON_ID || null,
54
+
55
+ // Skip Claude CLI permission prompts (only safe inside Docker containers)
56
+ skipPermissions: env.CLAUDE_SKIP_PERMISSIONS === 'true',
54
57
  };
55
58
 
56
59
  // Validate mode
@@ -149,9 +149,10 @@ class StandaloneServer extends BaseConnection {
149
149
 
150
150
  _handleConnection(ws, req) {
151
151
  const isLocalhost = this._isLocalhostConnection(req);
152
+ const authDisabled = process.env.CLAUDE_DISABLE_AUTH === 'true';
152
153
 
153
- // Validate auth token from query param (skip for localhost)
154
- if (!isLocalhost) {
154
+ // Validate auth token from query param (skip for localhost or when auth disabled in Docker)
155
+ if (!isLocalhost && !authDisabled) {
155
156
  let token = null;
156
157
  try {
157
158
  const url = new URL(req.url, `http://localhost:${this.port}`);
package/src/daemon.js CHANGED
@@ -147,6 +147,7 @@ class Daemon extends EventEmitter {
147
147
  const proc = this._createProcess(sessionId, {
148
148
  workingDir: options.workingDir || this._config.workingDir,
149
149
  claudeSessionId: options.claudeSessionId,
150
+ skipPermissions: this._config.skipPermissions,
150
151
  logger: this._logger.child(`Session:${sessionId}`),
151
152
  });
152
153