第 1 课

装好 Stroq,跑会话体检卡片,用内置样例看密钥外泄报告

确认 Node.js 22,安装 @stroq/cli 0.30.0 并核对版本;查看 help 命令分组;在没有历史会话的机器上跑体检卡片;用 sent --try 看官方内置的「密钥被发到另一家公司」报告,理解五档含义与「只打印名字、不打印值」。

图文20 分钟Stroq 官方文档 ↗

课程目录第 1 / 3 课

学习位置仅保存在当前浏览器,有效期 180 天。

01 / 图文教材

装好 Stroq,跑会话体检卡片,用内置样例看密钥外泄报告

本课对照的官方页面:首页 、文档 、Find credentials in past AI coding agent sessions 、npm:@stroq/cli 。测试环境:2026-11-09,Asia/Shanghai,Linux x86_64 云主机,Node.js v22.21.1,@stroq/cli 0.30.0(2026-11-05 发布)。下面所有「对照结果」都是这台机器的真实输出,只做了节选。

Stroq 是给 Claude Code、Cursor、Codex CLI 等编程 Agent 用的本地安全工具。它先读你机器上已经留下的会话记录,对照密钥文件,报告哪些密钥名出现在工具参数里(只打印名字,不打印值);再在后续课时里用本地钩子拦住危险动作。本课先把它装好,确认版本,跑一张会话体检卡片,并用官方内置样例看一份「密钥被发到另一家公司」的报告长什么样。

第 1 步:确认 Node.js 是 22 或更高

官方 README 写明需要 Node.js 22 或更新的版本。先看本机版本:

node -v

对照结果(测试机系统自带的是 v20.19.2,已换成官方 Linux x64 二进制):

v22.21.1

如果你看到的是 v20 或 v18,先升级再继续。常用做法是用 nvm、fnm,或从 https://nodejs.org/ 下载当前 22.x 的官方压缩包,把其中的 bin 目录放到 PATH 前面。Cursor 的会话库存放在 SQLite 里,官方指南还提到读取它需要带 node:sqlite 的 Node(文档写的是 22.23 或更高);本课后面的命令在 v22.21.1 上全部跑通,测试机没有 Cursor 会话可读,这一项未单独验证。

第 2 步:安装并确认是 0.30.0

官方推荐直接用 npx,不需要先全局安装:

npx @stroq/cli@0.30.0 --version

想留一条长期可用的 stroq 命令,官方写法是全局安装:

npm install -g @stroq/cli@0.30.0
stroq --version

本课为了不污染系统目录,在实验文件夹里做了一次本地安装(和全局安装效果相同,只是命令在当前目录的 node_modules/.bin 里):

mkdir -p ~/stroq-lab && cd ~/stroq-lab
npm install --prefix . @stroq/cli@0.30.0
export PATH="$PWD/node_modules/.bin:$PATH"
stroq --version

对照结果:

0.30.0

包装页与本机安装都确认当前发布版是 0.30.0(2026-11-05 更新)。后面的命令统一写成 stroq …;如果你没有加到 PATH,把开头的 stroq 换成 npx @stroq/cli@0.30.0 即可。

第 3 步:看一看命令分组

stroq help --all

对照结果(完整 31 行):

stroq: see what your AI coding agent saw, ran and installed.
Runs on your machine, no telemetry.

Start here:
  stroq                         A card from your own sessions
  stroq init                    stop it next time: guard your agent
  stroq why                     why an action was stopped
  stroq attack                  watch Stroq stop 36 known attacks, in a sandbox
  stroq uninstall               remove Stroq

Check past sessions:
  stroq sent --last             Did your agent see or send any of your keys?
  stroq replay --last           Which commands came from what the agent read?

Check before you open or install:
  stroq inspect [<dir>]         What will this repo run when an agent opens it?
  stroq vet --from <path>       Read a skill or MCP server before you add it
  stroq exposure                Map the agents and MCP servers on this machine

Guard your agent:
  stroq console                 Open the local security platform
  stroq doctor                  Is the guard installed and being called?
  stroq untaint --session <id>  Clear a flagged session after a false alarm
  stroq trust <file>            Mark a file as fine until it changes
  stroq log                     Show the latest entries of Stroq's audit log
  stroq verify                  Check that the audit log was not edited
  stroq policy check            Check your policy file and test what it changes
  stroq canary                  Make a decoy key; sending it out is blocked

One command:   stroq <command> --help
The version:   stroq --version

可以分成四块记:不带参数时打印近 30 天的会话卡片;sent / replay 回看已经发生的事;inspect / vet / exposure 在打开仓库或接入技能之前先读一遍;init / doctor / attack 负责往后拦住危险动作。单条命令的选项用 stroq <命令> --help 查看。

第 4 步:跑一张会话体检卡片

不带子命令时,Stroq 读取本机近 30 天的 Claude Code(~/.claude/projects)和 Codex(~/.codex/sessions)记录,打印一张卡片:Agent 跑过多少命令、其中多少条能追溯到它读过的外部文本、有没有密钥被发到另一家公司、哪些仓库一打开就会自动执行代码。卡片本身什么都不执行、什么都不外发,退出码是 0。加上 --plain 和 --no-animation 可以去掉猫头鹰装饰和动画,方便复制:

