Borrowing it
Nothing to install: this file belongs to x0c/subswap. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/x0c/subswap/main/AGENTS.mdgit clone --depth 1 https://github.com/x0c/subswapWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/instructions/x0c/subswap/agents-md)<a href="https://agentmods.dev/instructions/x0c/subswap/agents-md"><img src="https://agentmods.dev/badge/instructions/x0c/subswap/agents-md/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/instructions/x0c/subswap/agents-md"><img src="https://agentmods.dev/badge/instructions/x0c/subswap/agents-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.06325 | $0.06325 |
| Opus 5.5 | $0.02530 | $0.02530 |
| Sonnet 5.5 | $0.01265 | $0.01265 |
| Haiku 4.5 | $0.00632 | $0.00632 |
Grade A, and why
subswap AGENTS.md scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Makes network callslowCapability
Not a fault in itself. Listed so you know the mod talks to something, and to what.
需要更细证据时自行加参数(如 `--log debug`、`swap` / `doctor`),不必等用户授权或提示;唯一约束是遵守本文件「不得高频打 usage / 禁止 curl 连发复现」等不变量。 How it starts
The opening of the file, as written. The whole thing — 205 lines — stays where its author put it; the contents beside it link to each section on GitHub.
subswap · Agent 快速规则
全局规范仍适用;本文件只保留本项目最容易漏掉、最影响安全性的规则。文档索引见下方「文档导航」。
最高优先级
- 功能新增或缺陷修复后,当轮完成本机交付;平时不发版,机主要求时直接发版。
每次改完:
- 跑测试 / 构建 / release 构建。
- 先覆盖安装本机
subswap/subswapd,重启 daemon,并验证构建产物哈希与实际行为。 - 提交并推送 Git。 机主要求发版(或修复已发布版本的严重缺陷)时,直接执行并等到 GitHub Release 完成再回复:
- 按语义化版本提升 workspace 版本并同步
Cargo.lock,只提交版本文件。 - 跑测试 / 构建 / release 构建,覆盖安装并验证版本与哈希。
- 创建并推送版本 tag、确认 GitHub Release 发布成功。
- GitHub Release publish 后
update-homebrew.yml会自动更新x0c/homebrew-tap的 formula,无需手动操作。 详见 docs/OPERATIONS_GUIDE.md §「Homebrew Tap 自动更新」。
- 修改代码前先查调用链。
编辑函数 / 方法 / 类型前用 codebase-memory-mcp 的
trace_path查清调用者 / 被调用者,评估影响面后再动手。 - 工作区可能是脏的。 不回滚、不覆盖无关本地改动;提交时只 stage 本次相关文件。
- 改完必须验证;排查也必须自己跑
subswap。 代码、配置、构建脚本、依赖改动后,自己跑对应测试 / build / smoke,不把验证交给用户。 排查任何默认入口 / 列表 / 额度 / 自动切换 / 写操作后状态面相关的故障或异常输出时,必须自己自由执行本机subswap(及相关子命令)对照真实输出——用户贴了一截截图或粘贴输出也不够;禁止只读文档、只读代码或只问用户「现在长什么样」就开始定性。 默认入口 / 自动切换这类必须对着真实列表才能确认的行为:覆盖安装后再自己跑一次无参subswap; 只跑cargo test不够——没装上的二进制用户还是旧逻辑。 需要更细证据时自行加参数(如--log debug、swap/doctor),不必等用户授权或提示;唯一约束是遵守本文件「不得高频打 usage / 禁止 curl 连发复现」等不变量。
项目不变量
- 手动
subswap swap永远不依赖 quota 查询;网络坏、quota API 坏、token 过期时也要能切走。 - Claude 自定义 API 账号必须标记
manual_only:只能手动切入,active 时禁用自动换号,也不能成为自动候选; 切回 OAuth 时必须恢复进入 API 模式前的settings.json.env受管字段。 subswap rm永不因 active /manual_only/「请先 swap」拒绝:删当前 Claude 自定义 API 须先退出 API 模式(恢复受管 env、清.subswap-api.json)再清本地;原生客户端登出失败只警告,仍删本地记录(客户端仍登录时下次入口可能再导入)。- Linux Release 预编译包用
cargo zigbuild钉 GLIBC 2.28 地板(见release.yml的objdump守卫);禁止在较新 Ubuntu runner 上直接cargo build发布 Linux 产物,否则会在 22.04 类主机出现GLIBC_2.39警告/起不来。 - macOS 上读写 Claude Code 的
Claude Code-credentials、以及 Cursor 命令行的cursor-access-token/cursor-refresh-tokenkeychain item 只能 fork/usr/bin/security, 禁止用keyringcrate(security-framework 原生 API):keyring 写会把 item ACL 重置成「仅 subswap」, 导致官方客户端(也用security读)每次切换后反复弹授权框。详见 docs/troubleshooting/2026-06-11-claude-code-keychain-acl-poisoning.md。 Cursor 官方钥匙串已有条目只改内容、禁止 delete 后再 add:删建会把解密权限收成「仅 security」, 桌面版界面邮箱对了、请求却报未登录。新建时才把/usr/bin/security和 Cursor.app 写入信任名单。- 测试隔离:集成测试禁止触碰真实登录钥匙串(否则
cargo test在 macOS 弹授权框并改写本机凭证)。 Claude 认SUBSWAP_CLAUDE_KEYCHAIN_PATH,Cursor 命令行认SUBSWAP_CURSOR_KEYCHAIN_PATH;cli_surface.rs::isolated_subswap已把两者都指到同一份一次性 keychain。 新写的会激活 Claude OAuth 或 Cursor 命令行钥匙串的集成测试也必须经它隔离。
- 测试隔离:集成测试禁止触碰真实登录钥匙串(否则
- Cursor 命令行的令牌与身份必须成套读写:切换时同时写令牌后端和
cli-config.json的authInfo。 live 主人只认令牌 JWT,不得用过期邮箱去对号;仓库里令牌 JWT 与账号身份不一致时显示needs re-login, 禁止拿这份令牌查额度或刷新(会把真正主人的一次性 refresh token 刷废)。 详见 docs/PROVIDER_KNOWLEDGE_BASE.md 的「Cursor」与 docs/troubleshooting/2026-08-14-cursor-quota-cloned-across-accounts.md。 subswap run claude的隔离.claude.json必须包含hasCompletedOnboarding: true, 否则 claude 无论钥匙串里有无有效凭证都会弹「Select login method」首次引导—— 由materialize_isolated调mark_onboarding_complete写入;改隔离物化流程时不得删除该调用。 详见 docs/design/ACCOUNT_ISOLATION_DESIGN.md §2.3。Provider::activate必须先写快照,任一目标写失败要回滚。- refresh token 是一次性轮换,active 账号默认只读不刷;允许自愈的唯一例外是复用原生客户端官方协调机制,
绝不能由 subswap 自创一套互不相认的锁或并行抢刷:Codex 通过官方 app-server 查询/刷新,Kimi 只在能
识别并持有当前版本官方跨进程锁时刷新,Claude 只在
claude --version达到已核实版本并持有官方.oauth_refresh.lock与旧版<dir>.lock时续期(持锁重读、采用他人轮换、比较写入,经/usr/bin/security写回;见 PROVIDER_KNOWLEDGE_BASE「Active credential renewal under the official lock」), Cursor active 账号只重读 live、不刷新。activate覆盖 live 文件前先 capture-on-leave 回灌 live 凭证进 owner 账号 store; parked 账号按各 Provider 的串行化边界刷新;Cursor 必须使用 subswap 跨进程锁。daemon 每轮还做 capture-on-arrival (reconcile_active_from_live,只 live→store) 补「绕过 swap 离开」的缺口;refresh 被上游拒绝时必须有 死 token 守卫止住反复刷的风暴并显示needs re-login,Kimi/Cursor 的跨进程守卫只保存 refresh token SHA-256 指纹、不保存 secret。细节见 docs/PROVIDER_KNOWLEDGE_BASE.md 的「Refresh token 轮换」。capture_live_into_store绝不能用缺 access / refresh 的 live 快照覆盖 store 里对应凭据完整的副本 (会把账号静默写死),各 Provider 都必须保留守卫,改此逻辑前见 docs/troubleshooting/2026-06-18-live-capture-clobbers-refresh-token.md。 - 新 Provider 只能放在
crates/providers/<id>,再到AppContext::build()注册,并在默认入口同步本地 active。 Cursor 这类凭证位于 SQLite、切换还要协调 GUI 生命周期的 Provider 必须独立实现Provider,不能硬塞进 文件型 JSON 共享引擎;Cursor 也不支持subswap run/shell/env隔离运行。细节见 docs/PROVIDER_KNOWLEDGE_BASE.md 的「Cursor」与 docs/design/ARCHITECTURE.md 的「扩展新 Provider」。 - 共享逻辑禁止绑定具体 Provider:
core/cli/daemon不得出现provider == "<某id>"这类 按名分发的决策、提示或分支。Provider 差异必须以Providertrait 能力声明(额度池语义、 切换后客户端提示、断开提示、凭证字段、隔离支持),调用方只认抽象;新 Provider 只覆盖 与 defaults 不同的 hook。能力清单见 docs/design/ARCHITECTURE.md 的「扩展新 Provider」。 - OpenCode 官方 Console 账号与 Go API Key 是独立 Provider:
opencode只放官方账号,opencode-api-key只放 Key 且全部manual_only。自动换号只在官方账号间进行;V2 切 Key 必须经官方数据库与opencode auth switch opencode-go,只改旧auth.json不算切换成功。详见 docs/PROVIDER_KNOWLEDGE_BASE.md 的「OpenCode Console official sign-in and Go monitoring」。 - 文件型(凭证是本地一个 JSON blob、靠覆盖文件切换)provider 的切换机制统一在
crates/providers/common(FileBlobProvider<A>引擎)。新增此类 provider(如未来第三个)只写一个FileBlobRuntime实现 (路径、元数据解析、刷新、usage 查询等差异点),在AppContext::build()的 provider 列表注册一行, 若要支持subswap run/shell/env隔离运行再把它塞进isolated: HashMap<&str, Arc<dyn IsolatedProvider>>表(FileBlobRuntime有隔离能力时自动获得IsolatedProviderblanket impl)——隔离分发 (run.rs内的 materialize/absorb/env_vars/native_cli 查表逻辑)因此不用改。但run.rs的normalize_provider仍需加一行别名匹配(把用户输入的 provider 名解析成规范 id,纯文本解析, 查表机制吸收不了);login.rs必须新增一个该 provider 专属的 match 分支——登录流程从未做成 通用查表(Codex 走codex login子进程、Claude 走claude auth login --claudeai、Kimi 是纯导入 已登录凭证,语义各不相同),每个新 provider 都要写自己的登录分支。历史数据兼容用两个可选 hook:store_field()(凭证仓库里存 blob 的字段名,默认"blob")与dedup_extra_key()(registry.toml extra里去重键的字段名,默认"dedup_key")——仅当迁移一个已有存量账号数据、且旧字段名与默认值 不同的 provider(如 Codex 分别覆盖成"auth_json"/"chatgpt_account_id")时才需要覆盖,全新 provider(如 Kimi)用默认值即可。Claude 因 macOS 钥匙串 + API 账号特殊逻辑,不在此引擎上,run.rs保留其专用分支。 - AutoSwap 默认阈值只改
crates/core/src/defaults.rs::AUTO_SWAP_THRESHOLD,并同步 docs/design/AUTO_SWAP_DESIGN.md。 async fn内不得直接做阻塞 IO;文件锁、std::fs、keyring 等必须包进tokio::task::spawn_blocking。- 写入
registry.toml的Option<T>字段必须加#[serde(skip_serializing_if = "Option::is_none")],避免 TOML null 报错。 - CLI 子命令、Rust 标识符、英文文案统一用
swap,不要用switch。 swap/rm的数字编号必须与默认入口显示顺序一致,统一走AppContext::list_ordered()。- 跨模块调优参数走
crates/core/src/settings.rs::current(),不要在 provider / cli 里硬编码阈值、窗口、百分比。 - 不得用高频 quota / usage 请求模拟限流触发;必须保守退避,避免请求风暴和风控风险。
Anthropic usage 端点限流极严(~每账号每分钟 1 次),禁止手动
curl连发去"复现"——会打爆桶、 污染判断。查询前先走缓存节流:缓存比settings.quota.min_refresh_interval_ms(默认 90s) 新就复用、 不打端点;daemon 与 CLI 共用quota_cache.json,两条路径都要尊重。429 ≠ token 失效,三种「查不出」 的区分与处理见 docs/PROVIDER_KNOWLEDGE_BASE.md 的「Usage 接口异常状态码」; 根因与修复历史见 docs/troubleshooting/TROUBLESHOOTING_INDEX.md。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 3d ago Changed · -58 tokens per session abc0df877eb9
- 4d ago Changed · +5 lines · +202 tokens per session 9d31c77390f4
- 18d ago Changed · +2 lines · +172 tokens per session ab7826a67bc1
- 20d ago Changed · +5 lines · +148 tokens per session 4ca376f6c583
- 27d ago Changed · +118 tokens per session a3f5f81f1841
- 29d ago Changed · +6 lines · -4 tokens per session c36f4b9cfb47
- 1mo ago Changed · +1 lines · +50 tokens per session da7007ab67cf
- 1mo ago Changed · +154 tokens per session 83c8c621f227
- 1mo ago Changed · +25 tokens per session 04d54caea100
- 1mo ago First seen · 186 lines · 5,518 tokens per session scan A 34db4de7dc57
subswap AGENTS.md is an instructions file published in the GitHub repository x0c/subswap (6 stars, last pushed 3d ago), licensed MIT. It adds 6,325 tokens to every session, about $0.0253 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other instructions, from other repositories
vscode buildNext.instructions.md
Working notes and architecture documentation for the new esbuild-based build system in build/next. Use when making changes to the new build pipeline (transpile/bundle commands, NLS plugin, source-map handling, resource copying, or self-hosting watch tasks).
next.js AGENTS.md
AGENTS.md instructions for vercel/next.js, covering next.js development guide, codebase structure, monorepo overview, core package: packages/next and other important packages.
vscode oss-third-party-notices.instructions.md
Instructions for microsoft/vscode, covering vs code oss third-party-notices pipeline, architecture, pipeline flow in ci, cache eligibility and rollout and applying the notice (cutover).
langchain AGENTS.md
AGENTS.md instructions for langchain-ai/langchain, covering global development guidelines for the langchain monorepo, corridor security analysis, project architecture and context, monorepo structure and development tools & commands.
vscode copilot-instructions.md
Copilot instructions for microsoft/vscode, covering vs code copilot instructions, project overview, root folders, core architecture (src/ folder) and built-in extensions (extensions/ folder).
deepseek-harness AGENTS.md
AGENTS.md instructions for deepseek-ai/deepseek-harness, covering agents.md, pre-stable apis and released session data, repository layout, commands and host sandbox failures.