persistent-code-terminal
A persistent coding terminal for OpenClaw. It creates a tmux session per project:
INLINECODE0
This makes terminal-first AI coding (Codex CLI / Claude Code / any CLI tool) reliable and mobile/SSH friendly:
- - detach/reattach without losing output
- keep shell state across turns
- keep long-running tasks alive (dev server, watch mode, etc.)
OpenClaw natural-language routing
When user intent is "use natural language to drive Codex CLI in this repo", route through this skill first.
Intelligent auto-trigger:
- - Routing toggle:
openclaw.config.dev.autoCodeRouting (default false). - If enabled, route coding workflow messages via:
-
{baseDir}/bin/persistent-code-terminal-route.sh "<user message>"
- - The route script applies:
- intent detection (code change / fix / test / build / commit / push / codex phrases)
- safety filtering (must be git repo + action verbs; bypass on
不要执行,只分析)
- execution chain:
-
persistent-code-terminal-auto.sh --max-retries 3 --instruction "<message>"
-
persistent-code-terminal-summary.sh --lines 120
- fallback for missing deps (
tmux/
codex) with doctor guidance.
Multi-project routing:
- - One message can include multiple project tasks split by newline /
; / INLINECODE10 - Supported patterns:
-
给 <project> 项目 <instruction>
-
给<project>项目:<instruction>
-
为 <project> 修复/增加/修改 ...
-
<project> 项目 ...;<project> 项目 ...
- - Execution is serial per project:
-
start.sh --project <project>
-
auto.sh --max-retries 3 --instruction "<instruction>"
-
summary.sh --lines 120 --json
- - Invalid/unknown project tasks are reported as failed without blocking other tasks.
Trigger shortcuts (recommended):
- - If user message starts with
codex , treat the remaining text as instruction. - Execute:
-
{baseDir}/bin/persistent-code-terminal-codex-exec.sh "<remaining text>"
-
{baseDir}/bin/persistent-code-terminal-status.sh
- INLINECODE21
Preferred execution pattern in chat-driven runs:
- -
start.sh (or implicit auto-create from send.sh) - INLINECODE24 for Codex-driven work
- INLINECODE25 /
summary.sh for concise progress reporting
If user says "检查项目/继续会话/跑测试并总结", use this skill scripts instead of asking user to type long shell commands.
Core model (must follow)
start → send → read → decide
1) Start/ensure session:
2) Send ONE command:
- Appends a pane sentinel on completion:
__PCT_EXIT_CODE__N
- Supports:
--timeout <seconds>,
--dry-run, INLINECODE32
3) Read output:
- Parses the latest sentinel and updates INLINECODE34
4) Check state quickly (optional):
- - INLINECODE35
- INLINECODE36
- INLINECODE37
- INLINECODE38 (list
*-code-session) - INLINECODE40
State file:
- -
.pct-state.json (current project directory) - Fields:
projectDir, session, lastCommand, lastExitCode, phase, INLINECODE47
Structured output:
- - INLINECODE48
- INLINECODE49
- INLINECODE50
Codex-first workflow (one-shot)
If Codex CLI is installed as codex, prefer:
- - INLINECODE52
- Default behavior uses:
-
codex exec --full-auto --sandbox workspace-write --cd <current-dir> "<instruction>"
- - You can pass additional flags before the instruction:
-
{baseDir}/bin/persistent-code-terminal-codex-exec.sh --json -o /tmp/codex.json "<instruction>"
- - Set
PCT_CODEX_NO_DEFAULT_FLAGS=1 to disable default flags.
Example:
Safety
- - Never
git push --force unless user explicitly requests. - Keep secrets out of terminal output.
- Prefer feature branches; avoid direct pushes to main/master unless explicitly requested.
- For network/privileged actions (for example
git push), follow active Codex approval/sandbox policy.
persistent-code-terminal
为OpenClaw设计的持久化编码终端。它会为每个项目创建一个tmux会话:
<项目名称>-code-session
这使得以终端优先的AI编码(Codex CLI / Claude Code / 任何CLI工具)变得可靠且适合移动端/SSH连接:
- - 分离/重新连接时不会丢失输出
- 跨轮次保持shell状态
- 保持长时间运行的任务持续执行(开发服务器、监听模式等)
OpenClaw自然语言路由
当用户意图是使用自然语言在此仓库中驱动Codex CLI时,首先通过此技能进行路由。
智能自动触发:
- - 路由开关:openclaw.config.dev.autoCodeRouting(默认false)
- 如果启用,通过以下方式路由编码工作流消息:
- {baseDir}/bin/persistent-code-terminal-route.sh <用户消息>
- 意图检测(代码变更/修复/测试/构建/提交/推送/codex相关短语)
- 安全过滤(必须是git仓库+动作动词;不要执行,只分析时跳过)
- 执行链:
- persistent-code-terminal-auto.sh --max-retries 3 --instruction <消息>
- persistent-code-terminal-summary.sh --lines 120
- 缺少依赖(tmux/codex)时的回退,附带诊断指导。
多项目路由:
- - 一条消息可以包含多个项目任务,按换行/;/;分隔
- 支持的格式:
- 给 <项目> 项目 <指令>
- 给<项目>项目:<指令>
- 为 <项目> 修复/增加/修改 ...
- <项目> 项目 ...;<项目> 项目 ...
- start.sh --project <项目>
- auto.sh --max-retries 3 --instruction <指令>
- summary.sh --lines 120 --json
- - 无效/未知的项目任务会被报告为失败,但不阻塞其他任务。
触发快捷方式(推荐):
- - 如果用户消息以codex 开头,将剩余文本视为指令。
- 执行:
- {baseDir}/bin/persistent-code-terminal-codex-exec.sh <剩余文本>
- {baseDir}/bin/persistent-code-terminal-status.sh
- {baseDir}/bin/persistent-code-terminal-summary.sh --lines 120
聊天驱动运行中的首选执行模式:
- - start.sh(或通过send.sh隐式自动创建)
- codex-exec.sh <指令>用于Codex驱动的工作
- status.sh / summary.sh用于简洁的进度报告
如果用户说检查项目/继续会话/跑测试并总结,使用此技能脚本,而不是让用户输入长shell命令。
核心模型(必须遵循)
启动 → 发送 → 读取 → 决策
1) 启动/确保会话:
- - {baseDir}/bin/persistent-code-terminal-start.sh
2) 发送一条命令:
- - {baseDir}/bin/persistent-code-terminal-send.sh <命令>
- 完成后追加窗格标记:
PCTEXITCODEN
- 支持:--timeout <秒数>、--dry-run、--phase <名称>
3) 读取输出:
- - {baseDir}/bin/persistent-code-terminal-read.sh
- 解析最新的标记并更新.pct-state.json
4) 快速检查状态(可选):
- - {baseDir}/bin/persistent-code-terminal-status.sh
- {baseDir}/bin/persistent-code-terminal-summary.sh --lines 120
- {baseDir}/bin/persistent-code-terminal-doctor.sh
- {baseDir}/bin/persistent-code-terminal-list.sh(列出*-code-session)
- {baseDir}/bin/persistent-code-terminal-switch.sh --project <名称>
状态文件:
- - .pct-state.json(当前项目目录)
- 字段:projectDir、session、lastCommand、lastExitCode、phase、updatedAt
结构化输出:
- - {baseDir}/bin/persistent-code-terminal-read.sh --json
- {baseDir}/bin/persistent-code-terminal-summary.sh --json
- {baseDir}/bin/persistent-code-terminal-auto.sh --json
Codex优先工作流(一次性)
如果Codex CLI已安装为codex,优先使用:
- - {baseDir}/bin/persistent-code-terminal-codex-exec.sh <指令>
- 默认行为使用:
- codex exec --full-auto --sandbox workspace-write --cd <当前目录> <指令>
- {baseDir}/bin/persistent-code-terminal-codex-exec.sh --json -o /tmp/codex.json <指令>
- - 设置PCTCODEXNODEFAULTFLAGS=1可禁用默认标志。
示例:
- - {baseDir}/bin/persistent-code-terminal-codex-exec.sh 实现功能X。确保构建和测试通过。提交并推送到当前分支。不要强制推送。
安全
- - 除非用户明确要求,绝不执行git push --force。
- 保持终端输出中不包含机密信息。
- 优先使用功能分支;除非明确要求,避免直接推送到main/master分支。
- 对于网络/特权操作(例如git push),遵循活动的Codex审批/沙箱策略。