@dexhorthy: 嘿,惊喜——你可以在 tmux 里启动交互模式,然后 tail 那个 jsonl 文件——我刚推送了一个小封装...ralph 循环迭代中…
摘要
Shannon 是一个 CLI 和 SDK 封装工具,可以在 tmux 中运行交互式 Claude Code 会话,通过 tail 磁盘上的转录文件来实现程序化查询和流式 JSON 输出。
查看缓存全文
缓存时间: 2026/05/14 08:33
嘿,惊喜——你其实可以在tmux里启动交互模式,然后追踪jsonl文件。我发了一个小封装……现在正在把ralph循环迭代做到完全一致。https://t.co/3N4klSSEwd https://t.co/Q1ODMrVdpB — # dexhorthy/shannon
来源:https://github.com/dexhorthy/shannon
Shannon
Shannon 是一个围绕交互式 Claude Code CLI 的 CLI 和 SDK 封装器。它在 tmux 中启动一个真实的 claude 会话,发送提示词,并输出流式 JSON。
flowchart LR
User([你的代码 / shell])
subgraph Shannon["@dexh/shannon"]
SDK["SDK: query()"]
CLI["CLI: shannon"]
end
subgraph Host["本地主机"]
Tmux["tmux 会话"]
Claude["claude (交互模式)"]
Transcript[("~/.claude/projects/transcript JSONL")]
end
Anthropic[["Anthropic API"]]
User -->|"提示词"| SDK
User -->|"提示词"| CLI
SDK -->|"启动"| CLI
CLI -->|"发送按键"| Tmux
Tmux --> Claude
Claude <-->|"HTTPS"| Anthropic
Claude -->|"追加"| Transcript
CLI -->|"追踪"| Transcript
CLI -->|"stream-json / json / text"| User
边界说明(虚线部分):Shannon 从不直接调用 Anthropic API——它驱动一个真实的 claude 会话,并读取其磁盘上的对话记录。内部不直接使用 claude -p。
依赖
- Bun (https://bun.sh)
claude在PATH中tmux在PATH中- 已完成登录的 Claude Code
CLI
无需安装直接运行:
npx @dexh/shannon -p "回复内容仅为:hello" --output-format=stream-json --verbose
或全局安装:
npm install -g @dexh/shannon
shannon -p "回复内容仅为:hello" --output-format=stream-json --verbose
输出格式:stream-json(JSONL)、json(单个数组)、text(最终结果文本)。
SDK
npm install @dexh/shannon
import { query } from "@dexh/shannon";
for await (const message of query({
prompt: "回复内容仅为:hello",
options: { outputFormat: "stream-json", verbose: true },
})) {
console.log(JSON.stringify(message));
}
也支持有限用户消息流的异步输入:
import { query, type ShannonUserMessage } from "@dexh/shannon";
async function* messages(): AsyncIterable<ShannonUserMessage> {
yield {
type: "user",
message: {
role: "user",
content: [{ type: "text", text: "回复内容仅为:hello" }],
},
parent_tool_use_id: null,
session_id: "",
};
}
for await (const message of query({ prompt: messages() })) {
console.log(JSON.stringify(message));
}
在选项中传入 AbortController 可终止底层 Shannon 子进程。
Agent SDK 外观
@dexh/shannon-agent-sdk 是一个与 Claude Agent SDK 兼容的外观,重新导出了 Shannon 的 SDK 接口。完全一致的工作仍在进行中(详见 GOAL_PROGRESS.md)。
npm install @dexh/shannon-agent-sdk
import { query } from "@dexh/shannon-agent-sdk";
for await (const message of query({
prompt: "回复内容仅为:hello",
options: { outputFormat: "stream-json", verbose: true },
})) {
console.log(JSON.stringify(message));
}
开发
bun install
bun test
bun run typecheck
bun ./index.ts -p "hello" --output-format=stream-json --verbose
相似文章
@tom_doerr: 在 tmux 中全天候运行 Claude agent https://github.com/Jedward23/Tmux-Orchestrator…
Tmux-Orchestrator 是一款开源工具,通过 tmux 会话内的多 agent 层级结构,实现 Claude AI agent 的自主全天候运行,支持并行项目管理与编码。
@trq212: https://x.com/trq212/status/2061907337154367865
Claude Code 发布了动态工作流功能,使得Claude能够为研究、安全分析、代理团队和代码审查等任务创建自定义框架,所有这些都在工具内原生实现。
Show HN: Rmux – 一款可编程终端复用器,带有 Playwright 风格 SDK
Rmux 是一款用 Rust 编写的新式可编程终端复用器,提供与 tmux 兼容的命令行接口、类型化 SDK 以及面向智能体工作流的功能,支持在 Linux、macOS 和 Windows 上创建可分离、可脚本化的终端会话。
@steipete: 我虽然来晚了,但cmux真的很棒。https://github.com/manaflow-ai/cmux… 当前分工:Codex Mac 应用:知识工作、学习、阅读…
cmux是一款基于Ghostty的macOS终端,具有垂直标签和通知功能,专为AI编程代理设计,支持SSH、应用内浏览器以及Claude Code Teams集成。
claude-share
一个可以安全地与朋友共享 Claude Code 会话的工具。