context-doctor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Doctor
Context Doctor
Every session opens with a fixed tax paid before the user speaks: system prompt, tool definitions, MCP servers, plugins, skill descriptions, subagents, memory/rules files. Some is load-bearing; much is junk — unused in this repo yet shipped every turn, shrinking the window and feeding rot. This skill is the cleanup pass. Run it on "why is my context so full", token-budget triage, or after the user connects a pile of tools/MCP/skills.
You are the instrument — you can see your own loaded context. Read what you were actually given this session and cross-check it against real usage; don't guess what the harness injects.
每次 session 在用户开口之前,都要先支付一笔固定成本:system prompt、tool definitions、MCP servers、plugins、skill descriptions、subagents、memory/rules files。其中一部分不可或缺;大量内容却只是垃圾——在当前 repo 中没用到,却每轮都被加载,挤占 context window,并让内容逐渐腐化。这个 skill 就是一次清理流程。可在“为什么我的 context 这么满”、token-budget 排查时,或用户接入大量 tools/MCP/skills 后运行。
你就是检测工具本身——能够看到本次 session 实际加载的 context。读取本 session 真正收到的内容,并将其与实际使用情况进行交叉核对;不要猜测 harness 会注入什么。
The surfaces
各类上下文
Split by who controls it:
- Harness-injected — system prompt, the core-loop scaffolding, provider attachments. Mostly unchangeable; account for it. But less is truly fixed than it looks: on the Anthropic harness many built-in tools and whole feature subsystems are now switch-off-able — see Fix G.
- User-controlled (your target):
- Tool definitions — built-ins plus every MCP/connector tool. Usually the largest, most ignorable chunk. Built-in tools you never use in this repo (plan mode, notebooks, artifacts, cron, the ask-question UI…) can be denied by name.
- Feature subsystems — bundled-skill catalogues, the multi-agent workflow engine, remote control, connectors. Each ships its own tool defs; many drop with a single flag.
- MCP servers — project, user-level, and provider-synced "connectors" (enabled on a vendor site, synced down).
- Plugins — bundle their own tools/skills/MCP.
- Skills — each auto-loadable one spends its +
nameevery turn just to stay discoverable.description - Subagents — each definition costs tokens.
- Memory & rules — /
CLAUDE.md/ memory indexes at every scope; always-on, paid every turn.AGENTS.md
按控制方划分:
- Harness 注入——system prompt、core-loop scaffolding、provider attachments。大多无法更改,但应纳入评估。不过,真正固定的部分远少于表面所见:在 Anthropic harness 上,许多内置工具和完整的功能子系统如今都可以关闭——见 G 项。
- 用户可控(你的目标):
- Tool definitions——内置工具以及每个 MCP/connector tool。通常是最大、也最容易被忽略的一块。本 repo 中从不使用的内置工具(plan mode、notebooks、artifacts、cron、ask-question UI 等)可以按名称禁用。
- Feature subsystems——bundled skill 目录、multi-agent workflow engine、remote control、connectors。每个子系统都有自己的 tool definitions;许多只需一个开关即可移除。
- MCP servers——项目级、用户级 MCP servers,以及由 provider 同步的“connectors”(在 vendor 站点上启用后同步下来)。
- Plugins——会捆绑自己的 tools/skills/MCP。
- Skills——每个可自动加载的 skill 为了保持可发现性,每轮都会消耗其 +
name。description - Subagents——每个定义都会消耗 tokens。
- Memory 与 rules——各作用域下的 /
CLAUDE.md/ memory indexes;始终启用,每轮都要付费。AGENTS.md
Method
方法
1. Measure. Inventory your own context, concretely:
- tools grouped by origin (built-in vs. each MCP server / connector / plugin); flag namespaces you never call here.
- skills + descriptions; auto-loaded vs. invoke-only.
- MCP servers and where each is configured.
- subagents and memory/rules in effect.
Read the harness's own breakdown first if it has one — the Anthropic harness's command reports tokens by category (system prompt, system tools, MCP tools, memory files, messages); for individual tool sizes a logging proxy that intercepts the API request and ranks each tool def is the deepest view. Rank by per-section token count when exposed, else by definition count — a server with 40 tool defs is a fat target.
/context2. Correlate. Bloat is loaded but unused. Look past this session:
- Scan past transcripts for the project (Claude Code: ; other agents store theirs elsewhere). What was ever actually invoked? Loaded in 100 sessions, called in zero is the cleanest cut.
~/.claude/projects/**/<uuid>.jsonl - A tool doesn't only leave its trace in transcripts — check for artifacts it persists on disk. Some subsystems write durable run files that survive even when a transcript is summarized, truncated, or gone. The clearest example: the workflow engine writes run files and a
wf_*.jsondir underscripts/every time it runs. Their presence is proof the user runs workflows — stronger than any transcript grep. Before proposing to disable any surface, look for its on-disk footprint too, not just message history:~/.claude/projects/**/<uuid>/workflows/bash# Workflow usage — across ALL projects, not just this repo (a global flag reaches every project) find ~/.claude/projects -type d -name workflows 2>/dev/null | head find ~/.claude/projects -path '*/workflows/wf_*.json' 2>/dev/null | head - Absence of evidence is not evidence of absence — and it is never grounds for a confident "you don't use this." You searched one machine's local history; the user may run the feature in projects you didn't scan, in sessions already pruned, or on another machine. When you find no usage, say exactly that — "I found no trace of X in your local transcripts or run files" — and let the user confirm before cutting. Reserve "you don't use it" for surfaces with a positive dead signal (e.g. a connector for a service with zero footprint in the repo). Never turn silence into an assertion.
- Cross-check the repo: a Supabase/Vercel/Notion connector in a repo with no trace of that service is dead weight.
- Note heavy skills or servers riding along in sessions whose task never touches them.
3. Research. For each cut, look up how this harness disables or scopes that surface today, and at which scope (global/project/local) — scope sets the blast radius.
4. Propose. Present a ranked table — surface → est. saving → mechanism → scope → why safe. For every change, explain plainly what the mechanism does and what the user gives up — the goal is an informed decision, not just a smaller number; the user may knowingly keep some bloat. For any blanket switch, enumerate exactly what it turns off (every connector, server, or skill) — never let the user approve a broad cut blind. Get approval, apply, re-measure.
1. 测量。 具体清点当前自己的 context:
- 按来源对 tools 分组(内置工具,以及各 MCP server / connector / plugin);标记本环境从不调用的 namespaces。
- skills 及其 descriptions;区分自动加载与仅 invoke-only。
- MCP servers 及其配置位置。
- 当前生效的 subagents 与 memory/rules。
如果 harness 自身提供 context breakdown,应先读取。Anthropic harness 的 命令会按类别报告 token 数(system prompt、system tools、MCP tools、memory files、messages);若要查看单个 tool 的大小,最深入的方法是使用一个拦截 API 请求并为每个 tool definition 排名的 logging proxy。如果能够获取各部分的 token 数,就按它排序;否则按 definition 数量排序——一个拥有 40 个 tool definitions 的 server 就是明显的大目标。
/context2. 关联。 臃肿的本质是已加载但未使用。应超越本次 session 进行检查:
- 扫描该项目的历史 transcripts(Claude Code:;其他 agent 会将记录存放在其他位置)。究竟实际调用过什么?一个在 100 次 session 中被加载、调用次数却为 0 的工具,是最干净的裁剪对象。
~/.claude/projects/**/<uuid>.jsonl - 工具留下的痕迹不仅存在于 transcripts 中——还要检查它持久化在磁盘上的 artifacts。 某些子系统会写入持久的 run files,即使 transcript 被摘要、截断或删除,这些文件仍然存在。最明显的例子是:workflow engine 每次运行时,都会在 下写入
~/.claude/projects/**/<uuid>/workflows/run files 和一个wf_*.json目录。 它们的存在能够证明用户确实在运行 workflows——这是比 grep transcript 更强的证据。在建议禁用任何上下文项之前,除了消息历史,还要检查其磁盘 footprint:scripts/bash# Workflow usage — across ALL projects, not just this repo (a global flag reaches every project) find ~/.claude/projects -type d -name workflows 2>/dev/null | head find ~/.claude/projects -path '*/workflows/wf_*.json' 2>/dev/null | head - 没有证据并不等于证据不存在——它绝不能成为确信声称“你没有使用它”的依据。 你只搜索了一台机器的本地历史;用户可能在你未扫描的项目、已被清理的 session,或另一台机器上使用该功能。找不到使用记录时,应准确表述——“我在你的本地 transcripts 或 run files 中没有找到 X 的任何踪迹”——并在裁剪前让用户确认。只有出现明确的闲置信号时,才可保留“你不使用它”的结论,例如某个 connector 对应的服务在 repo 中完全没有 footprint。绝不能把沉默变成断言。
- 交叉检查 repo:如果某个 repo 中完全找不到 Supabase/Vercel/Notion connector 对应服务的踪迹,它就是无效负担。
- 留意那些搭便车加载的重量级 skills 或 servers:当前 session 的任务根本没有涉及它们。
3. 研究。 对每项裁剪,查明当前 harness 如何禁用或限定该上下文项,以及它作用于哪个作用域——作用域决定影响范围。
4. 提出方案。 给出一张排名表——上下文项 → 预计节省 → 机制 → 作用域 → 安全原因。对于每项变更,通俗说明该机制会做什么,以及用户会失去什么——目标是帮助用户作出知情决策,而不只是得到一个更小的数字;用户可能有充分理由保留部分臃肿内容。对于任何全局开关,必须准确枚举它会关闭的全部内容(每一个 connector、server 或 skill)——绝不能让用户在不了解影响范围的情况下盲目批准大范围裁剪。获得批准后再应用,并重新测量。
Fixes
修复方案
A. Prune MCP servers & connectors — the biggest win if you don't use them
A. 裁剪 MCP servers 与 connectors——如果不用它们,这是收益最大的一项
Provider-synced connectors (enabled once on a vendor site, then present every session) are the classic offender — but plenty of people genuinely use them (Notion, Supabase, …), so this is never a safe default. Real before/after from this user:
Before: … WebFetch, WebSearch, mcp__claude_ai_Canva__* (×40),
mcp__claude_ai_Gmail__*, mcp__claude_ai_Google_Drive__*, mcp__claude_ai_Miro__*,
mcp__claude_ai_Notion__*, mcp__claude_ai_Supabase__* (×30), mcp__claude_ai_Vercel__* (×30),
mcp__plugin_posthog_posthog__*, … mcp__ide__*, mcp__plugin_context7_*
After: … WebFetch, WebSearch, mcp__executor__*, mcp__ide__*, mcp__plugin_context7_context7__*Every and the unused PostHog plugin gone: ~1,500 → ~100 tokens, every turn. Two shapes (confirm the current setting):
mcp__claude_ai_*- Kill switch — one flag drops all synced connectors (e.g. ). Before recommending it, list every connector it will disable so the user sees what they lose; only right when they use none here.
disableClaudeAiConnectors: true - Per-server — disable by name, keep the few you use. Usually better, since the switch is all-or-nothing.
Scope it: project vs. global changes what other repos see.
由 provider 同步的 connectors(在 vendor 站点上启用一次,此后每个 session 都会出现)是最典型的元凶——但确实有很多人真正使用它们(Notion、Supabase 等),因此绝不能将其作为安全默认值。用户实际应用前后的效果:
Before: … WebFetch, WebSearch, mcp__claude_ai_Canva__* (×40),
mcp__claude_ai_Gmail__*, mcp__claude_ai_Google_Drive__*,
mcp__claude_ai_Miro__*, mcp__claude_ai_Notion__*,
mcp__claude_ai_Supabase__* (×30), mcp__claude_ai_Vercel__* (×30),
mcp__plugin_posthog_posthog__*, … mcp__ide__*, mcp__plugin_context7_*
After: … WebFetch, WebSearch, mcp__executor__*, mcp__ide__*, mcp__plugin_context7_context7__*所有 和未使用的 PostHog plugin 都被移除:每轮约 1,500 → 约 100 tokens。有两种方式(需确认当前设置):
mcp__claude_ai_*- Kill switch——一个开关即可移除所有同步的 connectors,例如 。推荐前,必须列出它将禁用的每一个 connector,让用户清楚自己会失去什么;只有当用户在此处一个都不用时才适合采用。
disableClaudeAiConnectors: true - 按 server 禁用——按名称禁用,保留少数真正使用的 server。通常更好,因为 kill switch 是全有或全无的。
确定作用域:project 与 global 的区别决定了其他 repos 能否看到这些变更。
B. Gate rarely-used skills behind explicit invocation
B. 将低频使用的 skills 置于显式调用之后
A skill useful here but irrelevant to most tasks still spends its description every turn. Make it invoke-only:
- Claude Code: in frontmatter (this skill uses it) — the skill stops auto-loading and runs only when the user types it explicitly.
disable-model-invocation: true - Other harnesses ignore the flag; instead move the skill off the auto-discovered path so it's read only on request.
Both mechanisms make the skill user-invoke-only — the harness can no longer load it on the model's behalf, so an auto-trigger and a rules-file pointer alike stop being able to pull it in (see the gate/pointer guardrail before pairing a gate with a rules-file mention).
First check the skill earns its keep as invoke-only. Some skills are meant to trigger exactly when relevant, and a good + auto-trigger already delivers "loads when relevant, quiet otherwise." Only gate skills genuinely rarely relevant to this repo's work.
descriptionSuggest gating (or relocation), never apply silently — and spell out the consequence: after the flag the skill no longer surfaces on its own, so any value it got from auto-triggering on file context is gone and the user must remember to invoke it.
某个 skill 即使只在这里有用、与大多数任务无关,其 description 仍会每轮消耗 tokens。应将其设为 invoke-only:
- Claude Code:在 frontmatter 中设置 (这个 skill 采用了该设置)——skill 将停止自动加载,并且仅在用户明确输入它时运行。
disable-model-invocation: true - **其他 harness:**忽略该标志;应将 skill 移出自动发现路径,使其只在收到请求时读取。
两种机制都会让 skill 变成 user-invoke-only——harness 不再代表模型加载它,因此自动触发和 rules 文件指针都无法再将其拉入 context(在将 gate 与 rules 文件提及配对前,先参阅 gate/pointer guardrail)。
首先确认 skill 作为 invoke-only 是否仍然值得保留。 有些 skill 的设计目的就是恰好在相关场景下触发,而良好的 + auto-trigger 已经能够做到“相关时加载,否则保持安静”。只应 gate 那些在当前 repo 的工作中确实极少相关的 skills。
description建议 gate(或迁移),绝不能静默应用——并明确说明后果:设置该标志后,skill 不再自行浮现,因此它过去通过文件上下文自动触发所获得的价值将会消失,用户必须记得主动调用它。
C. Route monolithic skills
C. 路由巨型 skills
A skill that inlines a big doc forces the whole payload in whenever it loads, even for tasks touching none of it. Refactor to a router — a tiny dispatch table, with heavy content in sibling files read on demand:
md
undefined如果一个 skill 内联了一份大型文档,那么每次加载它时都会强制载入整个 payload,即使当前任务完全没有涉及其中内容。应将其重构为一个 router——一份轻量的分发表,将重量级内容放在同级文件中按需读取:
md
undefinedDatabase toolkit (router)
Database toolkit (router)
- Running a migration? → read ./migrations.md
- Writing a seed? → read ./seeds.md
- Debugging a slow query? → read ./query-perf.md
A force-loaded router costs only the table. Harness-agnostic — recommend it for any large always-loaded skill with conditional content.- Running a migration? → read ./migrations.md
- Writing a seed? → read ./seeds.md
- Debugging a slow query? → read ./query-perf.md
force-loaded router 的成本仅为这张表。该方法与 harness 无关——建议对任何包含条件性内容的大型 always-loaded skill 都采用这种方式。D. Delete what's dead
D. 删除死内容
Unused skills, orphaned subagents, stale MCP entries — if history shows zero use and the repo gives no reason to keep them, propose deletion. Exception: a skill or rule mirrored across and is not a dupe to collapse — see the dual-home guardrail.
.claude.agents未使用的 skills、孤立的 subagents、过时的 MCP entries——如果历史记录显示零使用,且 repo 中没有理由保留,就建议删除。**例外:**同时镜像在 与 中的 skill 或 rule 并不是可以合并的重复项——见 dual-home guardrail。
.claude.agentsE. Trim always-on memory & rules
E. 裁剪始终加载的 memory 与 rules
CLAUDE.mdAGENTS.mdBetter than trimming: turn conditional rules into a skill. When a block of an always-on rules file is really task-specific — e.g. a global "how to scaffold a new project" guide loaded in every repo but relevant only when starting one — lift it into a skill. The body leaves context; only its one-line description stays, loading when the task calls for it. The trade: no longer guaranteed present, so surface that and let the user choose. (Same move for router-shaped content → C, or directory-specific rules → F.)
Watch for / inline includes that force conditional content always-on. A rules-file line like pastes that file's entire body into context every turn — same cost as inlining it. If the content is conditional (e.g. TypeScript coding standards, useless during a pure-docs task) that whole body is bloat, and if the file is also a registered skill it's loaded twice.
@import@.agents/skills/quality-code/SKILL.mdThe fix: downgrade the heavy import to a light pointer — keep the mention, drop the body. Replace the with a one-line "for coding, follow the skill" note. That preserves what the user wanted the import for — emphasis: a rules-file line explicitly saying "load this when you do X" makes the model far likelier to pull that skill than if it were one of 20 in the list — while the body now loads on demand instead of every turn. (Works only while the skill stays auto-loadable — see the gate/pointer guardrail.) Do not silently delete the mention: people import a skill precisely because it's the important one they want highlighted, they just don't want its full text always-on.
@importquality-codeTwo things to keep straight: don't delete the target file (the skill still needs it), and know you're removing the import line, not the skill.
CLAUDE.mdAGENTS.md比裁剪更好的办法:将条件性 rules 转换为 skill。 当 always-on rules 文件中的一块内容实际上只针对特定任务时,例如一个在每个 repo 中加载、却仅在创建新项目时才相关的全局“如何搭建新项目”指南,就应将其提取为一个 skill。正文会离开 context,只保留一行 description;在任务需要时再加载。代价是它不再保证始终存在,因此应明确说明这一点并让用户选择。对于 router 形态的内容可采用同样做法(见 C),目录专属 rules 则见 F。
警惕会强制条件性内容始终加载的 / inline includes。 rules 文件中的一行 会将该文件的完整正文每轮粘贴进 context——成本与内联完全相同。如果内容具有条件性(例如 TypeScript 编码规范在纯文档任务中毫无用处),整段正文就是负担;如果该文件同时还是已注册的 skill,它还会被加载两次。
@import@.agents/skills/quality-code/SKILL.md修复方法是:将重量级 import 降级为轻量指针——保留提及,移除正文。 把 替换为一行“进行编码时,请遵循 skill”的说明。这样既保留了用户引入该 skill 的目的——强调:rules 文件中明确写着“执行 X 时加载它”,比它只是 20 个 skill 列表中的一个普通条目更能促使模型拉取它——又能让正文改为按需加载,而不是每轮加载。(这只在 skill 保持 auto-loadable 时有效——见 gate/pointer guardrail。)**不要静默删除提及:**人们 import 某个 skill,正是因为它是希望被重点强调的 skill,只是并不希望其完整文本始终加载。
@importquality-code必须分清两件事:不要删除目标文件(skill 仍然需要它),并要清楚自己删除的是 import 行,而不是 skill。
F. Scope rules with nested memory
F. 使用嵌套 memory 限定 rules 作用域
The root rules file is the worst home for conditional guidance — "how to run a migration", "how to add a UI component" — paid every turn including the 90% that never touch that area. Most harnesses load nested memory on demand: a / in a subdirectory enters context only when the agent touches that subtree. So the fix is usually relocation, not deletion:
CLAUDE.mdAGENTS.mdBefore: After:
CLAUDE.md (always loaded) CLAUDE.md ← cross-cutting rules only
# DB migrations … (30 lines) packages/database/CLAUDE.md ← loads on DB work
# UI components … (25 lines) packages/ui/CLAUDE.md ← loads on UI workContent survives and arrives exactly when relevant; unrelated turns stop paying. Confirm the trigger and file name per agent.
根 rules 文件是放置条件性指导的最差位置——例如“如何运行 migration”“如何添加 UI component”——即便 90% 的任务从未涉及这些内容,它们仍会每轮付费。大多数 harness 会按需加载嵌套 memory:子目录中的 / 只有在 agent 触及该子树时才会进入 context。因此,修复方式通常是迁移,而不是删除:
CLAUDE.mdAGENTS.mdBefore: After:
CLAUDE.md (always loaded) CLAUDE.md ← cross-cutting rules only
# DB migrations … (30 lines) packages/database/CLAUDE.md ← loads on DB work
# UI components … (25 lines) packages/ui/CLAUDE.md ← loads on UI work内容得以保留,并且恰好在相关时到达;无关任务不再为此付费。需针对每个 agent 确认触发条件和文件名。
G. Disable built-in tools & feature subsystems you don't use
G. 禁用不用的内置工具与功能子系统
Fixes A–F trim what you added. But a large, ignorable chunk is first-party — built-in tools and whole subsystems shipped every turn whether this repo needs them or not. On the Anthropic harness two mechanisms (global , project ) turn them off.
settings.json~/.claude/.claude/Harness-specific — this is the Anthropic Claude Code shape only. The keys below don't exist on Codex, OpenCode, Pi, or others. Treat them as a worked example of the idea — "find the config that drops unused built-in tooling" — and, for any other agent, research that agent's own docs for its equivalent before recommending anything. (Codex, for instance, configures tools differently and has no/permissions.denyflags.)disable*
G1 — Feature flags: one key drops a whole subsystem.
| Flag | Drops | What the user gives up |
|---|---|---|
| the | multi-agent orchestration / "ultracode" runs. Before proposing this, check the on-disk footprint (Method step 2): |
| Anthropic's bundled skill catalogue ( | the model auto-loading them — but their slash commands stay typable, so |
| the | publishing HTML/Markdown artifact pages |
| remote-control / push tooling | driving the session remotely |
| all provider-synced connectors at once | every connector — same kill switch as Fix A; list them before flipping it |
G2 — Deny built-in tools by name. strips each named tool's definition from every turn. Name the high-consequence ones out loud so the user decides with eyes open — several change the UI, not just the token count:
permissions.deny: ["EnterPlanMode", "AskUserQuestion", …]- +
EnterPlanMode→ removes plan mode entirely. Shift-Tab plan mode stops working. Keep both if the user ever plans before editing.ExitPlanMode - → removes the multiple-choice question UI. The model can no longer pop option chips to disambiguate; it falls back to asking in plain prose — or to guessing instead of asking. Real UX loss, not free.
AskUserQuestion - → no Jupyter
NotebookEditediting. Safe to drop in a repo with no notebooks..ipynb - /
CronCreate/CronDelete,CronList→ no scheduled or self-paced recurring agents (ScheduleWakeup,/schedule)./loop - ,
SendMessage,PushNotification,RemoteTrigger,DesignSync→ inter-agent messaging, notifications, and review plumbing — deny whatever this workflow never triggers.ReportFindings
G3 — : gate a skill from settings, not frontmatter. removes a skill from the payload entirely; keeps its slash command typable but hides it from the model. This is the Fix-B gate applied from settings — so it works on bundled and plugin skills whose frontmatter you don't own.
skillOverridesskillOverrides: { "some-skill": "off" }"user-invocable-only"Don't strip the machinery your own workflow rides on. Background jobs and multi-agent runs depend on the Task tools, , and the worktree tools; scheduled/recurring agents depend on the cron tools. If the user runs , scheduled agents, or workflows, keep those — the definition cost buys a feature they actually use. Some of what looks like bloat is load-bearing machinery.
Workflow/loopIllustrative combined cut (confirm each key still exists, and that the user uses none of what it removes):
json
{
"permissions": {
"deny": ["EnterPlanMode", "ExitPlanMode", "NotebookEdit",
"AskUserQuestion", "CronCreate", "CronDelete", "CronList",
"ScheduleWakeup", "SendMessage", "PushNotification",
"RemoteTrigger", "DesignSync", "ReportFindings"]
},
"disableBundledSkills": true,
"disableWorkflows": true,
"disableRemoteControl": true,
"disableClaudeAiConnectors": true,
"disableArtifact": true
}Re-measure with afterward — a full strip like this recovers tens of thousands of tokens per turn. But every line above is a behavior change, not just a smaller number: present each with its consequence and let the user opt in per item. Many will knowingly keep plan mode, the question UI, artifacts, or workflows — that's the informed decision, not a failure to cut.
/contextA–F 项裁剪的是你添加的内容。但还有一大块容易被忽略的内容来自第一方——无论当前 repo 是否需要,内置工具和完整子系统都会每轮加载。在 Anthropic harness 上, 中有两种机制(全局 、项目 )可以关闭它们。
settings.json~/.claude/.claude/仅限 Harness——这只是 Anthropic Claude Code 的配置形态。 以下配置项不存在于 Codex、OpenCode、Pi 或其他 agent 中。应将它们视为“寻找可移除未使用内置工具的配置”这一思路的示例——针对其他 agent,必须先研究其自身文档中的对应机制,再提出建议。(例如,Codex 的 tools 配置方式不同,并且没有/permissions.deny标志。)disable*
G1——Feature flags:一个配置项即可移除完整子系统。
| 标志 | 移除内容 | 用户会失去什么 |
|---|---|---|
| | multi-agent orchestration / “ultracode” runs。提出此建议前,检查磁盘 footprint(方法步骤 2): |
| 从模型 payload 中移除 Anthropic bundled skill 目录( | 模型自动加载它们的能力——但其 slash commands 仍可手动输入,因此 |
| | 发布 HTML/Markdown artifact pages 的能力 |
| remote-control / push tooling | 远程驱动 session 的能力 |
| 一次性移除所有由 provider 同步的 connectors | 每一个 connector——与 A 项中的 kill switch 相同;启用前必须列出它们 |
G2——按名称 deny 内置 tools。 会从每一轮中移除每个指定 tool 的 definition。应明确说出后果较重的工具,让用户能够清醒决策——其中几项改变的是 UI,而不只是 token 数量:
permissions.deny: ["EnterPlanMode", "AskUserQuestion", …]- +
EnterPlanMode→ 完全移除 plan mode。 Shift-Tab plan mode 将不再可用。如果用户会在编辑前进行规划,就应保留两者。ExitPlanMode - → 移除 multiple-choice question UI。 模型无法再弹出选项卡片来消除歧义;它会退回到使用普通文本提问——或者直接猜测而不询问。这是真实的 UX 损失,并非免费优化。
AskUserQuestion - → 无法编辑 Jupyter
NotebookEdit文件。对于没有 notebooks 的 repo,可以安全移除。.ipynb - /
CronCreate/CronDelete、CronList→ 无法使用 scheduled 或 self-paced recurring agents(ScheduleWakeup、/schedule)。/loop - 、
SendMessage、PushNotification、RemoteTrigger、DesignSync→ inter-agent messaging、notifications 和 review plumbing——应 deny 当前 workflow 从不触发的任何相关工具。ReportFindings
G3——:通过 settings 而非 frontmatter 对 skill 进行 gate。 会将 skill 彻底从 payload 中移除; 则保留可手动输入的 slash command,但将其对模型隐藏。这就是从 settings 应用的 B 项 gate——因此可用于那些并不由你控制 frontmatter 的 bundled 和 plugin skills。
skillOverridesskillOverrides: { "some-skill": "off" }"user-invocable-only"不要移除当前 workflow 自身依赖的基础设施。 Background jobs 和 multi-agent runs 依赖 Task tools、 以及 worktree tools;scheduled/recurring agents 则依赖 cron tools。如果用户会运行 、scheduled agents 或 workflows,就应保留它们——definition 的成本是在购买一项实际使用的功能。有些看似臃肿的内容,正是承重的基础设施。
Workflow/loop组合裁剪示例(需确认每个配置项仍然存在,并确认用户不使用其中任何被移除的功能):
json
{
"permissions": {
"deny": ["EnterPlanMode", "ExitPlanMode", "NotebookEdit",
"AskUserQuestion", "CronCreate", "CronDelete", "CronList",
"ScheduleWakeup", "SendMessage", "PushNotification",
"RemoteTrigger", "DesignSync", "ReportFindings"]
},
"disableBundledSkills": true,
"disableWorkflows": true,
"disableRemoteControl": true,
"disableClaudeAiConnectors": true,
"disableArtifact": true
}之后使用 重新测量——如此彻底的裁剪每轮可以回收数万 tokens。但上述每一行都是行为变更,而不只是数字变小:应逐项说明后果,让用户自行选择加入。许多用户会有充分理由保留 plan mode、question UI、artifacts 或 workflows——这是知情决策,而不是裁剪失败。
/contextGuardrails
Guardrails
- Treat every flag, path, and setting name here as illustrative, not current. Harnesses rename and relocate them across versions, and other agents (Codex, OpenCode, Pi, …) use different mechanisms entirely. Confirm today's mechanism in the agent's own docs before telling the user to edit anything.
- Propose, don't apply — config edits are durable and user-owned. Show the cut and its saving, then ask. Killing something load-bearing is worse than the bloat, and a context too small to do the job is no win.
- Treat a +
.claudedual-home as intentional cross-harness support; leave both..agents/.claudeis read by Anthropic's harness;CLAUDE.md/.agentsis the open standard every other agent reads. Skills and rules mirrored across both — duplicated or symlinked — let each harness see its own home; collapsing to one silently blinds the other. Treat the mirror as intentional unless told otherwise.AGENTS.md - Follow the reference chain before proposing a cut. An /include, a skill, and a symlink all point at a real file; deleting the file breaks every pointer to it. Know whether you're removing the pointer (import line) or the target (file), and change one while leaving the other intact.
@import - Gate a skill or keep a rules-file pointer to it — never both. Gating (, or moving it off the auto-discovered path) makes a skill user-invoke-only: the model can't load it on its own, so a rules pointer to it becomes dead weight rather than a fallback. If the agent should still pull the skill on coding tasks, keep it auto-loadable and keep the pointer. If it should fire only when typed, gate it and say plainly the pointer no longer summons it.
disable-model-invocation - Judge scope by reach, not just cost — this repo isn't the only place the user works. A global surface is the fallback for every other project on the machine (and any sub-agent spawned anywhere); a project surface is checked in to share with teammates who may lack your global config. So a global-vs-project duplicate is usually deliberate: keep the global copy (in a repo with no project pointer it's the only thing auto-loading that skill) and keep the project copy (dropping it breaks team sharing). Collapse redundancy only when it's provably wasteful at the same reach — e.g. an body stacked on the description in this one repo. Judge a global cut by every repo it touches, not this session, and prefer narrow scope (project/local) for new cuts unless the user wants them everywhere.
@import
Now run the analysis on this session. Produce a comprehensive, ranked menu of ways to prune the context — across MCP/connectors (A), skills (B, C), dead weight (D), memory/rules (E, F), and built-in tools & feature subsystems (G) — each row stating its estimated per-turn saving, its exact mechanism at a stated scope, and plainly what the user gives up. Cover the built-in-tool and feature-flag cuts explicitly; they are usually the largest untapped win and the most ignored. Then let the user decide per item — the goal is a leaner, more focused agent the user chose, not the smallest possible number.
- 将这里出现的每个 flag、path 和 setting name 都视为示例,而非当前有效配置。 不同版本中的 harness 会重命名和迁移这些配置项,其他 agent(Codex、OpenCode、Pi 等)也采用完全不同的机制。在建议用户编辑任何内容前,必须在对应 agent 的官方文档中确认当前机制。
- 提出建议,不要直接应用——配置编辑是持久性的,并且归用户所有。 展示裁剪方案及其节省量,然后询问用户。移除承重内容比保留臃肿更糟,而过小、不足以完成任务的 context 同样没有价值。
- 将 +
.claudedual-home 视为有意提供跨 harness 支持;两者都应保留。.agents/.claude由 Anthropic 的 harness 读取;CLAUDE.md/.agents是所有其他 agent 都会读取的开放标准。镜像在两处的 skills 和 rules——无论是重复还是符号链接——能让每个 harness 看到自己的目录;将它们静默合并为一份,会让另一个 harness 失去对应内容。除非用户另有说明,否则应将这种镜像视为有意设计。AGENTS.md - 提出裁剪建议前,遵循 reference chain。 /include、skill 和 symlink 都可能指向同一个真实文件;删除该文件会破坏所有指向它的指针。必须确认自己移除的是指针(import 行)还是目标(文件),并且只修改其中之一,保留另一个。
@import - 要么 gate 一个 skill,要么保留指向它的 rules 文件指针——绝不能两者同时做。 Gating(,或将其移出自动发现路径)会让 skill 变成 user-invoke-only:模型无法自行加载它,因此指向它的 rules 指针会变成无效负担,而不再是 fallback。如果 agent 仍应在编码任务中拉取该 skill,就保持其 auto-loadable,并保留指针。如果它只应在用户输入时触发,就 gate 它,并明确说明该指针不再能够召唤它。
disable-model-invocation - 判断作用域时应看覆盖范围,而不只是成本——当前 repo 并不是用户唯一的工作地点。 全局上下文项是机器上所有其他 projects(以及任何地方启动的 sub-agent)的 fallback;项目级上下文项则会被提交到版本库,与可能没有你全局配置的团队成员共享。因此,global 与 project 之间的重复通常是有意为之:如果 repo 中没有 project 指针,应保留 global 副本(它是唯一会自动加载该 skill 的内容);也应保留 project 副本(删除它会破坏团队共享)。只有当能够证明重复在同一覆盖范围内确实造成浪费时,才应合并它——例如当前 repo 中某个 正文与 description 重复堆叠。评估 global 裁剪时,要考虑它触及的每一个 repo,而不只是当前 session;除非用户希望到处生效,否则新的裁剪应优先采用较窄的 project/local 作用域。
@import
现在对本次 session 执行分析。给出一份全面且经过排名的 context 裁剪菜单——覆盖 MCP/connectors(A)、skills(B、C)、死内容(D)、memory/rules(E、F),以及内置 tools 与 feature subsystems(G)——每一行都要说明预计每轮节省量、处于指定作用域的确切机制,以及通俗地指出用户会失去什么。必须明确涵盖内置 tool 和 feature flag 的裁剪方案;它们通常是最未被开发的巨大收益来源,也是最常被忽略的部分。然后让用户逐项决定——目标是打造一个由用户自主选择、更精简且更聚焦的 agent,而不是单纯追求最小的数字。