@bramblex/codex-workbench 0.1.19 → 0.1.20

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 CHANGED
@@ -18,7 +18,7 @@ codex-workbench is an **interactive terminal UI** for coding-agent sessions. Ins
18
18
 
19
19
  It also connects to **remote machines over SSH**, so you can manage sessions across all your servers from a single pane of glass.
20
20
 
21
- Built-in backends currently include [Codex](https://github.com/openai/codex), pi, and opencode. The backend layer is intentionally provider-based so additional agents can be added without changing the TUI workflow.
21
+ Built-in backends currently include [Codex](https://github.com/openai/codex), Claude Code, pi, and opencode. The backend layer is intentionally provider-based so additional agents can be added without changing the TUI workflow.
22
22
 
23
23
  A handful of CLI subcommands are available for scripting, but the TUI is the product.
24
24
 
@@ -136,6 +136,7 @@ codex-workbench auto-detects installed backends by checking each backend's sessi
136
136
  | Backend | Sessions | Binary override | Notes |
137
137
  |---------|----------|-----------------|-------|
138
138
  | `codex` | `$CODEX_SESSIONS_DIR` or `~/.codex/sessions` | `CODEX_BIN` | Uses the Codex CLI for new, resume, fork, archive, unarchive, and delete. |
139
+ | `claude` | `$CLAUDE_PROJECTS_DIR` or `~/.claude/projects` | `CLAUDE_BIN` | Uses the Claude Code CLI for new, resume, and fork. Archive/unarchive use workbench metadata; delete removes the session file. |
139
140
  | `pi` | `$PI_CODING_AGENT_SESSION_DIR` or `$PI_CODING_AGENT_DIR/sessions` | `PI_BIN` | Uses the pi CLI for new, resume, and fork. Archive/unarchive use workbench metadata; delete removes the session file. |
140
141
  | `opencode` | `$OPENCODE_DB`, `$OPENCODE_DATA_DIR/opencode.db`, or `~/.local/share/opencode/opencode.db` | `OPENCODE_BIN` | Uses the opencode CLI and database for list, new, resume, fork, archive, unarchive, and delete. |
141
142
 
@@ -165,6 +166,7 @@ cwb fork <session>
165
166
  cwb delete <session> --force
166
167
 
167
168
  cwb new --cwd ~/projects/foo --backend codex "Summarize this repo"
169
+ cwb new --cwd ~/projects/foo --backend claude "Summarize this repo"
168
170
  cwb new --cwd ~/projects/foo --backend pi "Summarize this repo"
169
171
  cwb new --cwd ~/projects/foo --backend opencode "Summarize this repo"
170
172
  cwb resume <session> "what was the conclusion about the rate limiter?"
@@ -191,6 +193,8 @@ When you run `new` or `resume`, the selected backend takes over the terminal. Wh
191
193
  | `CWB_CONFIG` | `$CWB_HOME/config.json` | SSH remote sources config |
192
194
  | `CODEX_HOME` | `~/.codex` | Codex data directory |
193
195
  | `CODEX_SESSIONS_DIR` | `$CODEX_HOME/sessions` | Session JSONL files |
196
+ | `CLAUDE_HOME` | `~/.claude` | Claude Code data directory |
197
+ | `CLAUDE_PROJECTS_DIR` | `$CLAUDE_HOME/projects` | Claude Code project session JSONL files |
194
198
  | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | pi coding agent data directory |
195
199
  | `PI_CODING_AGENT_SESSION_DIR` | `$PI_CODING_AGENT_DIR/sessions` | pi session JSONL files |
196
200
  | `OPENCODE_DATA_DIR` | `~/.local/share/opencode` | opencode data directory |
@@ -198,6 +202,7 @@ When you run `new` or `resume`, the selected backend takes over the terminal. Wh
198
202
  | `CODEX_WORKBENCH_META` | unset | Legacy override for `CWB_META` |
199
203
  | `CODEX_WORKBENCH_CONFIG` | unset | Legacy override for `CWB_CONFIG` |
200
204
  | `CODEX_BIN` | auto-detected | Force a specific Codex executable |
205
+ | `CLAUDE_BIN` | auto-detected | Force a specific Claude Code executable |
201
206
  | `PI_BIN` | auto-detected | Force a specific pi executable |
202
207
  | `OPENCODE_BIN` | auto-detected | Force a specific opencode executable |
203
208
 
@@ -223,6 +228,10 @@ Run `codex-workbench doctor` to see where codex-workbench is looking. Common fix
223
228
 
224
229
  Make sure you've run Codex at least once. Sessions are stored as `.jsonl` files under `$CODEX_SESSIONS_DIR`. Run `ls ~/.codex/sessions/` to verify.
225
230
 
231
+ ### No Claude Code sessions appear
232
+
233
+ Make sure you've run Claude Code at least once. Sessions are stored as `.jsonl` files under `$CLAUDE_PROJECTS_DIR`. Run `find ~/.claude/projects -name '*.jsonl'` to verify.
234
+
226
235
  ### No pi sessions appear
227
236
 
228
237
  Make sure you've run the pi coding agent at least once. Sessions are stored as `.jsonl` files under `$PI_CODING_AGENT_SESSION_DIR` or `$PI_CODING_AGENT_DIR/sessions`. Run `ls ~/.pi/agent/sessions/` to verify.
@@ -293,6 +302,7 @@ src/
293
302
  workbench-config.js # SSH remote source config loader
294
303
  providers/
295
304
  codex.js # Codex provider
305
+ claude.js # Claude Code provider
296
306
  pi.js # pi provider
297
307
  opencode.js # opencode provider
298
308
  index.js # provider registry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bramblex/codex-workbench",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Terminal workbench for browsing and managing local and SSH Codex sessions.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/cli-output.js CHANGED
@@ -31,6 +31,8 @@ Environment:
31
31
  CWB_CONFIG default: $CWB_HOME/config.json
32
32
  CODEX_HOME default: ~/.codex
33
33
  CODEX_SESSIONS_DIR default: $CODEX_HOME/sessions
34
+ CLAUDE_HOME default: ~/.claude
35
+ CLAUDE_PROJECTS_DIR default: $CLAUDE_HOME/projects
34
36
  PI_CODING_AGENT_DIR default: ~/.pi/agent
35
37
  PI_CODING_AGENT_SESSION_DIR default: $PI_CODING_AGENT_DIR/sessions
36
38
  OPENCODE_DATA_DIR default: ~/.local/share/opencode
@@ -38,6 +40,7 @@ Environment:
38
40
  CODEX_WORKBENCH_META legacy override for CWB_META
39
41
  CODEX_WORKBENCH_CONFIG legacy override for CWB_CONFIG
40
42
  CODEX_BIN default: codex from shell PATH
43
+ CLAUDE_BIN default: claude from shell PATH
41
44
  PI_BIN default: pi from shell PATH
42
45
  OPENCODE_BIN default: opencode from shell PATH
43
46
  `);
@@ -0,0 +1,283 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Claude Code provider – session parsing, binary discovery, and CLI operations
5
+ // ---------------------------------------------------------------------------
6
+
7
+ const fs = require('fs');
8
+ const os = require('os');
9
+ const path = require('path');
10
+ const { spawn, spawnSync } = require('child_process');
11
+ const { removeMetadata, updateMetadata } = require('../model/metadata');
12
+
13
+ const HOME = os.homedir();
14
+ const CLAUDE_HOME = process.env.CLAUDE_HOME || path.join(HOME, '.claude');
15
+ const CLAUDE_PROJECTS_DIR = process.env.CLAUDE_PROJECTS_DIR || path.join(CLAUDE_HOME, 'projects');
16
+
17
+ function shellQuote(value) {
18
+ return `'${String(value).replace(/'/g, "'\\''")}'`;
19
+ }
20
+
21
+ function isExecutable(file) {
22
+ try { fs.accessSync(file, fs.constants.X_OK); return true; } catch { return false; }
23
+ }
24
+
25
+ function findOnPath(command, pathValue) {
26
+ for (const dir of (pathValue || process.env.PATH || '').split(path.delimiter)) {
27
+ if (!dir) continue;
28
+ const candidate = path.join(dir, command);
29
+ if (isExecutable(candidate)) return candidate;
30
+ }
31
+ return null;
32
+ }
33
+
34
+ function executableFromOutput(output) {
35
+ for (const line of String(output || '').split(/\r?\n/)) {
36
+ const candidate = line.trim();
37
+ if (candidate && path.isAbsolute(candidate) && isExecutable(candidate)) return candidate;
38
+ }
39
+ return null;
40
+ }
41
+
42
+ function runShellLookup(shell, shellArgs, command, env) {
43
+ const result = spawnSync(shell, [...shellArgs, `command -v ${shellQuote(command)}`], {
44
+ encoding: 'utf8',
45
+ env,
46
+ stdio: ['ignore', 'pipe', 'pipe'],
47
+ });
48
+ if (result.error || result.status !== 0) return null;
49
+ return executableFromOutput(result.stdout);
50
+ }
51
+
52
+ function findWithShell(command, env) {
53
+ const shell = (env || process.env).SHELL || '/bin/sh';
54
+ if (!isExecutable(shell)) return null;
55
+ return runShellLookup(shell, ['-lc'], command, env) ||
56
+ runShellLookup(shell, ['-ic'], command, env);
57
+ }
58
+
59
+ function resolveClaudeBin() {
60
+ const env = process.env;
61
+ if (env.CLAUDE_BIN) {
62
+ if (isExecutable(env.CLAUDE_BIN)) return env.CLAUDE_BIN;
63
+ throw new Error(`CLAUDE_BIN is not executable: ${env.CLAUDE_BIN}`);
64
+ }
65
+ const fromShell = findWithShell('claude', env);
66
+ if (fromShell) return fromShell;
67
+ const fromPath = findOnPath('claude', env.PATH);
68
+ if (fromPath) return fromPath;
69
+ throw new Error('Could not find the claude executable. Set CLAUDE_BIN or add claude to PATH.');
70
+ }
71
+
72
+ function commandShell() {
73
+ const shell = process.env.SHELL || '/bin/sh';
74
+ try { fs.accessSync(shell, fs.constants.X_OK); return shell; } catch { return '/bin/sh'; }
75
+ }
76
+
77
+ function usableCwd(dir) {
78
+ for (const candidate of [dir, process.cwd(), HOME]) {
79
+ if (!candidate || candidate === '(unknown)') continue;
80
+ try { if (fs.statSync(candidate).isDirectory()) return candidate; } catch { /* skip */ }
81
+ }
82
+ return HOME;
83
+ }
84
+
85
+ function walk(dir, out) {
86
+ out = out || [];
87
+ let entries;
88
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return out; }
89
+ for (const entry of entries) {
90
+ const full = path.join(dir, entry.name);
91
+ if (entry.isDirectory()) walk(full, out);
92
+ else if (entry.isFile() && entry.name.endsWith('.jsonl')) out.push(full);
93
+ }
94
+ return out;
95
+ }
96
+
97
+ function textFromContent(content) {
98
+ if (typeof content === 'string') return content.trim();
99
+ if (!Array.isArray(content)) return '';
100
+ return content
101
+ .map((item) => {
102
+ if (!item) return '';
103
+ if (typeof item === 'string') return item;
104
+ if (item.type === 'text') return item.text || '';
105
+ if (item.type === 'tool_result') return '';
106
+ return '';
107
+ })
108
+ .filter(Boolean)
109
+ .join(' ')
110
+ .replace(/\s+/g, ' ')
111
+ .trim();
112
+ }
113
+
114
+ function firstUserText(messages) {
115
+ const message = messages.find((msg) => msg.role === 'user');
116
+ return message ? message.text : '';
117
+ }
118
+
119
+ function lastText(messages, role) {
120
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
121
+ if (!role || messages[i].role === role) return messages[i].text;
122
+ }
123
+ return '';
124
+ }
125
+
126
+ function isNoiseUserText(text) {
127
+ return /^<local-command-/.test(text) ||
128
+ /^<command-name>/.test(text) ||
129
+ text.includes('<environment_context>') ||
130
+ text.includes('<permissions instructions>');
131
+ }
132
+
133
+ function emptySession(file, stat) {
134
+ return {
135
+ id: path.basename(file, '.jsonl'),
136
+ file,
137
+ cwd: '(unknown)',
138
+ startedAt: stat.birthtime?.toISOString() || null,
139
+ updatedAt: stat.mtime.toISOString(),
140
+ cliVersion: '',
141
+ provider: '',
142
+ turns: 0,
143
+ first: '',
144
+ last: '',
145
+ lastAssistant: '',
146
+ messages: [],
147
+ backend: 'claude',
148
+ };
149
+ }
150
+
151
+ function parseSession(file) {
152
+ const stat = fs.statSync(file);
153
+ const raw = fs.readFileSync(file, 'utf8').trim();
154
+ if (!raw) return emptySession(file, stat);
155
+
156
+ const messages = [];
157
+ let id = path.basename(file, '.jsonl');
158
+ let cwd = '';
159
+ let startedAt = '';
160
+ let updatedAt = stat.mtime.toISOString();
161
+ let cliVersion = '';
162
+ let provider = '';
163
+ let turns = 0;
164
+
165
+ for (const line of raw.split(/\n/)) {
166
+ let row;
167
+ try { row = JSON.parse(line); } catch { continue; }
168
+
169
+ if (row.sessionId) id = row.sessionId;
170
+ if (row.cwd) cwd = row.cwd;
171
+ if (row.version) cliVersion = row.version;
172
+ if (row.timestamp) {
173
+ if (!startedAt) startedAt = row.timestamp;
174
+ updatedAt = row.timestamp;
175
+ }
176
+
177
+ if ((row.type === 'user' || row.type === 'assistant') && row.message) {
178
+ const role = row.message.role || row.type;
179
+ const text = textFromContent(row.message.content);
180
+ if (!text) continue;
181
+ if (role === 'user' && isNoiseUserText(text)) continue;
182
+ messages.push({ role, text });
183
+ if (role === 'user') turns += 1;
184
+ if (!provider && role === 'assistant' && row.message.model) provider = row.message.model;
185
+ }
186
+ }
187
+
188
+ return {
189
+ id,
190
+ file,
191
+ cwd: cwd || '(unknown)',
192
+ startedAt: startedAt || stat.birthtime?.toISOString() || null,
193
+ updatedAt,
194
+ cliVersion,
195
+ provider,
196
+ turns,
197
+ first: firstUserText(messages),
198
+ last: lastText(messages, 'user'),
199
+ lastAssistant: lastText(messages, 'assistant'),
200
+ messages,
201
+ backend: 'claude',
202
+ };
203
+ }
204
+
205
+ function runArgv(argv, cwd, inherit) {
206
+ const shellCommand = `exec ${argv.map(shellQuote).join(' ')}`;
207
+ const shell = commandShell();
208
+ if (inherit) {
209
+ const child = spawn(shell, ['-lc', shellCommand], { stdio: 'inherit', cwd, env: process.env });
210
+ child.on('error', (err) => { console.error(`error: failed to start claude: ${err.message}`); process.exit(1); });
211
+ child.on('exit', (code, signal) => { if (signal) process.kill(process.pid, signal); process.exit(code || 0); });
212
+ return undefined;
213
+ }
214
+ const result = spawnSync(shell, ['-lc', shellCommand], { stdio: 'inherit', cwd, env: process.env });
215
+ if (result.error) throw new Error(`failed to start claude: ${result.error.message}`);
216
+ const status = typeof result.status === 'number' ? result.status : 1;
217
+ process.exitCode = status;
218
+ return status;
219
+ }
220
+
221
+ function runSessionCommand(command, session, args, inherit) {
222
+ const executable = resolveClaudeBin();
223
+ const cwd = usableCwd(session.cwd);
224
+ switch (command) {
225
+ case 'resume': {
226
+ const argv = [executable, '--resume', session.id];
227
+ if (args && args.length) argv.push(args.join(' '));
228
+ return runArgv(argv, cwd, inherit);
229
+ }
230
+ case 'fork': {
231
+ return runArgv([executable, '--resume', session.id, '--fork-session'], cwd, inherit);
232
+ }
233
+ case 'delete': {
234
+ fs.unlinkSync(session.file);
235
+ removeMetadata(session);
236
+ return 0;
237
+ }
238
+ case 'archive':
239
+ case 'unarchive': {
240
+ updateMetadata(session, { archived: command === 'archive' });
241
+ return 0;
242
+ }
243
+ default:
244
+ throw new Error(`Unknown command for claude backend: ${command}`);
245
+ }
246
+ }
247
+
248
+ function runNew(cwd, args, inherit) {
249
+ const argv = [resolveClaudeBin(), ...(args || [])];
250
+ return runArgv(argv, usableCwd(cwd), inherit);
251
+ }
252
+
253
+ function isAvailable() {
254
+ try { return fs.statSync(CLAUDE_PROJECTS_DIR).isDirectory(); } catch { return false; }
255
+ }
256
+
257
+ function getSessionFiles() {
258
+ return walk(CLAUDE_PROJECTS_DIR);
259
+ }
260
+
261
+ function resolveBin() {
262
+ try { return resolveClaudeBin(); } catch { return null; }
263
+ }
264
+
265
+ module.exports = {
266
+ id: 'claude',
267
+ label: 'Claude Code',
268
+ capabilities: {
269
+ new: true,
270
+ resume: true,
271
+ fork: true,
272
+ archive: true,
273
+ unarchive: true,
274
+ delete: true,
275
+ },
276
+ isAvailable,
277
+ getSessionFiles,
278
+ parseSession,
279
+ resolveBin,
280
+ runCommand: runSessionCommand,
281
+ runNew,
282
+ resolveClaudeBin,
283
+ };
@@ -5,10 +5,11 @@
5
5
  // ---------------------------------------------------------------------------