stroq card --plain --no-animation

对照结果(测试机上没有 Claude Code 或 Codex 的历史会话):

Hoo found no agent sessions in the last 30 days.
Looked for Claude Code in ~/.claude/projects and Codex
in ~/.codex/sessions.

See what Stroq stops:  npx @stroq/cli attack

如果你本机天天在用 Claude Code,这里会变成你自己的卡片,内容因人而异。官方提醒:卡片里可能出现路径、密钥名和主机名,分享前请先检查;如果只想贴一个不含路径和名字的计数,可以用 stroq card --share。

没有历史会话并不影响学完后面的课。官方专门准备了一条不读取本机任何文件的样例命令。

第 5 步:用内置样例看密钥外泄报告

stroq sent --try

这条命令在内存里跑完整套检查:会话是编的,密钥是编的,不读你磁盘上的任何文件,也不写任何东西。对照结果:

stroq sent: did your AI agent pass your keys on?

This is a built-in sample. The key and the session are made up.
Nothing on this machine was read.

1 of your 1 key appears in your agent sessions: 1 sent to another company.

Checked 1 session (Claude Code) on 2026-10-15.
Compared with 1 key: .env.

SENT TO ANOTHER COMPANY: rotate these today (1)
 1. STRIPE_SECRET_KEY  from .env
    went to  collector.example, in a curl command
    when     2026-10-15 10:00 UTC · Claude Code · /sample/project
    do       revoke it at https://dashboard.stripe.com/apikeys, then update .env

Stroq names a send only when it sees the key in the command that sent it. A script, a file or a variable can carry a key out without showing it.
A key in a call was written by the AI, so your AI provider saw it too.
Stroq read a made-up session here: this check sent nothing and wrote nothing. No key values are printed.

Next: `stroq sent` checks every session on this machine. `stroq init` guards the next one.

报告只出现了密钥名 STRIPE_SECRET_KEY 和来源 .env,没有出现值。这就是官方一直强调的原则:命名凭证和那次工具调用,永不打印值。

真实检查时,一条密钥只会出现在它到达过的「最靠外」的那一档里。官方文档给出的五档是:

档位含义
Sent to another company某次已记录的调用把该密钥带到了不是它自己服务的主机
Maybe sent可能离开过:例如程序带着它跑了,或它被写进文件之后文件又被发送,但 Stroq 不能完全读清
Seen by the AIAgent 的模型看到了它(工具输出、提示或只读命令),没有看到一次外发
Used with its own service有严格证据表明它只被用在自己的官方接口,例如发往该服务自己的 API 主机
Blocked before it ranClaude Code 的记录显示这次调用被拒绝或被 Stroq 拦住了

「went to」的意思是那次调用的参数里带着这个密钥,并不证明对端主机保存了它,也不构成外部泄露的法庭证据。官方原文写得很清楚:把发现当作调查并轮换敏感凭证的理由,而不是已经失窃的证明。Stroq 也只在「命令文本里看见了密钥值」时才把一次外发记成 Sent;脚本、文件或变量把密钥带出去却不出现在命令里时,它看不到。

对本机做真实检查(会读取会话和密钥文件,仍然不打印值、不外传)可以按范围选择:

stroq sent                  # 这台机器上能找到的全部会话
stroq sent --here           # 只看当前项目
stroq sent --last           # 只看当前项目最新一条
stroq sent --transcript /path/to/session.jsonl

测试机没有可扫描的会话,官方说明这种情况下文本报告会说明原因并以退出码 1 结束。本课没有对测试机跑真实的 stroq sent(避免扫描共享环境里的密钥文件),请你在自己的电脑上运行。分享报告前请再看一眼:名字、路径和主机名仍可能敏感。

常见坑

  • Node 版本不够:系统还是 20.x 时,先换成 22 再装。本课就是这种情况。
  • 第一次用 npx 会下载包装:官方 session-secret-scan 页写明,首次调用会从 npm 拉 CLI。如果要在无网络或脚本里跑,请先 npm install -g @stroq/cli@0.30.0。
  • 没有会话不是故障:卡片会诚实地说找不到;sent --try 专门用来在这种情况下看懂报告格式。
  • 报告可以含路径和密钥名:可以给自己看,不要原样贴到公共渠道。计数版用 --share 或 sent --card。
  • 只认识当前还在磁盘上的密钥:已经轮换或删掉的值匹配不到;拆开、编码或变形后的值也可能漏掉。官方把这些限制写在「Not checked」里,而不是假装扫过了。

小结

你已经装好 Stroq 0.30.0,知道了命令分成「回看会话、打开仓库前检查、往后拦截」三组,并在没有历史会话的机器上看过卡片的空结果。用官方内置样例,你也看到了一份「密钥被发到另一家公司」的报告:只出现名字和来源,不出现值。下一课在实验目录里装上钩子,亲手喂一条「读到投毒 README 之后去跑远程脚本」的事件,看 Stroq 如何拦住它。