@betrue/openclaw-claude-code-plugin 1.0.3 → 1.0.5
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 +152 -470
- package/dist/index.js +46 -42
- package/openclaw.plugin.json +7 -0
- package/package.json +14 -5
package/README.md
CHANGED
|
@@ -2,102 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
**An OpenClaw plugin that orchestrates Claude Code sessions as managed background processes.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Launch, monitor, and interact with multiple Claude Code SDK sessions directly from any OpenClaw channel (Telegram, Discord, etc.). Turn OpenClaw into a control plane for autonomous coding agents — launch tasks, stream output in real time, send follow-up messages, resume previous conversations, and catch up on missed output — all without leaving your chat interface.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[](https://youtube.com/shorts/vbX1Y0Nx4Tc)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- [Features](#features)
|
|
12
|
-
- [Architecture](#architecture)
|
|
13
|
-
- [Installation](#installation)
|
|
14
|
-
- [Configuration](#configuration)
|
|
15
|
-
- [Usage](#usage)
|
|
16
|
-
- [Chat Commands](#chat-commands)
|
|
17
|
-
- [Agent Tools](#agent-tools)
|
|
18
|
-
- [Gateway RPC Methods](#gateway-rpc-methods)
|
|
19
|
-
- [API Reference](#api-reference)
|
|
20
|
-
- [Tools](#tools)
|
|
21
|
-
- [Commands](#commands)
|
|
22
|
-
- [RPC Methods](#rpc-methods)
|
|
23
|
-
- [Notification System](#notification-system)
|
|
24
|
-
- [Skill Example: Coding Agent Workflow](#skill-example-coding-agent-workflow)
|
|
25
|
-
- [Development](#development)
|
|
9
|
+
*Orchestrating two parallel Claude Code agents from Telegram — building an X clone and an Instagram clone simultaneously.*
|
|
26
10
|
|
|
27
11
|
---
|
|
28
12
|
|
|
29
13
|
## Features
|
|
30
14
|
|
|
31
|
-
- **Multi-session management** — Run up to N concurrent
|
|
32
|
-
- **Foreground / background model** — Sessions run in the background by default
|
|
33
|
-
- **Foreground catchup** — When
|
|
34
|
-
- **Multi-turn conversations** —
|
|
35
|
-
- **Session resume & fork** — Resume any completed session
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
- **Triple interface** — Every operation
|
|
42
|
-
- **Automatic cleanup** — Completed sessions
|
|
43
|
-
- **Agent event triggers** — When a session completes or becomes idle waiting for input, an OpenClaw system event is fired so the AI agent can immediately process the result or provide follow-up instructions.
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Architecture
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
┌─────────────────────────────────────────────────────┐
|
|
51
|
-
│ index.ts │
|
|
52
|
-
│ (Plugin entry point) │
|
|
53
|
-
│ Registers tools, commands, RPC methods, service │
|
|
54
|
-
└──────────────┬──────────────────────────────────────┘
|
|
55
|
-
│
|
|
56
|
-
┌────────┼─────────────────┐
|
|
57
|
-
│ │ │
|
|
58
|
-
▼ ▼ ▼
|
|
59
|
-
Tools Commands Gateway RPC
|
|
60
|
-
(8) (8) (5 methods)
|
|
61
|
-
│ │ │
|
|
62
|
-
└────────┼─────────────────┘
|
|
63
|
-
│
|
|
64
|
-
▼
|
|
65
|
-
┌─────────────┐ ┌────────────────────┐
|
|
66
|
-
│ shared.ts │────▶│ SessionManager │
|
|
67
|
-
│ (globals, │ │ (spawn, resolve, │
|
|
68
|
-
│ helpers) │ │ kill, cleanup, │
|
|
69
|
-
│ │ │ metrics, persist)│
|
|
70
|
-
└─────────────┘ └────────┬───────────┘
|
|
71
|
-
│
|
|
72
|
-
┌────────┴───────────┐
|
|
73
|
-
│ Session │
|
|
74
|
-
│ (Claude SDK │
|
|
75
|
-
│ query() wrapper, │
|
|
76
|
-
│ message stream, │
|
|
77
|
-
│ abort, output) │
|
|
78
|
-
└────────────────────┘
|
|
79
|
-
│
|
|
80
|
-
┌────────┴───────────┐
|
|
81
|
-
│ NotificationRouter │
|
|
82
|
-
│ (foreground │
|
|
83
|
-
│ streaming, │
|
|
84
|
-
│ catchup display, │
|
|
85
|
-
│ completion, │
|
|
86
|
-
│ session-limit, │
|
|
87
|
-
│ long-run remind) │
|
|
88
|
-
└────────────────────┘
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Key Components
|
|
92
|
-
|
|
93
|
-
| Component | File | Responsibility |
|
|
94
|
-
|---|---|---|
|
|
95
|
-
| **Session** | `src/session.ts` | Wraps the Claude Agent SDK `query()` call. Manages the async message stream, output buffering (last 200 blocks), abort control, multi-turn `MessageStream`, idle timeouts, waiting-for-input detection (end-of-turn + 15s safety-net timer with `waitingForInputFired` guard), and event callbacks (`onOutput`, `onToolUse`, `onComplete`, `onSessionLimitReached`). |
|
|
96
|
-
| **SessionManager** | `src/session-manager.ts` | Manages the pool of active sessions. Enforces `maxSessions`, generates unique names, wires notification callbacks, persists Claude session IDs for resume, records metrics, triggers agent events on completion and waiting-for-input, and runs periodic garbage collection. |
|
|
97
|
-
| **NotificationRouter** | `src/notifications.ts` | Routes events to the right chat channels. Debounces foreground text streaming (500ms), shows compact tool-use indicators, sends completion/failure/session-limit notifications, foreground catchup display, and periodically checks for sessions running longer than 10 minutes. |
|
|
98
|
-
| **Gateway** | `src/gateway.ts` | Exposes 5 JSON-RPC methods for external/programmatic access. |
|
|
99
|
-
| **Shared** | `src/shared.ts` | Global singletons (`sessionManager`, `notificationRouter`, `pluginConfig`), helper functions (name generation, duration formatting, session listing, stats formatting), and channel resolution logic. |
|
|
100
|
-
| **Types** | `src/types.ts` | TypeScript interfaces: `SessionConfig`, `ClaudeSession`, `PluginConfig`, `SessionStatus`, `PermissionMode`. |
|
|
15
|
+
- **Multi-session management** — Run up to N concurrent sessions (configurable), each with a unique ID and human-readable name
|
|
16
|
+
- **Foreground / background model** — Sessions run in the background by default; bring any session to the foreground to stream output in real time
|
|
17
|
+
- **Foreground catchup** — When foregrounding, missed background output is displayed before live streaming begins
|
|
18
|
+
- **Multi-turn conversations** — Sessions are multi-turn by default; send follow-up messages, refine instructions, or have iterative dialogues with a running agent. Set `multi_turn_disabled: true` for fire-and-forget sessions
|
|
19
|
+
- **Session resume & fork** — Resume any completed session or fork it into a new branch of conversation
|
|
20
|
+
- **Pre-launch safety checks** — Four mandatory guards (autonomy skill, heartbeat config, HEARTBEAT.md, agentChannels mapping) ensure every agent is properly configured before spawning sessions
|
|
21
|
+
- **Real-time notifications** — Completion alerts, budget exhaustion warnings, long-running reminders, and live tool-use indicators
|
|
22
|
+
- **Background visibility** — See `🔔 Claude asks:` and `↩️ Responded:` in-channel even when sessions run in the background
|
|
23
|
+
- **Waiting-for-input wake events** — `openclaw system event` fired when sessions become idle, waking the orchestrator agent
|
|
24
|
+
- **Multi-agent support** — Route notifications to the correct agent/chat via `agentChannels` workspace mapping with longest-prefix matching
|
|
25
|
+
- **Triple interface** — Every operation available as a chat command, agent tool, and gateway RPC method
|
|
26
|
+
- **Automatic cleanup** — Completed sessions garbage-collected after 1 hour; persisted IDs survive for resume
|
|
101
27
|
|
|
102
28
|
---
|
|
103
29
|
|
|
@@ -109,7 +35,7 @@ Claude Code Plugin lets you launch, monitor, and interact with multiple Claude C
|
|
|
109
35
|
openclaw plugins install @betrue/openclaw-claude-code-plugin
|
|
110
36
|
```
|
|
111
37
|
|
|
112
|
-
### From source
|
|
38
|
+
### From source
|
|
113
39
|
|
|
114
40
|
```bash
|
|
115
41
|
git clone git@github.com:alizarion/openclaw-claude-code-plugin.git
|
|
@@ -135,22 +61,55 @@ Ensure `openclaw` CLI is available in your PATH — the plugin shells out to `op
|
|
|
135
61
|
|
|
136
62
|
---
|
|
137
63
|
|
|
64
|
+
## Pre-Launch Safety Checks
|
|
65
|
+
|
|
66
|
+
When an agent calls the `claude_launch` tool, four mandatory guards run before any session is spawned. If any check fails, the launch is blocked and an actionable error message is returned telling the agent exactly how to fix the issue. These checks are enforced only on the `claude_launch` tool — the gateway RPC `claude-code.launch` method and `/claude` chat command skip them.
|
|
67
|
+
|
|
68
|
+
### 1. Autonomy Skill
|
|
69
|
+
|
|
70
|
+
**Checks for:** `{agentWorkspace}/skills/claude-code-autonomy/SKILL.md`
|
|
71
|
+
|
|
72
|
+
The autonomy skill defines how the agent handles Claude Code interactions (auto-respond to routine questions, forward architecture decisions to the user, etc.). Without it, the agent is told to ask the user what level of autonomy they want, then create the skill directory with `SKILL.md` and `autonomy.md`.
|
|
73
|
+
|
|
74
|
+
### 2. Heartbeat Configuration
|
|
75
|
+
|
|
76
|
+
**Checks for:** `heartbeat` field in `~/.openclaw/openclaw.json` under `agents.list[]` for the current agent (resolved from `ctx.agentId` or `resolveAgentId(workdir)` via the `agentChannels` mapping).
|
|
77
|
+
|
|
78
|
+
Heartbeat enables automatic "waiting for input" notifications so the agent gets nudged when a Claude Code session needs attention. The expected config:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{ "heartbeat": { "every": "5s", "target": "last" } }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 3. HEARTBEAT.md Content
|
|
85
|
+
|
|
86
|
+
**Checks for:** `{agentWorkspace}/HEARTBEAT.md` with real content (not just comments, blank lines, or whitespace — validated via regex `/^(\s|#.*)*$/`).
|
|
87
|
+
|
|
88
|
+
The heartbeat file tells the agent what to do during heartbeat cycles — e.g. check for waiting Claude Code sessions, read their output, and respond or notify the user.
|
|
89
|
+
|
|
90
|
+
### 4. agentChannels Mapping
|
|
91
|
+
|
|
92
|
+
**Checks for:** A matching entry in `pluginConfig.agentChannels` for the session's working directory, resolved via `resolveAgentChannel(workdir)`.
|
|
93
|
+
|
|
94
|
+
The workspace must be mapped to a notification channel so session events (completion, waiting-for-input, etc.) reach the correct agent/chat. Uses longest-prefix matching with trailing slash normalisation.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
138
98
|
## Configuration
|
|
139
99
|
|
|
140
|
-
Configuration is defined in `openclaw.plugin.json`
|
|
100
|
+
Configuration is defined in `openclaw.plugin.json` and passed to the plugin via `api.getConfig()`. Set values in `~/.openclaw/openclaw.json` under `plugins.config["openclaw-claude-code-plugin"]`.
|
|
141
101
|
|
|
142
102
|
| Option | Type | Default | Description |
|
|
143
103
|
|---|---|---|---|
|
|
144
|
-
| `maxSessions` | `number` | `5` |
|
|
145
|
-
| `defaultBudgetUsd` | `number` | `5` | Default max budget in USD
|
|
146
|
-
| `defaultModel` | `string` | — | Default model
|
|
147
|
-
| `defaultWorkdir` | `string` | — | Default working directory
|
|
148
|
-
| `idleTimeoutMinutes` | `number` | `30` | Idle timeout for multi-turn sessions
|
|
149
|
-
| `maxPersistedSessions` | `number` | `50` |
|
|
150
|
-
| `fallbackChannel` | `string` | — | Fallback notification channel (e.g. `"telegram
|
|
151
|
-
| `permissionMode` | `string` | `"bypassPermissions"` | Default permission mode
|
|
152
|
-
|
|
153
|
-
### Example configuration
|
|
104
|
+
| `maxSessions` | `number` | `5` | Max concurrently active sessions. |
|
|
105
|
+
| `defaultBudgetUsd` | `number` | `5` | Default max budget per session in USD. |
|
|
106
|
+
| `defaultModel` | `string` | — | Default model (e.g. `"sonnet"`, `"opus"`). |
|
|
107
|
+
| `defaultWorkdir` | `string` | — | Default working directory. Falls back to `process.cwd()`. |
|
|
108
|
+
| `idleTimeoutMinutes` | `number` | `30` | Idle timeout for multi-turn sessions before auto-kill. |
|
|
109
|
+
| `maxPersistedSessions` | `number` | `50` | Max completed sessions kept for resume. |
|
|
110
|
+
| `fallbackChannel` | `string` | — | Fallback notification channel (e.g. `"telegram\|123456789"`). |
|
|
111
|
+
| `permissionMode` | `string` | `"bypassPermissions"` | Default permission mode: `"default"`, `"plan"`, `"acceptEdits"`, `"bypassPermissions"`. |
|
|
112
|
+
| `agentChannels` | `Record<string, string>` | — | Map workdir paths to notification channels. See [Agent Channels](docs/AGENT_CHANNELS.md). |
|
|
154
113
|
|
|
155
114
|
```json
|
|
156
115
|
{
|
|
@@ -158,439 +117,162 @@ Configuration is defined in `openclaw.plugin.json` under `configSchema` and pass
|
|
|
158
117
|
"defaultBudgetUsd": 10,
|
|
159
118
|
"defaultModel": "sonnet",
|
|
160
119
|
"defaultWorkdir": "/home/user/projects",
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
|
|
120
|
+
"permissionMode": "bypassPermissions",
|
|
121
|
+
"fallbackChannel": "telegram|main-bot|123456789",
|
|
122
|
+
"agentChannels": {
|
|
123
|
+
"/home/user/agent-seo": "telegram|seo-bot|123456789",
|
|
124
|
+
"/home/user/agent-main": "telegram|main-bot|123456789"
|
|
125
|
+
}
|
|
165
126
|
}
|
|
166
127
|
```
|
|
167
128
|
|
|
168
129
|
---
|
|
169
130
|
|
|
170
|
-
## Usage
|
|
131
|
+
## Quick Usage
|
|
171
132
|
|
|
172
133
|
### Chat Commands
|
|
173
134
|
|
|
174
|
-
Commands are invoked by humans in chat (Telegram, Discord, etc.) with a `/` prefix.
|
|
175
|
-
|
|
176
135
|
```
|
|
177
136
|
/claude Fix the authentication bug in src/auth.ts
|
|
178
|
-
/claude --name fix-auth Fix the authentication bug
|
|
137
|
+
/claude --name fix-auth Fix the authentication bug
|
|
179
138
|
/claude_sessions
|
|
180
139
|
/claude_fg fix-auth
|
|
181
|
-
/
|
|
140
|
+
/claude_respond fix-auth Also add unit tests
|
|
141
|
+
/claude_respond --interrupt fix-auth Stop that and do this instead
|
|
182
142
|
/claude_bg fix-auth
|
|
183
143
|
/claude_kill fix-auth
|
|
184
|
-
/
|
|
185
|
-
/
|
|
144
|
+
/claude_resume fix-auth Add error handling
|
|
145
|
+
/claude_resume --fork fix-auth Try a different approach
|
|
186
146
|
/claude_resume --list
|
|
187
|
-
/claude_resume fix-auth Add error handling to the login flow
|
|
188
|
-
/claude_resume --fork fix-auth Try a completely different approach
|
|
189
147
|
/claude_stats
|
|
190
148
|
```
|
|
191
149
|
|
|
192
150
|
### Agent Tools
|
|
193
151
|
|
|
194
|
-
Tools
|
|
152
|
+
Tools receive the calling agent's context automatically. Channel resolution is handled internally — **no `channel` parameter** is exposed on any tool. The parameter `multi_turn_disabled` (not `multi_turn`) controls single-turn mode.
|
|
195
153
|
|
|
196
154
|
```
|
|
197
155
|
claude_launch(prompt: "Fix auth bug", workdir: "/app", name: "fix-auth")
|
|
198
|
-
claude_launch(prompt: "
|
|
199
|
-
claude_launch(prompt: "Continue", resume_session_id: "abc123", fork_session: true)
|
|
156
|
+
claude_launch(prompt: "Quick check", multi_turn_disabled: true)
|
|
200
157
|
claude_sessions(status: "running")
|
|
158
|
+
claude_output(session: "fix-auth", lines: 20)
|
|
201
159
|
claude_output(session: "fix-auth", full: true)
|
|
202
|
-
claude_fg(session: "fix-auth"
|
|
203
|
-
claude_bg(session: "fix-auth"
|
|
160
|
+
claude_fg(session: "fix-auth")
|
|
161
|
+
claude_bg(session: "fix-auth")
|
|
162
|
+
claude_respond(session: "fix-auth", message: "Also add tests")
|
|
163
|
+
claude_respond(session: "fix-auth", message: "Do this instead", interrupt: true)
|
|
204
164
|
claude_kill(session: "fix-auth")
|
|
205
|
-
claude_respond(session: "fix-auth", message: "Also add tests", interrupt: false)
|
|
206
165
|
claude_stats()
|
|
207
166
|
```
|
|
208
167
|
|
|
209
|
-
### Gateway RPC
|
|
210
|
-
|
|
211
|
-
RPC methods are called by external clients (dashboards, APIs, other plugins) via the OpenClaw gateway.
|
|
168
|
+
### Gateway RPC
|
|
212
169
|
|
|
213
170
|
```json
|
|
214
|
-
// Launch a session
|
|
215
171
|
{ "method": "claude-code.launch", "params": { "prompt": "Fix auth", "workdir": "/app" } }
|
|
216
|
-
|
|
217
|
-
// List sessions
|
|
218
172
|
{ "method": "claude-code.sessions", "params": { "status": "running" } }
|
|
219
|
-
|
|
220
|
-
// Get output
|
|
221
173
|
{ "method": "claude-code.output", "params": { "session": "fix-auth", "full": true } }
|
|
222
|
-
|
|
223
|
-
// Kill a session
|
|
224
174
|
{ "method": "claude-code.kill", "params": { "session": "fix-auth" } }
|
|
225
|
-
|
|
226
|
-
// Get stats
|
|
227
175
|
{ "method": "claude-code.stats" }
|
|
228
176
|
```
|
|
229
177
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
## API Reference
|
|
233
|
-
|
|
234
|
-
### Tools
|
|
235
|
-
|
|
236
|
-
#### `claude_launch`
|
|
237
|
-
|
|
238
|
-
Launch a new Claude Code session.
|
|
239
|
-
|
|
240
|
-
| Parameter | Type | Required | Description |
|
|
241
|
-
|---|---|---|---|
|
|
242
|
-
| `prompt` | `string` | Yes | The task prompt to execute. |
|
|
243
|
-
| `name` | `string` | No | Human-readable name (kebab-case). Auto-generated from prompt if omitted. |
|
|
244
|
-
| `workdir` | `string` | No | Working directory. Defaults to config `defaultWorkdir` or `cwd`. |
|
|
245
|
-
| `model` | `string` | No | Model name (e.g. `"sonnet"`, `"opus"`). |
|
|
246
|
-
| `max_budget_usd` | `number` | No | Maximum budget in USD. Default: `5`. |
|
|
247
|
-
| `system_prompt` | `string` | No | Additional system prompt appended to the session. |
|
|
248
|
-
| `allowed_tools` | `string[]` | No | Explicit list of allowed tools. |
|
|
249
|
-
| `resume_session_id` | `string` | No | Claude session ID (or name/internal ID) to resume from. |
|
|
250
|
-
| `fork_session` | `boolean` | No | Fork instead of continuing when resuming. |
|
|
251
|
-
| `multi_turn` | `boolean` | No | Enable multi-turn mode for follow-up messages via `claude_respond`. |
|
|
252
|
-
| `permission_mode` | `string` | No | One of `"default"`, `"plan"`, `"acceptEdits"`, `"bypassPermissions"`. |
|
|
253
|
-
| `channel` | `string` | No | Origin channel for notifications (e.g. `"telegram:123456789"`). Prevents `"unknown"` routing. |
|
|
254
|
-
|
|
255
|
-
#### `claude_sessions`
|
|
256
|
-
|
|
257
|
-
List all sessions with status and progress.
|
|
258
|
-
|
|
259
|
-
| Parameter | Type | Required | Description |
|
|
260
|
-
|---|---|---|---|
|
|
261
|
-
| `status` | `string` | No | Filter: `"all"` (default), `"running"`, `"completed"`, `"failed"`. |
|
|
262
|
-
|
|
263
|
-
#### `claude_output`
|
|
264
|
-
|
|
265
|
-
Show output from a session.
|
|
266
|
-
|
|
267
|
-
| Parameter | Type | Required | Description |
|
|
268
|
-
|---|---|---|---|
|
|
269
|
-
| `session` | `string` | Yes | Session name or ID. |
|
|
270
|
-
| `lines` | `number` | No | Number of recent lines to show (default 50). |
|
|
271
|
-
| `full` | `boolean` | No | Show all available output (up to 200 buffered blocks). |
|
|
272
|
-
|
|
273
|
-
#### `claude_fg`
|
|
274
|
-
|
|
275
|
-
Bring a session to foreground — displays any missed background output under a "📋 Catchup (N missed outputs):" header, then starts streaming new output to the current channel in real time.
|
|
276
|
-
|
|
277
|
-
| Parameter | Type | Required | Description |
|
|
278
|
-
|---|---|---|---|
|
|
279
|
-
| `session` | `string` | Yes | Session name or ID. |
|
|
280
|
-
| `lines` | `number` | No | Number of recent buffered lines to show (default 30). |
|
|
281
|
-
| `channel` | `string` | No | Target channel for streaming (e.g. `"telegram:123456789"`). Prevents `"unknown"` routing. |
|
|
282
|
-
|
|
283
|
-
#### `claude_bg`
|
|
284
|
-
|
|
285
|
-
Send a session back to background (stop streaming).
|
|
286
|
-
|
|
287
|
-
| Parameter | Type | Required | Description |
|
|
288
|
-
|---|---|---|---|
|
|
289
|
-
| `session` | `string` | No | Session name or ID. If omitted, detaches all foreground sessions for the current channel. |
|
|
290
|
-
| `channel` | `string` | No | Channel to detach from (e.g. `"telegram:123456789"`). Prevents `"unknown"` routing. |
|
|
291
|
-
|
|
292
|
-
#### `claude_kill`
|
|
293
|
-
|
|
294
|
-
Terminate a running session.
|
|
295
|
-
|
|
296
|
-
| Parameter | Type | Required | Description |
|
|
297
|
-
|---|---|---|---|
|
|
298
|
-
| `session` | `string` | Yes | Session name or ID. |
|
|
299
|
-
|
|
300
|
-
#### `claude_respond`
|
|
301
|
-
|
|
302
|
-
Send a follow-up message to a running session.
|
|
303
|
-
|
|
304
|
-
| Parameter | Type | Required | Description |
|
|
305
|
-
|---|---|---|---|
|
|
306
|
-
| `session` | `string` | Yes | Session name or ID. |
|
|
307
|
-
| `message` | `string` | Yes | The message to send. |
|
|
308
|
-
| `interrupt` | `boolean` | No | Interrupt the current turn before sending. Useful to redirect mid-response. |
|
|
309
|
-
|
|
310
|
-
#### `claude_stats`
|
|
311
|
-
|
|
312
|
-
Show usage metrics. Takes no parameters.
|
|
313
|
-
|
|
314
|
-
Returns: session counts by status, average duration, and notable session (sorted by cost internally — cost values are not shown in user-facing output).
|
|
178
|
+
For the full API reference (all parameter tables, response schemas), see [docs/API.md](docs/API.md).
|
|
315
179
|
|
|
316
180
|
---
|
|
317
181
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
182
|
+
## Multi-Agent Setup
|
|
183
|
+
|
|
184
|
+
See [docs/AGENT_CHANNELS.md](docs/AGENT_CHANNELS.md) for the complete guide. Quick summary:
|
|
185
|
+
|
|
186
|
+
Each agent needs three things configured:
|
|
187
|
+
|
|
188
|
+
1. **agentChannels mapping** — Map the agent's workspace directory to its notification channel in `openclaw.json`:
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"plugins": {
|
|
192
|
+
"config": {
|
|
193
|
+
"openclaw-claude-code-plugin": {
|
|
194
|
+
"agentChannels": {
|
|
195
|
+
"/home/user/agent-seo": "telegram|seo-bot|123456789",
|
|
196
|
+
"/home/user/agent-devops": "telegram|devops-bot|123456789"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
2. **Heartbeat** — Enable heartbeat for each agent in `openclaw.json`:
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"agents": {
|
|
208
|
+
"list": [
|
|
209
|
+
{ "id": "seo-bot", "heartbeat": { "every": "5s", "target": "last" } },
|
|
210
|
+
{ "id": "devops-bot", "heartbeat": { "every": "5s", "target": "last" } }
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
3. **Agent files** — Each agent's workspace needs:
|
|
217
|
+
- `HEARTBEAT.md` — Instructions for checking Claude Code sessions during heartbeat cycles
|
|
218
|
+
- `skills/claude-code-autonomy/SKILL.md` — Autonomy rules for handling session interactions
|
|
335
219
|
|
|
336
220
|
---
|
|
337
221
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
All methods return `respond(true, data)` on success or `respond(false, { error })` on failure.
|
|
341
|
-
|
|
342
|
-
#### `claude-code.sessions`
|
|
343
|
-
|
|
344
|
-
| Parameter | Type | Description |
|
|
345
|
-
|---|---|---|
|
|
346
|
-
| `status` | `string` | Filter: `"all"`, `"running"`, `"completed"`, `"failed"`. |
|
|
347
|
-
|
|
348
|
-
**Response:** `{ sessions: [...], count: number }`
|
|
349
|
-
|
|
350
|
-
Each session object includes: `id`, `name`, `status`, `prompt`, `workdir`, `model`, `startedAt`, `completedAt`, `durationMs`, `claudeSessionId`, `foreground`, `multiTurn`, `display`.
|
|
351
|
-
|
|
352
|
-
#### `claude-code.launch`
|
|
353
|
-
|
|
354
|
-
| Parameter | Type | Description |
|
|
355
|
-
|---|---|---|
|
|
356
|
-
| `prompt` | `string` | **(required)** Task prompt. |
|
|
357
|
-
| `name` | `string` | Session name. |
|
|
358
|
-
| `workdir` | `string` | Working directory. |
|
|
359
|
-
| `model` | `string` | Model name. |
|
|
360
|
-
| `maxBudgetUsd` / `max_budget_usd` | `number` | Budget cap. |
|
|
361
|
-
| `systemPrompt` / `system_prompt` | `string` | System prompt. |
|
|
362
|
-
| `allowedTools` / `allowed_tools` | `string[]` | Allowed tools. |
|
|
363
|
-
| `resumeSessionId` / `resume_session_id` | `string` | Session ID to resume. |
|
|
364
|
-
| `forkSession` / `fork_session` | `boolean` | Fork on resume. |
|
|
365
|
-
| `multiTurn` / `multi_turn` | `boolean` | Multi-turn mode. |
|
|
366
|
-
| `originChannel` | `string` | Origin channel for notifications. |
|
|
367
|
-
|
|
368
|
-
**Response:** `{ id, name, status, workdir, model }`
|
|
369
|
-
|
|
370
|
-
#### `claude-code.kill`
|
|
371
|
-
|
|
372
|
-
| Parameter | Type | Description |
|
|
373
|
-
|---|---|---|
|
|
374
|
-
| `session` / `id` | `string` | **(required)** Session name or ID. |
|
|
375
|
-
|
|
376
|
-
**Response:** `{ id, name, status, message }`
|
|
377
|
-
|
|
378
|
-
#### `claude-code.output`
|
|
379
|
-
|
|
380
|
-
| Parameter | Type | Description |
|
|
381
|
-
|---|---|---|
|
|
382
|
-
| `session` / `id` | `string` | **(required)** Session name or ID. |
|
|
383
|
-
| `lines` | `number` | Number of lines (default 50). |
|
|
384
|
-
| `full` | `boolean` | Return all buffered output. |
|
|
385
|
-
|
|
386
|
-
**Response:** `{ id, name, status, durationMs, duration, lines, lineCount, result }`
|
|
387
|
-
|
|
388
|
-
#### `claude-code.stats`
|
|
389
|
-
|
|
390
|
-
No parameters.
|
|
391
|
-
|
|
392
|
-
**Response:**
|
|
393
|
-
```json
|
|
394
|
-
{
|
|
395
|
-
"sessionsByStatus": { "completed": 10, "failed": 2, "killed": 1, "running": 1 },
|
|
396
|
-
"totalLaunched": 14,
|
|
397
|
-
"averageDurationMs": 45000,
|
|
398
|
-
"notableSession": { "id": "abc123", "name": "refactor-db", "prompt": "..." },
|
|
399
|
-
"display": "📊 Claude Code Plugin Stats\n..."
|
|
400
|
-
}
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
---
|
|
404
|
-
|
|
405
|
-
## Notification System
|
|
406
|
-
|
|
407
|
-
The `NotificationRouter` implements a notification matrix based on session state and channel mode:
|
|
408
|
-
|
|
409
|
-
| Event | Background session | Foreground session |
|
|
410
|
-
|---|---|---|
|
|
411
|
-
| Session started | Silent | Silent (streaming begins) |
|
|
412
|
-
| Assistant text output | Silent | Streamed to chat (500ms debounce) |
|
|
413
|
-
| Tool call | Silent | Compact indicator (e.g. `🔧 Bash — git status`) |
|
|
414
|
-
| Tool result | Silent | Silent |
|
|
415
|
-
| Session completed (success) | Notify origin channel | Notify all channels |
|
|
416
|
-
| Session completed (error) | Notify origin channel | Notify all channels |
|
|
417
|
-
| Session limit reached | Notify origin channel | Notify all channels |
|
|
418
|
-
| Session > 10 minutes | One-time reminder | Silent (user sees output) |
|
|
419
|
-
| Waiting for input | `🔔 [name] Claude asks:` + preview to origin channel + fire `openclaw system event` | `💬 Session waiting for input` + fire `openclaw system event` |
|
|
420
|
-
| Agent responds (`claude_respond`) | `↩️ [name] Responded:` echoed to origin channel | `↩️ [name] Responded:` echoed to origin channel |
|
|
421
|
-
|
|
422
|
-
### Notification delivery
|
|
423
|
-
|
|
424
|
-
Notifications are sent via the `openclaw message send` CLI command. The channel ID format is `"channel:target"` (e.g. `"telegram:123456789"`, `"discord:987654321"`). Bare numeric IDs are assumed to be Telegram chat IDs.
|
|
425
|
-
|
|
426
|
-
### Background visibility
|
|
427
|
-
|
|
428
|
-
When a session is running in the background, users can follow the conversation without foregrounding:
|
|
429
|
-
|
|
430
|
-
- **🔔 Claude asks** — When a session becomes idle and waiting for input (e.g. Claude asked a question or needs a decision), the origin channel receives a `🔔 [name] Claude asks:` message with a preview of the last output, so the user sees what Claude needs.
|
|
431
|
-
- **↩️ Responded** — When the agent (or user via `claude_respond`) sends a follow-up message, a `↩️ [name] Responded:` message is echoed to the origin channel with the response content, so the full conversation is visible in-channel.
|
|
432
|
-
|
|
433
|
-
This makes the plugin a transparent transport layer — the user sees both sides of the conversation in their chat, even when sessions run in the background.
|
|
222
|
+
## Skill Example
|
|
434
223
|
|
|
435
|
-
|
|
224
|
+
Claude Code Plugin is a **transparent transport layer** — it spawns sessions and delivers notifications, but business logic lives in **OpenClaw skills**. Here's a minimal skill that orchestrates coding agent sessions:
|
|
436
225
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
When any session (single or multi-turn) becomes idle and waiting for input, an `openclaw system event` is also fired to wake the orchestrator. Idle detection uses end-of-turn detection (for multi-turn results) combined with a 15-second safety-net timer. A `waitingForInputFired` flag prevents duplicate wake events from being fired for the same idle period.
|
|
226
|
+
### `coding-agent/SKILL.md`
|
|
440
227
|
|
|
228
|
+
```markdown
|
|
441
229
|
---
|
|
442
|
-
|
|
443
|
-
## Skill Example: Coding Agent Workflow
|
|
444
|
-
|
|
445
|
-
Claude Code Plugin is a **transparent transport layer** — it spawns sessions, streams output, and delivers notifications, but it has no opinion about *how* to orchestrate coding agents. Business logic lives in **OpenClaw skills**.
|
|
446
|
-
|
|
447
|
-
Here's an example skill that defines a coding agent workflow: it auto-responds to certain Claude questions and forwards others to the user.
|
|
448
|
-
|
|
449
|
-
### `coding-agent.skill.yaml`
|
|
450
|
-
|
|
451
|
-
```yaml
|
|
452
|
-
id: coding-agent
|
|
453
230
|
name: Coding Agent Orchestrator
|
|
454
|
-
description:
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
to the user.
|
|
458
|
-
|
|
459
|
-
instructions: |
|
|
460
|
-
You are a coding agent orchestrator. You manage Claude Code sessions
|
|
461
|
-
via the claude-code plugin tools.
|
|
462
|
-
|
|
463
|
-
## Auto-response rules
|
|
464
|
-
|
|
465
|
-
When a Claude Code session asks a question (🔔 wake event), analyze the
|
|
466
|
-
question and decide whether to auto-respond or forward to the user:
|
|
467
|
-
|
|
468
|
-
### Auto-respond (use claude_respond immediately):
|
|
469
|
-
- Permission requests for file reads, writes, or bash commands
|
|
470
|
-
→ Respond: "Yes, proceed."
|
|
471
|
-
- Confirmation prompts like "Should I continue?" or "Do you want me to apply these changes?"
|
|
472
|
-
→ Respond: "Yes, continue."
|
|
473
|
-
- Questions about which approach to take when only one is reasonable
|
|
474
|
-
→ Respond with the obvious choice
|
|
475
|
-
- Requests for clarification about the codebase (file locations, conventions)
|
|
476
|
-
→ Respond with the info if you know it, or "Use your best judgment."
|
|
477
|
-
|
|
478
|
-
### Forward to user (relay the question to the chat):
|
|
479
|
-
- Architecture decisions (e.g. "Should I use Redis or PostgreSQL for caching?")
|
|
480
|
-
- Destructive operations (e.g. "Should I delete the old migration files?")
|
|
481
|
-
- Ambiguous requirements (e.g. "The spec doesn't mention error handling — what should I do?")
|
|
482
|
-
- Budget or scope changes (e.g. "This will require refactoring 15 files — should I proceed?")
|
|
483
|
-
- Anything involving credentials, secrets, or production environments
|
|
231
|
+
description: Orchestrates Claude Code sessions with smart auto-response rules for routine questions and user forwarding for critical decisions.
|
|
232
|
+
metadata: {"openclaw": {"requires": {"plugins": ["openclaw-claude-code-plugin"]}}}
|
|
233
|
+
---
|
|
484
234
|
|
|
485
|
-
|
|
235
|
+
# Coding Agent Orchestrator
|
|
486
236
|
|
|
487
|
-
|
|
488
|
-
claude_launch(prompt: "<task>", multi_turn: true, channel: "<origin>")
|
|
237
|
+
You are a coding agent orchestrator. You manage Claude Code sessions via the claude-code plugin tools.
|
|
489
238
|
|
|
490
|
-
|
|
239
|
+
## Auto-response rules
|
|
491
240
|
|
|
492
|
-
|
|
493
|
-
- If auto-respond rule matches → claude_respond(session, answer)
|
|
494
|
-
- If forward rule matches → relay the question to the user
|
|
241
|
+
When a Claude Code session asks a question (wake event), analyze it and decide:
|
|
495
242
|
|
|
496
|
-
|
|
243
|
+
### Auto-respond (use `claude_respond` immediately):
|
|
244
|
+
- Permission requests for file reads, writes, or bash commands -> "Yes, proceed."
|
|
245
|
+
- Confirmation prompts like "Should I continue?" -> "Yes, continue."
|
|
246
|
+
- Questions about approach when only one is reasonable -> respond with the obvious choice
|
|
497
247
|
|
|
498
|
-
|
|
248
|
+
### Forward to user:
|
|
249
|
+
- Architecture decisions (Redis vs PostgreSQL, REST vs GraphQL...)
|
|
250
|
+
- Destructive operations (deleting files, dropping tables...)
|
|
251
|
+
- Anything involving credentials, secrets, or production environments
|
|
252
|
+
- When in doubt -> always forward to the user
|
|
499
253
|
|
|
500
|
-
|
|
254
|
+
## Workflow
|
|
501
255
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
256
|
+
1. User sends a coding task -> `claude_launch(prompt, ...)`
|
|
257
|
+
2. Session runs in background. Monitor via wake events.
|
|
258
|
+
3. On wake event -> `claude_output` to read the question, then auto-respond or forward.
|
|
259
|
+
4. On user reply to a forwarded question -> `claude_respond` with their answer.
|
|
260
|
+
5. On completion -> summarize the result and notify the user.
|
|
506
261
|
```
|
|
507
262
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
This skill demonstrates the key architectural principle: **Claude Code Plugin provides the transport, skills provide the brain.**
|
|
511
|
-
|
|
512
|
-
| Layer | Responsibility |
|
|
513
|
-
|---|---|
|
|
514
|
-
| **Claude Code Plugin** (this plugin) | Spawn sessions, stream output, deliver `🔔`/`↩️` notifications, fire wake events |
|
|
515
|
-
| **Skill** (e.g. `coding-agent`) | Decide what to auto-respond, what to forward, how to summarize results |
|
|
516
|
-
| **User** | Receives forwarded questions, provides high-level instructions |
|
|
517
|
-
|
|
518
|
-
The same Claude Code Plugin plugin can power completely different workflows — a code review skill, a CI/CD skill, a documentation skill — simply by swapping the skill definition. The plugin itself remains a generic, reusable transport layer.
|
|
263
|
+
A comprehensive orchestration skill is available at [`skills/claude-code-orchestration/SKILL.md`](skills/claude-code-orchestration/SKILL.md).
|
|
519
264
|
|
|
520
265
|
---
|
|
521
266
|
|
|
522
|
-
##
|
|
523
|
-
|
|
524
|
-
### Project Structure
|
|
267
|
+
## Documentation
|
|
525
268
|
|
|
526
|
-
|
|
527
|
-
claude-code/
|
|
528
|
-
├── index.ts # Plugin entry point (register function)
|
|
529
|
-
├── openclaw.plugin.json # Plugin manifest and config schema
|
|
530
|
-
├── package.json # Dependencies
|
|
531
|
-
├── src/
|
|
532
|
-
│ ├── types.ts # TypeScript interfaces
|
|
533
|
-
│ ├── shared.ts # Global state, helpers, formatting
|
|
534
|
-
│ ├── session.ts # Session class (SDK wrapper)
|
|
535
|
-
│ ├── session-manager.ts # Session pool management
|
|
536
|
-
│ ├── notifications.ts # NotificationRouter
|
|
537
|
-
│ ├── gateway.ts # RPC method registration
|
|
538
|
-
│ ├── tools/
|
|
539
|
-
│ │ ├── claude-launch.ts # claude_launch tool
|
|
540
|
-
│ │ ├── claude-sessions.ts # claude_sessions tool
|
|
541
|
-
│ │ ├── claude-output.ts # claude_output tool
|
|
542
|
-
│ │ ├── claude-fg.ts # claude_fg tool
|
|
543
|
-
│ │ ├── claude-bg.ts # claude_bg tool
|
|
544
|
-
│ │ ├── claude-kill.ts # claude_kill tool
|
|
545
|
-
│ │ ├── claude-respond.ts # claude_respond tool
|
|
546
|
-
│ │ └── claude-stats.ts # claude_stats tool
|
|
547
|
-
│ └── commands/
|
|
548
|
-
│ ├── claude.ts # /claude command
|
|
549
|
-
│ ├── claude-sessions.ts # /claude_sessions command
|
|
550
|
-
│ ├── claude-fg.ts # /claude_fg command
|
|
551
|
-
│ ├── claude-bg.ts # /claude_bg command
|
|
552
|
-
│ ├── claude-kill.ts # /claude_kill command
|
|
553
|
-
│ ├── claude-resume.ts # /claude_resume command
|
|
554
|
-
│ ├── claude-respond.ts # /claude_respond command
|
|
555
|
-
│ └── claude-stats.ts # /claude_stats command
|
|
556
|
-
└── docs/
|
|
557
|
-
└── plans/ # Design documents
|
|
558
|
-
```
|
|
559
|
-
|
|
560
|
-
### Dependencies
|
|
561
|
-
|
|
562
|
-
| Package | Purpose |
|
|
269
|
+
| Document | Description |
|
|
563
270
|
|---|---|
|
|
564
|
-
|
|
|
565
|
-
|
|
|
566
|
-
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
1. **Foreground is per-channel, not per-session.** Multiple channels can watch the same session simultaneously, and one channel can have multiple sessions in foreground.
|
|
571
|
-
|
|
572
|
-
2. **Multi-turn uses `AsyncIterable` prompts.** The `MessageStream` class implements `Symbol.asyncIterator` to feed user messages into the SDK's `query()` function as an async generator, keeping the session alive across turns.
|
|
573
|
-
|
|
574
|
-
3. **Persisted sessions survive GC.** When a session is garbage-collected (1 hour after completion), its Claude session ID is retained in a separate `persistedSessions` map so it can be resumed later. Entries are stored under three keys (internal ID, name, Claude UUID) for flexible lookup.
|
|
575
|
-
|
|
576
|
-
4. **Notifications use CLI shelling.** Since the plugin API doesn't expose a runtime `sendMessage` method, outbound notifications go through `openclaw message send` via `child_process.execFile`.
|
|
577
|
-
|
|
578
|
-
5. **Metrics are in-memory only.** Session metrics are aggregated in the `SessionManager` and reset on service restart. They are not persisted to disk. Cost data is tracked internally but not exposed in any user-facing output.
|
|
579
|
-
|
|
580
|
-
6. **Waiting-for-input uses dual detection.** End-of-turn detection (when a multi-turn result resolves) is the primary signal, backed by a 15-second safety-net timer for edge cases. A `waitingForInputFired` flag prevents duplicate wake events.
|
|
581
|
-
|
|
582
|
-
7. **Channel `"unknown"` falls through.** If `channelId` is `"unknown"`, the notification system explicitly falls through to `fallbackChannel` rather than attempting delivery to an invalid destination.
|
|
583
|
-
|
|
584
|
-
### Adding a new tool or command
|
|
585
|
-
|
|
586
|
-
1. Create a new file under `src/tools/` or `src/commands/`.
|
|
587
|
-
2. Export a `registerXxxTool(api)` or `registerXxxCommand(api)` function.
|
|
588
|
-
3. Import and call it in `index.ts` inside the `register()` function.
|
|
589
|
-
|
|
590
|
-
### Service lifecycle
|
|
591
|
-
|
|
592
|
-
- **`start()`** — Creates `SessionManager` and `NotificationRouter`, wires them together, starts the long-running reminder check interval (60s), and starts a GC interval (5 min).
|
|
593
|
-
- **`stop()`** — Stops the notification router, kills all active sessions, clears intervals, and nulls singletons.
|
|
271
|
+
| [docs/API.md](docs/API.md) | Full API reference — tools, commands, and RPC methods with parameter tables |
|
|
272
|
+
| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Architecture diagram and component breakdown |
|
|
273
|
+
| [docs/NOTIFICATIONS.md](docs/NOTIFICATIONS.md) | Notification matrix, delivery details, and agent wake events |
|
|
274
|
+
| [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | Project structure, dependencies, design decisions, and contribution guide |
|
|
275
|
+
| [docs/AGENT_CHANNELS.md](docs/AGENT_CHANNELS.md) | Multi-agent setup, notification routing, and workspace mapping |
|
|
594
276
|
|
|
595
277
|
---
|
|
596
278
|
|