6
6
 
7
7
  const codex = require('./codex');
8
+ const claude = require('./claude');
8
9
  const opencode = require('./opencode');
9
10
  const pi = require('./pi');
10
11
 
11
- const ALL_PROVIDERS = [codex, pi, opencode];
12
+ const ALL_PROVIDERS = [codex, pi, opencode, claude];
12
13
  const providerMap = new Map(ALL_PROVIDERS.map((p) => [p.id, p]));
13
14
 
14
15
  /**
@@ -59,6 +60,7 @@ module.exports = {
59
60
  getProvider,
60
61
  providerForSession,
61
62
  getAllSessionFiles,
63
+ claude,
62
64
  codex,
63
65
  opencode,
64
66
  pi,
@@ -24,6 +24,35 @@ function findOnPath(command, pathValue) {
24
24
  return null;
25
25
  }
26
26
 
27
+ function shellQuote(value) {
28
+ return `'${String(value).replace(/'/g, "'\\''")}'`;
29
+ }
30
+
31
+ function executableFromOutput(output) {
32
+ for (const line of String(output || '').split(/\r?\n/)) {
33
+ const candidate = line.trim();
34
+ if (candidate && path.isAbsolute(candidate) && isExecutable(candidate)) return candidate;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ function runShellLookup(shell, shellArgs, command, env) {
40
+ const result = spawnSync(shell, [...shellArgs, `command -v ${shellQuote(command)}`], {
41
+ encoding: 'utf8',
42
+ env,
43
+ stdio: ['ignore', 'pipe', 'pipe'],
44
+ });
45
+ if (result.error || result.status !== 0) return null;
46
+ return executableFromOutput(result.stdout);
47
+ }
48
+
49
+ function findWithShell(command, env) {
50
+ const shell = (env || process.env).SHELL || '/bin/sh';
51
+ if (!isExecutable(shell)) return null;
52
+ return runShellLookup(shell, ['-lc'], command, env) ||
53
+ runShellLookup(shell, ['-ic'], command, env);
54
+ }
55
+
27
56
  function resolveOpenCodeBin() {
28
57
  if (process.env.OPENCODE_BIN) {
29
58
  if (isExecutable(process.env.OPENCODE_BIN)) return process.env.OPENCODE_BIN;
@@ -31,6 +60,8 @@ function resolveOpenCodeBin() {
31
60
  }
32
61
  const fromPath = findOnPath('opencode', process.env.PATH);
33
62
  if (fromPath) return fromPath;
63
+ const fromShell = findWithShell('opencode', process.env);
64
+ if (fromShell) return fromShell;
34
65
  throw new Error('Could not find the opencode executable. Set OPENCODE_BIN or add opencode to PATH.');
35
66
  }
36
67
 
@@ -227,6 +227,7 @@ async function runWorkbench() {
227
227
  const styledListLabel = (color, text) => `{${color}-fg}{bold}${blessed.escape(text)}{/}`;
228
228
 
229
229
  const backendThemes = {
230
+ claude: 'yellow',
230
231
  codex: 'cyan',
231
232
  pi: 'magenta',
232
233
  opencode: 'green',