面向 VS Code / Cursor 内置终端的 Agent 通知扩展。
核心目标:
- 你继续在终端里正常运行
codex/claude/opencode。 - Agent 一次任务(turn / stop)结束时自动通知。
- 点击通知后,回到发起该任务的终端标签页。
本扩展有意不做“通用 OSC 通知插件”,只聚焦 Agent 工作流。
- Codex + Claude + OpenCode 优先的事件流设计。
- 结构化事件协议:
OSC 777;notify;AGENT_TASK_EVENT_V1;<base64url-json>。 - 同时支持系统通知与 VS Code toast,并提供回到终端动作。
- 使用 deep-link 回跳到原 VS Code 窗口与对应终端标签页。
- 安装扩展。
- 在内置终端启动一次
codex。 - 扩展会自动检查并改写
~/.codex/config.toml:- 旧的
notify配置会被注释(# ...)。 - 每次检测到
codex启动都会同步脚本到~/.codex/agent-task-notifier/notify.sh。 - 再把
notify写成指向这个外部脚本。
- 旧的
- 按提示重启当前
codex进程后生效。 - 在内置终端启动一次
claude。 - 扩展会自动同步 Claude hooks 脚本到
~/.claude/agent-task-notifier/,并检查/改写~/.claude/settings.json的hooks.Stop与hooks.SubagentStop。 - 按提示重启当前
claude进程后生效。 - 在内置终端启动一次
opencode。 - 扩展会自动同步 OpenCode 插件脚本到
~/.opencode/plugins/。 - 按提示重启当前
opencode进程后生效。
默认不需要手动修改配置。扩展会在检测到你启动 codex 时自动接管 notify,并把脚本复制到 ~/.codex/agent-task-notifier/notify.sh。
如需手动触发修复,可执行命令:
Agent Task Notifier: Repair Codex Notify
说明:Codex 会把 notify 事件 JSON 作为脚本第一个参数传入。
当前适配器会把通知文案处理为:
- 标题:
Codex: <last-assistant-message> - 正文:
input-messages的短预览(默认 120 字符,超出追加…)
默认不需要手动修改配置。扩展会在检测到你启动 claude 时自动同步脚本到 ~/.claude/agent-task-notifier/,并写入 ~/.claude/settings.json 的 hooks。
如需手动触发修复,可执行命令:
Agent Task Notifier: Repair Claude Hooks
手动配置时可参考以下结构:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "bash /absolute/path/to/vscode-agent-task-notifier/adapters/claude/stop-hook.sh"
}
]
}
],
"SubagentStop": [
{
"hooks": [
{
"type": "command",
"command": "bash /absolute/path/to/vscode-agent-task-notifier/adapters/claude/subagent-stop-hook.sh"
}
]
}
]
}
}默认不需要手动修改配置。扩展会在检测到你启动 opencode 时自动同步插件脚本到 ~/.opencode/plugins/:
agent-task-notifier.jsagent-task-notifier-emit.sh
如需手动触发修复,可执行命令:
Agent Task Notifier: Repair OpenCode Plugin
说明:OpenCode 通过 plugin hooks 输出事件,当前适配器映射关系为:
session.status(status.type=idle)/session.idle->turn_completepermission.updated/permission.asked->approval_requested
所有配置位于 agentTaskNotifier.*:
enabled:总开关。osNotification:是否启用系统通知。vscodeToast:是否启用 VS Code 内部通知。logLevel:日志级别(error/warn/info/debug)。dedupeWindowMs:去重时间窗口(毫秒)。strictWindowRouting:是否严格校验窗口 token(防止多窗口误跳转)。
Agent Task Notifier: EnableAgent Task Notifier: DisableAgent Task Notifier: Test NotificationAgent Task Notifier: Show LogsAgent Task Notifier: Debug StatusAgent Task Notifier: Repair Codex NotifyAgent Task Notifier: Repair Claude HooksAgent Task Notifier: Repair OpenCode Plugin
- 在设置里把
agentTaskNotifier.logLevel设为debug。 - 运行命令
Agent Task Notifier: Show Logs打开输出面板。 - 再执行一次
Agent Task Notifier: Debug Status,确认当前终端shellIntegration=ready。 - 关注这些日志关键字:
Codex command detected ...:检测到你在终端启动了 codex。Codex notify config rewritten ...:已自动改写~/.codex/config.toml。Claude command detected ...:检测到你在终端启动了 claude。Claude hooks config rewritten ...:已自动改写~/.claude/settings.json。OpenCode command detected ...:检测到你在终端启动了 opencode。OpenCode plugin scripts synced ...:已自动同步~/.opencode/plugins/下插件脚本。Structured event parsed ...:说明扩展已收到结构化事件。Structured payload detail ...:可直接看到本次通知使用的title/message(会截断显示)。Suppressed duplicate event ...:说明事件被去重抑制。Notification delivered ...:说明通知已发出。
- 如果没有
Started shell execution stream ...,请在扩展激活后重新启动一次对应的codex/claude/opencode进程(只会监听启动后的 shell 执行流)。
给启动 Codex 的终端加环境变量:
export AGENT_TASK_NOTIFIER_DEBUG=1
export AGENT_TASK_NOTIFIER_LOG_FILE=/tmp/agent-task-notifier-codex.log
export AGENT_TASK_NOTIFIER_CODEX_MESSAGE_MAX_CHARS=120然后运行 Codex,并在另一个终端观察:
tail -f /tmp/agent-task-notifier-codex.log若看到 received type=... 与 emitted event=...,说明 notify.sh 确实被触发并已输出事件。
补充:脚本会优先尝试按以下顺序写回事件:
/dev/tty- 父进程 TTY(
ps -o tty= -p $PPID对应的/dev/<tty>) stdout + stderr兜底
这样在 terminal tab 被切走或 /dev/tty 不可用时,仍尽量写回正确会话。
npm install
npm run watch然后在 VS Code 中按 F5 启动 Extension Development Host。
- 适配脚本依赖
jq处理 JSON。 - 当前版本仅支持“适配脚本/hook 输出结构化事件”这一路径。
- Codex/Claude 配置改写逻辑与 OpenCode 插件同步逻辑只会在检测到对应命令启动时触发。