Code Agent Orchestration
Use openclaw-code-agent to run Claude Code or Codex sessions as background coding jobs from chat.
Launch
- - Do not pass
channel manually. Routing comes from agentChannels, the current chat context, and fallbackChannel. - Sessions are multi-turn. Continue existing work with
agent_respond or agent_launch(..., resume_session_id=...); do not start a fresh session for the same task. - Always set a short kebab-case
name when you care about later follow-up. - Set
workdir to the target repo. - Use
permission_mode: "plan" when the user wants a real review gate before implementation. - Use
permission_mode: "bypassPermissions" only for autonomous execution. - INLINECODE10 now defaults to
off. Opt into a worktree strategy explicitly when you want branch isolation. - In
plan mode, the plan belongs in normal session output. Do not ask the coding agent to write plan docs or transcript artifacts unless the user explicitly asked for a file.
Example:
CODEBLOCK0
Resume, Don't Respawn
When a session already exists for the task, keep using it.
- - Waiting for plan approval:
agent_respond(session, message, approve=true) or agent_request_plan_approval(...) if delegated approval must escalate to the user - Waiting for a question answer: INLINECODE15
- Killed/stopped by restart: INLINECODE16
- Completed but needs follow-up: INLINECODE17
- Fresh
agent_launch is only for genuinely independent work
Do not launch a new coding session from a wake event for the same task.
State and Monitoring
Use:
CODEBLOCK1
For worktree follow-through, inspect:
CODEBLOCK2
Treat that tool's lifecycle, derived state, cleanup disposition, and retained reasons as authoritative. Do not infer cleanup safety from a transcript summary or from branch names alone.
Treat these wake fields as authoritative state when present:
- - INLINECODE19
- INLINECODE20 / INLINECODE21
- INLINECODE22
Use those deterministic fields instead of inferring behavior from transcript fragments.
Approval/execution meanings:
- -
approved_then_implemented: normal approved execution - INLINECODE24 : actual approval bypass
- INLINECODE25 : still stopped at the approval gate
- INLINECODE26 : no plan gate applied
Completion ownership:
- - The plugin sends the canonical completion notification.
- The plugin owns the canonical completion status line; the orchestrator owns any additional plain-text follow-up.
- After a coding-agent session completes, the orchestrator should usually add at least a short human-useful summary of what changed, what was done, or the concrete outcome.
- That expectation applies to ordinary terminal/manual completions, manual no-change completions, and delegated worktree completions alike.
- Treat the plugin's canonical
✅ as the status signal and your follow-up as the factual outcome summary that should usually come right after it. - That summary can be brief; one sentence is often enough.
- Extra synthesis, risk framing, and next-step guidance are optional. Add them when useful; do not force them every time.
- Do not generate your own heuristic completion summary from transcript tail lines. Base any summary on reliable result data such as
agent_output(..., full=true), diff context, or deterministic tool state. - Skip the summary only in narrow cases:
- no user-facing follow-up will be sent at all because the orchestrator is silently continuing an internal multi-phase pipeline
- the completion produced no meaningful outcome to report, or the reliable result data is still too incomplete to support even a short factual summary
Respond Rules
Auto-respond immediately only for:
- - permission requests for file reads, writes, or shell commands
- explicit continuation prompts such as "Should I continue?"
Forward everything else to the user:
- - architecture or design choices
- destructive operations
- scope changes
- credentials or production questions
- ambiguous requirements
When forwarding, quote the session's exact question. Do not add commentary.
Plan Approval
Use permission_mode: "plan" whenever the user wants a real planning checkpoint.
planApproval: "ask"
- - Approval belongs to the user.
- The plugin sends the canonical Approve / Revise / Reject prompt directly to the user.
- If the user requests changes, wait for the revised plan from that same session; the revised submission becomes the latest actionable review version automatically.
- Wait for the user's answer, then forward it with
agent_respond(...). - Do not send a duplicate approval recap or second approval prompt.
planApproval: "delegate"
- - Approval belongs to the orchestrator first.
- This is wake-first: the plugin wakes the orchestrator without user buttons.
- Before deciding, read the full plan with
agent_output(session, full=true); do not rely on the truncated preview. - Approve directly with
agent_respond(..., approve=true) only when the latest actionable plan version is clearly in-bounds and low risk. - When approving directly, pass a structured rationale with
approval_rationale, for example: INLINECODE36 - After approving directly, send the user a short plain-text follow-up explaining what was approved and why. The plugin's
👍 Plan approved line is only a fallback signal, not the full explanation. - If a prior version had
changes_requested, that stale state should not block approval of the latest revised plan version. - If escalation is needed, call
agent_request_plan_approval(session='...', summary='...') exactly once so the plugin sends the single canonical user approval prompt. - That escalation summary must concisely explain why you are escalating, plus risk/scope notes the user needs to decide.
- After that canonical prompt exists, wait for the user's decision; do not send a second plain-text approval summary.
planApproval: "approve"
- - Auto-approve only after verification per the session policy.
Worktree Decisions
Treat worktrees as temporary task sandboxes, not as generic branch inventory.
Lifecycle meanings:
- -
pending_decision: still waiting for merge / PR / dismiss follow-through - INLINECODE42 : PR exists; preserve the sandbox
- INLINECODE43 : normal ancestry merge landed
- INLINECODE44 : content already landed on the base branch even though SHAs differ after rebase, squash, or cherry-pick
- INLINECODE45 : sandbox intentionally discarded
- INLINECODE46 : no committed delta
If agent_worktree_status reports released, treat that sandbox as already landed. Do not narrate it as “still unmerged” just because the branch appears ahead.
off
- - No worktree. The session runs in the main checkout.
ask
- - The plugin owns the user-facing completion/decision message and button UI.
- Do not call
agent_merge or agent_pr unless the user explicitly asks after that. - A completed ask-session worktree may later resolve as
released if its content already landed on base through another path. Confirm that with agent_worktree_status(...) before deciding what follow-up is still needed.
delegate
- - The plugin wakes the orchestrator with diff context and no automatic user buttons.
- Read the diff context and decide whether a local merge is clearly safe.
- INLINECODE56 is acceptable for low-risk, clearly scoped changes that match the task.
- Never call
agent_pr() autonomously in delegate flows. Escalate PR decisions to the user. - If the wake already says the plugin sent the canonical completion notification, do not repeat that status line, but you should still usually add a short summary of the completed outcome.
manual
- - Wait for an explicit user request before calling
agent_merge or agent_pr.
Cleanup
- - Use
agent_worktree_cleanup(mode: "preview_safe") to review what Clean all safe would remove. - Use
agent_worktree_cleanup(mode: "clean_safe") only when the user asked to clean up safe sandboxes. - Use
agent_worktree_cleanup(mode: "preview_all") when you need both safe candidates and retained reasons. - Respect retained reasons from
agent_worktree_status / agent_worktree_cleanup; they are the lifecycle model, not advisory prose.
Never
- - Never use raw
git merge or raw PR commands in place of plugin tools. - Never invent your own workaround for a pending worktree decision; use
agent_worktree_cleanup(session: "...", dismiss_session: true) to dismiss permanently. - Never use
agent_worktree_cleanup to force-delete unresolved worktrees. The supported bulk action is "clean all safe": omit session and let the plugin remove only lifecycle-safe worktrees while preserving anything active, pending, dirty, or PR-open. - Never merge or PR an
ask worktree behind the user's back.
File Artifact Policy
- - Do not ask the coding agent to write planning documents, investigation notes, or analysis artifacts as files unless the user explicitly requested a file.
- Do not commit planning documents, investigation notes, or transcript-summary artifacts to the branch.
- Commit only actual code, configuration, tests, and explicitly requested documentation.
Anti-Patterns
- - Do not pass
multi_turn or multi_turn_disabled; all sessions are multi-turn. - Do not pass
channel manually unless you are debugging routing. - Do not auto-answer design or scope questions.
- Do not infer approval/completion ownership from old transcript snippets when deterministic fields are present.
- Do not post duplicate completion or approval recaps when the plugin already sent the canonical message.
代码代理编排
使用 openclaw-code-agent 在聊天中以后台编码任务形式运行 Claude Code 或 Codex 会话。
启动
- - 不要手动传递 channel。路由来自 agentChannels、当前聊天上下文和 fallbackChannel。
- 会话是多轮交互的。使用 agentrespond 或 agentlaunch(..., resumesessionid=...) 继续现有工作;不要为同一任务启动全新会话。
- 当您关心后续跟进时,始终设置一个简短的短横线连接式 name。
- 将 workdir 设置为目标仓库。
- 当用户希望在实施前进行真正的审查关卡时,使用 permissionmode: plan。
- 仅在自主执行时使用 permissionmode: bypassPermissions。
- defaultWorktreeStrategy 现在默认为 off。当您需要分支隔离时,明确选择工作树策略。
- 在 plan 模式下,计划属于正常的会话输出。除非用户明确要求文件,否则不要要求编码代理编写计划文档或记录工件。
示例:
text
agent_launch(
prompt: 修复认证中间件错误并添加测试,
name: fix-auth,
workdir: /home/user/projects/my-app
)
恢复,而非重生
当任务已有会话存在时,继续使用它。
- - 等待计划批准:agentrespond(session, message, approve=true) 或 agentrequestplanapproval(...)(如果委托的批准必须升级给用户)
- 等待问题回答:agentrespond(session, message)
- 因重启而被终止/停止:agentrespond(session, message)
- 已完成但需要后续跟进:agentlaunch(resumesessionid=sessionid, prompt=...)
- 全新的 agent_launch 仅用于真正独立的工作
不要从唤醒事件中为同一任务启动新的编码会话。
状态与监控
使用:
text
agent_sessions()
agent_output(session: fix-auth, lines: 100)
agent_output(session: fix-auth, full: true)
对于工作树跟进,检查:
text
agentworktreestatus()
agentworktreestatus(session: fix-auth)
将该工具的生命周期、派生状态、清理处置和保留原因视为权威依据。不要仅从记录摘要或分支名称推断清理安全性。
当以下唤醒字段存在时,将其视为权威状态:
- - requestedPermissionMode
- effectivePermissionMode / currentPermissionMode
- approvalExecutionState
使用这些确定性字段,而不是从记录片段推断行为。
批准/执行含义:
- - approvedthenimplemented:正常批准执行
- implementedwithoutrequiredapproval:实际绕过批准
- awaitingapproval:仍在批准关卡处停止
- notplangated:未应用计划关卡
完成所有权:
- - 插件发送规范的完成通知。
- 插件拥有规范的完成状态行;编排器拥有任何额外的纯文本后续跟进。
- 编码代理会话完成后,编排器通常应至少添加一段简短的对人类有用的摘要,说明更改了什么、完成了什么或具体结果。
- 该期望适用于普通的终端/手动完成、手动无更改完成以及委托的工作树完成。
- 将插件的规范 ✅ 视为状态信号,将您的后续跟进视为事实结果摘要,通常应紧随其后。
- 该摘要可以简短;一句话通常就足够了。
- 额外的综合、风险框架和下一步指导是可选的。在有用时添加它们;不要每次都强制添加。
- 不要从记录尾部行生成您自己的启发式完成摘要。任何摘要都应基于可靠的结果数据,如 agent_output(..., full=true)、差异上下文或确定性工具状态。
- 仅在少数情况下跳过摘要:
- 根本不会发送面向用户的后续跟进,因为编排器正在静默地继续内部多阶段流水线
- 完成没有产生有意义的可报告结果,或者可靠的结果数据仍然不完整,无法支持即使是简短的事实摘要
响应规则
仅在以下情况下自动立即响应:
- - 文件读取、写入或 shell 命令的权限请求
- 明确的继续提示,如我应该继续吗?
将所有其他内容转发给用户:
- - 架构或设计选择
- 破坏性操作
- 范围变更
- 凭据或生产问题
- 模糊需求
转发时,引用会话的确切问题。不要添加评论。
计划批准
每当用户想要真正的计划检查点时,使用 permission_mode: plan。
planApproval: ask
- - 批准属于用户。
- 插件将规范的批准/修订/拒绝提示直接发送给用户。
- 如果用户请求更改,等待同一会话的修订计划;修订后的提交自动成为最新的可操作审查版本。
- 等待用户的回答,然后使用 agent_respond(...) 转发。
- 不要发送重复的批准摘要或第二个批准提示。
planApproval: delegate
- - 批准首先属于编排器。
- 这是先唤醒:插件唤醒编排器,不显示用户按钮。
- 在决定之前,使用 agentoutput(session, full=true) 阅读完整计划;不要依赖截断的预览。
- 仅当最新的可操作计划版本明显在范围内且风险较低时,才直接使用 agentrespond(..., approve=true) 批准。
- 直接批准时,传递带有 approvalrationale 的结构化理由,例如:agentrespond(session=..., message=已批准。请继续。, approve=true, approvalrationale=范围与请求匹配,且更改风险较低。)
- 直接批准后,向用户发送简短的纯文本后续跟进,解释批准了什么以及原因。插件的 👍 计划已批准 行仅作为后备信号,并非完整解释。
- 如果先前版本有 changesrequested,该过期状态不应阻止批准最新的修订计划版本。
- 如果需要升级,调用 agentrequestplan_approval(session=..., summary=...) 恰好一次,以便插件发送单个规范的用户批准提示。
- 该升级摘要必须简洁地解释您为何升级,以及用户决策所需的风险/范围说明。
- 在该规范提示存在后,等待用户的决定;不要发送第二个纯文本批准摘要。
planApproval: approve
工作树决策
将工作树视为临时任务沙箱,而非通用分支清单。
生命周期含义:
- - pendingdecision:仍在等待合并/PR/关闭跟进
- propen:PR 存在;保留沙箱
- merged:正常祖先合并已落地
- released:内容已在基础分支上落地,尽管变基、压缩或精选后 SHA 不同
- dismissed:沙箱被有意丢弃
- no_change:无提交的增量
如果 agentworktreestatus 报告 released,将该沙箱视为已落地。不要仅仅因为分支看起来领先而将其描述为尚未合并。
off
ask
- - 插件拥有面向用户的完成/决策消息和按钮 UI。
- 除非用户之后明确要求,否则不要调用 agentmerge 或 agentpr。
- 已完成的 ask 会话工作树可能后来解析为 released,如果其内容已通过其他路径在基础分支上落地。在决定还需要什么后续跟进之前,使用 agentworktreestatus(...) 确认。
delegate
- - 插件使用差异上下文唤醒编排器,不显示自动用户按钮。
- 阅读差异上下文并决定本地合并是否明显安全。
- 对于低风险、范围明确且与任务匹配的更改,agentmerge 是可接受的。
- 在委托流程中永远不要自主调用 agentpr()。将 PR 决策升级给用户。
- 如果唤醒消息已说明插件发送了规范的完成通知,不要重复该状态行,但您通常仍应添加已完成结果的简短摘要。
manual
- - 在调用 agentmerge 或 agentpr 之前,等待用户的明确请求。
清理
- - 使用 agentworktreecleanup(mode: previewsafe) 查看清理所有安全项将删除什么。
- 仅当用户要求清理安全沙箱时,使用 agentworktreecleanup(mode: cleansafe)。
- 当您需要安全候选和保留原因时,使用 agentworktreecleanup(mode: previewall)。
- 尊重来自 agentworktreestatus / agentworktree_cleanup 的保留原因;它们是生命周期模型,而非建议性文字。
禁止事项
- - 永远不要使用原始 git merge 或原始 PR 命令代替插件工具。
- 永远不要为待处理的工作树决策发明自己的变通方法;使用 agentworktreeclean