EN 中文
Background jobs are session-scoped — they live and die with the current seek session. No persistence across restarts. For persistent scheduled jobs, see Cron. 后台任务随当前 seek 会话生死,不写盘、不跨重启。持久化定时任务见 Cron

Launch a Background Job

启动一个后台任务

Pass run_in_background: true to the bash tool. It returns a handle bg-N immediately instead of blocking:

给 bash 传 run_in_background: true,它立即返回句柄 bg-N:

bash(command="go build ./...", run_in_background=true)
→ [bg: started bg-1] $ go build ./...
  Track with: monitor(job="bg-1", action=poll|wait|kill).

Track with monitor

用 monitor 跟踪

poll (default) — incremental output since last check

poll(默认)——看自上次以来的新输出 + 状态

monitor(job="bg-1")
→ [bg-1: running, elapsed=12s]
  <new output since last poll>

Cursor is server-side — each poll returns only incremental output. No new output = (no new output).

游标是服务端记的——每次 poll 只给你增量输出。

wait — block until exit / match / timeout

wait——阻塞直到完成 / 命中 / 超时

monitor(job="bg-1", action=wait, timeout_ms=60000)
→ [bg-1: exited code=0, elapsed=43s]
  <final output>

Three exit paths: task exits, until_regex matches ("Listening on" for a dev server), or timeout.

三条退出路径:任务退出、until_regex 命中(如 dev server 的 "Listening on")、超时。

Cancelling a wait (Esc) stops observing but leaves the job running.

取消 wait(Esc)停止观察但让任务继续跑。

kill — terminate

kill——终止

monitor(job="bg-1", action=kill)
→ [bg-1: killed, elapsed=67s]

Lifecycle

生命周期

Design: PRD feature-bash-monitor.md

设计文档:PRD feature-bash-monitor.md