@dexhorthy: 嘿,惊喜——你可以在 tmux 里启动交互模式,然后 tail 那个 jsonl 文件——我刚推送了一个小封装...ralph 循环迭代中…

X AI KOLs Following 工具

摘要

Shannon 是一个 CLI 和 SDK 封装工具,可以在 tmux 中运行交互式 Claude Code 会话,通过 tail 磁盘上的转录文件来实现程序化查询和流式 JSON 输出。

嘿,惊喜——你可以在 tmux 里启动交互模式,然后 tail 那个 jsonl 文件——我刚推送了一个小封装...ralph 循环正在迭代以实现完全对等 https://t.co/3N4klSSEwd https://t.co/Q1ODMrVdpB
查看原文
查看缓存全文

缓存时间: 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)
  • claudePATH
  • tmuxPATH
  • 已完成登录的 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

相似文章

claude-share

Product Hunt

一个可以安全地与朋友共享 Claude Code 会话的工具。