重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
context-mode by mksglu/context-mode
npx skills add https://github.com/mksglu/context-mode --skill context-mode<context_mode_logic> <mandatory_rule> 所有命令默认使用上下文模式。仅对保证输出量小的操作使用 Bash。 </mandatory_rule> </context_mode_logic>
Bash 白名单(可直接安全运行):
mkdir, mv, cp, rm, touch, chmodgit add, git commit, git push, , , 广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
git checkoutgit branchgit mergecd, pwd, whichkill, pkillnpm install, npm publish, pip installecho, printf其他所有命令 → 使用 ctx_execute 或 ctx_execute_file。 任何读取、查询、获取、列出、记录日志、测试、构建、比较差异、检查或调用外部服务的命令。这包括所有 CLI 工具(gh, aws, kubectl, docker, terraform, wrangler, fly, heroku, gcloud 等)—— 有成千上万种,我们无法全部列出。
不确定时,使用上下文模式。 每一 KB 不必要的上下文都会降低整个会话的质量和速度。
即将运行命令 / 读取文件 / 调用 API?
│
├── 命令在 Bash 白名单上吗(文件操作、Git 写入、导航、echo)?
│ └── 使用 Bash
│
├── 输出可能很大或你不确定?
│ └── 使用上下文模式 ctx_execute 或 ctx_execute_file
│
├── 正在获取网页文档或 HTML 页面?
│ └── 使用 ctx_fetch_and_index → ctx_search
│
├── 正在使用 Playwright(导航、快照、控制台、网络)?
│ └── 始终使用 filename 参数保存到文件,然后:
│ browser_snapshot(filename) → ctx_index(path) 或 ctx_execute_file(path)
│ browser_console_messages(filename) → ctx_execute_file(path)
│ browser_network_requests(filename) → ctx_execute_file(path)
│ ⚠ browser_navigate 会自动返回快照 —— 忽略它,
│ 任何检查都使用 browser_snapshot(filename)。
│ ⚠ Playwright MCP 使用单个浏览器实例 —— 不支持并行安全。
│ 对于并行浏览器操作,请通过 execute 使用 agent-browser。
│
├── 正在使用 agent-browser(并行安全的浏览器自动化)?
│ └── 通过 execute(shell)运行 —— 每次调用都获得自己的子进程:
│ execute("agent-browser open example.com && agent-browser snapshot -i -c")
│ ✓ 支持会话以实现隔离的浏览器实例
│ ✓ 对并行子代理执行安全
│ ✓ 轻量级可访问性树,支持基于引用的交互
│
├── 正在处理来自另一个 MCP 工具(Context7、GitHub API 等)的输出?
│ ├── 输出是否已从之前的工具调用加载到上下文中?
│ │ └── 直接使用。不要用 ctx_index(content: ...) 重新索引。
│ ├── 需要多次搜索输出吗?
│ │ └── 通过 ctx_execute 保存到文件,然后 ctx_index(path) → ctx_search
│ └── 一次性提取?
│ └── 通过 ctx_execute 保存到文件,然后 ctx_execute_file(path)
│
└── 正在读取文件进行分析/总结(而非编辑)?
└── 使用 ctx_execute_file(文件加载到 FILE_CONTENT,而非上下文)
| 场景 | 工具 | 示例 |
|---|---|---|
| 调用 API 端点 | ctx_execute | fetch('http://localhost:3000/api/orders') |
| 运行返回数据的 CLI | ctx_execute | gh pr list, aws s3 ls, kubectl get pods |
| 运行测试 | ctx_execute | npm test, pytest, go test ./... |
| Git 操作 | ctx_execute | git log --oneline -50, git diff HEAD~5 |
| Docker/K8s 检查 | ctx_execute | docker stats --no-stream, kubectl describe pod |
| 读取日志文件 | ctx_execute_file | 解析 access.log, error.log, 构建输出 |
| 读取数据文件 | ctx_execute_file | 分析 CSV, JSON, YAML, XML |
| 读取源代码进行分析 | ctx_execute_file | 统计函数、查找模式、提取指标 |
| 获取网页文档 | ctx_fetch_and_index | 索引 React/Next.js/Zod 文档,然后搜索 |
| Playwright 快照 | browser_snapshot(filename) → ctx_index(path) → ctx_search | 保存到文件,在服务器端索引,查询 |
| Playwright 快照(一次性) | browser_snapshot(filename) → ctx_execute_file(path) | 保存到文件,在沙盒中提取 |
| Playwright 控制台/网络 | browser_*(filename) → ctx_execute_file(path) | 保存到文件,在沙盒中分析 |
| MCP 输出(已在上下文中) | 直接使用 | 不要重新索引 —— 它已经加载了 |
| MCP 输出(需要多次查询) | ctx_execute 保存 → ctx_index(path) → ctx_search | 先保存到文件,在服务器端索引 |
遇到以下任何情况时,无需询问,直接使用上下文模式:
| 场景 | 语言 | 原因 |
|---|---|---|
| HTTP/API 调用,JSON | javascript | 原生 fetch, JSON.parse, async/await |
| 数据分析,CSV,统计 | python | csv, statistics, collections, re |
| 带管道的 Shell 命令 | shell | grep, awk, jq, 原生工具 |
| 文件模式匹配 | shell | find, wc, sort, uniq |
source 参数,以避免跨源污染
source: "Node" 匹配 "Node.js v22 CHANGELOG"queries 数组 —— 在一次调用中批处理所有搜索问题:
ctx_search(queries: ["transform pipe", "refine superRefine", "coerce codec"], source: "Zod")ctx_fetch_and_index —— 对于你不拥有的包,永远不要使用 cat 或带有本地路径的 ctx_executehttps://raw.githubusercontent.com/org/repo/main/CHANGELOG.mdsource 参数将结果范围限定在该特定文档console.log(JSON.stringify(data)) —— 先分析,再打印发现。ctx_index(content: large_data)。 使用 ctx_index(path: ...) 在服务器端读取文件。content 参数将数据作为工具参数通过上下文发送 —— 仅用于小的内联文本。browser_snapshot, browser_console_messages, browser_network_requests)上始终使用 filename 参数。 没有它,完整输出会进入上下文。<sandboxed_data_workflow> <critical_rule> 当使用支持保存到文件的工具时:始终使用 'filename' 参数。永远不要将大型原始数据集直接返回到上下文。 </critical_rule> LargeDataTool(filename: "path") → mcp__context-mode__ctx_index(path: "path") → ctx_search() </sandboxed_data_workflow>
这是无论源工具(Playwright、GitHub API、AWS CLI 等)如何,都能保持上下文的通用模式。
const resp = await fetch('http://localhost:3000/api/orders');
const { orders } = await resp.json();
const bugs = [];
const negQty = orders.filter(o => o.quantity < 0);
if (negQty.length) bugs.push(`Negative qty: ${negQty.map(o => o.id).join(', ')}`);
const nullFields = orders.filter(o => !o.product || !o.customer);
if (nullFields.length) bugs.push(`Null fields: ${nullFields.map(o => o.id).join(', ')}`);
console.log(`${orders.length} orders, ${bugs.length} bugs found:`);
bugs.forEach(b => console.log(`- ${b}`));
npm test 2>&1
echo "EXIT=$?"
gh pr list --json number,title,state,reviewDecision --jq '.[] | "\(.number) [\(.state)] \(.title) — \(.reviewDecision // "no review")"'
# FILE_CONTENT 由 ctx_execute_file 预加载
import json
data = json.loads(FILE_CONTENT)
print(f"Records: {len(data)}")
# ... 分析并打印发现
当任务涉及 Playwright 快照、截图或页面检查时,始终通过 文件 → 沙盒 的路径进行。
Playwright 的 browser_snapshot 返回 10K–135K 令牌的可访问性树数据。不带 filename 调用它会将所有数据转储到上下文中。将其输出传递给 ctx_index(content: ...) 会将其作为参数第二次发送到上下文中。这两种做法都是错误的。
关键见解:browser_snapshot 有一个 filename 参数,可以保存到文件而不是返回到上下文。ctx_index 有一个 path 参数,可以在服务器端读取文件。ctx_execute_file 在沙盒中处理文件。这些都不会触及上下文。
步骤 1: browser_snapshot(filename: "/tmp/playwright-snapshot.md")
→ 保存到文件,返回约 50B 的确认信息(而非 135K 令牌)
步骤 2: ctx_index(path: "/tmp/playwright-snapshot.md", source: "Playwright snapshot")
→ 在服务器端读取文件,索引到 FTS5,返回约 80B 的确认信息
步骤 3: ctx_search(queries: ["login form email password"], source: "Playwright")
→ 仅返回匹配的片段(约 300B)
总上下文:约 430B 而不是 270K 令牌。实际节省 99%。
步骤 1: browser_snapshot(filename: "/tmp/playwright-snapshot.md")
→ 保存到文件,返回约 50B 的确认信息
步骤 2: ctx_execute_file(path: "/tmp/playwright-snapshot.md", language: "javascript", code: "
const links = [...FILE_CONTENT.matchAll(/- link \"([^\"]+)\"/g)].map(m => m[1]);
const buttons = [...FILE_CONTENT.matchAll(/- button \"([^\"]+)\"/g)].map(m => m[1]);
const inputs = [...FILE_CONTENT.matchAll(/- textbox|- checkbox|- radio/g)];
console.log('Links:', links.length, '| Buttons:', buttons.length, '| Inputs:', inputs.length);
console.log('Navigation:', links.slice(0, 10).join(', '));
")
→ 在沙盒中处理,返回约 200B 的摘要
总上下文:约 250B 而不是 135K 令牌。
browser_console_messages(level: "error", filename: "/tmp/console.md")
→ ctx_execute_file(path: "/tmp/console.md", ...) 或 ctx_index(path: "/tmp/console.md", ...)
browser_network_requests(includeStatic: false, filename: "/tmp/network.md")
→ ctx_execute_file(path: "/tmp/network.md", ...) 或 ctx_index(path: "/tmp/network.md", ...)
filename + path 是强制性的| 方法 | 上下文成本 | 正确? |
|---|---|---|
browser_snapshot() → 原始数据进入上下文 | 135K 令牌 | 否 |
browser_snapshot() → ctx_index(content: raw) | 270K 令牌(翻倍!) | 否 |
browser_snapshot(filename) → ctx_index(path) → ctx_search | 约 430B | 是 |
browser_snapshot(filename) → ctx_execute_file(path) | 约 250B | 是 |
调用
browser_snapshot、browser_console_messages或browser_network_requests时,始终使用filename参数。 然后通过ctx_index(path: ...)或ctx_execute_file(path: ...)处理 —— 永远不要用ctx_index(content: ...)。数据流:Playwright → 文件 → 服务器端读取 → 上下文。永远不要:Playwright → 上下文 → ctx_index(content) → 再次进入上下文。
子代理通过 PreToolUse 钩子自动接收上下文模式工具路由。你不需要手动将工具名称添加到子代理提示中 —— 钩子会注入它们。只需编写自然的任务描述即可。
curl http://api/endpoint → 50KB 淹没上下文。改用带 fetch 的 ctx_execute。cat large-file.json → 整个文件进入上下文。改用 ctx_execute_file。gh pr list → 原始 JSON 进入上下文。改用带 --jq 过滤器的 ctx_execute。| head -20 管道传输 Bash 输出 → 你丢失了其余部分。使用 ctx_execute 分析所有数据并打印摘要。npm test → 完整的测试输出进入上下文。使用 ctx_execute 捕获并总结。browser_snapshot() 时没有 filename 参数 → 135K 令牌淹没上下文。始终使用 browser_snapshot(filename: "/tmp/snap.md")。browser_console_messages() 或 browser_network_requests() 时没有 filename 参数 → 整个输出淹没上下文。始终使用 filename 参数。ctx_index(content: ...) → 数据作为参数进入上下文。始终使用 ctx_index(path: ...) 在服务器端读取。content 参数应仅用于你自己编写的小型内联文本。query-docs、GitHub API 等),然后将响应传递给 ctx_index(content: response) → 加倍上下文使用量。响应已在上下文中 —— 直接使用或先保存到文件。browser_navigate 的自动快照 → 导航响应包含完整的页面快照。不要依赖它进行检查 —— 单独调用 browser_snapshot(filename)。每周安装量
60
代码仓库
GitHub 星标数
6.0K
首次出现
2026年3月8日
安全审计
安装于
opencode58
cursor57
gemini-cli57
codex57
kimi-cli57
amp57
<context_mode_logic> <mandatory_rule> Default to context-mode for ALL commands. Only use Bash for guaranteed-small-output operations. </mandatory_rule> </context_mode_logic>
Bash whitelist (safe to run directly):
mkdir, mv, cp, rm, touch, chmodgit add, git commit, git push, git checkout, git branch, git mergecd, pwd, whichkill, pkillnpm install, npm publish, pip installecho, printfEverything else →ctx_execute or ctx_execute_file. Any command that reads, queries, fetches, lists, logs, tests, builds, diffs, inspects, or calls an external service. This includes ALL CLIs (gh, aws, kubectl, docker, terraform, wrangler, fly, heroku, gcloud, etc.) — there are thousands and we cannot list them all.
When uncertain, use context-mode. Every KB of unnecessary context reduces the quality and speed of the entire session.
About to run a command / read a file / call an API?
│
├── Command is on the Bash whitelist (file mutations, git writes, navigation, echo)?
│ └── Use Bash
│
├── Output MIGHT be large or you're UNSURE?
│ └── Use context-mode ctx_execute or ctx_execute_file
│
├── Fetching web documentation or HTML page?
│ └── Use ctx_fetch_and_index → ctx_search
│
├── Using Playwright (navigate, snapshot, console, network)?
│ └── ALWAYS use filename parameter to save to file, then:
│ browser_snapshot(filename) → ctx_index(path) or ctx_execute_file(path)
│ browser_console_messages(filename) → ctx_execute_file(path)
│ browser_network_requests(filename) → ctx_execute_file(path)
│ ⚠ browser_navigate returns a snapshot automatically — ignore it,
│ use browser_snapshot(filename) for any inspection.
│ ⚠ Playwright MCP uses a SINGLE browser instance — NOT parallel-safe.
│ For parallel browser ops, use agent-browser via execute instead.
│
├── Using agent-browser (parallel-safe browser automation)?
│ └── Run via execute (shell) — each call gets its own subprocess:
│ execute("agent-browser open example.com && agent-browser snapshot -i -c")
│ ✓ Supports sessions for isolated browser instances
│ ✓ Safe for parallel subagent execution
│ ✓ Lightweight accessibility tree with ref-based interaction
│
├── Processing output from another MCP tool (Context7, GitHub API, etc.)?
│ ├── Output already in context from a previous tool call?
│ │ └── Use it directly. Do NOT re-index with ctx_index(content: ...).
│ ├── Need to search the output multiple times?
│ │ └── Save to file via ctx_execute, then ctx_index(path) → ctx_search
│ └── One-shot extraction?
│ └── Save to file via ctx_execute, then ctx_execute_file(path)
│
└── Reading a file to analyze/summarize (not edit)?
└── Use ctx_execute_file (file loads into FILE_CONTENT, not context)
| Situation | Tool | Example |
|---|---|---|
| Hit an API endpoint | ctx_execute | fetch('http://localhost:3000/api/orders') |
| Run CLI that returns data | ctx_execute | gh pr list, aws s3 ls, kubectl get pods |
| Run tests | ctx_execute |
Use context-mode for ANY of these, without being asked:
| Situation | Language | Why |
|---|---|---|
| HTTP/API calls, JSON | javascript | Native fetch, JSON.parse, async/await |
| Data analysis, CSV, stats | python | csv, statistics, collections, re |
| Shell commands with pipes | shell | grep, awk, jq, native tools |
| File pattern matching | shell | find, wc, sort, uniq |
source parameter when multiple docs are indexed to avoid cross-source contamination
source: "Node" matches "Node.js v22 CHANGELOG"queries array — batch ALL search questions in ONE call:
ctx_search(queries: ["transform pipe", "refine superRefine", "coerce codec"], source: "Zod")ctx_fetch_and_index for external docs — NEVER cat or ctx_execute with local paths for packages you don't ownhttps://raw.githubusercontent.com/org/repo/main/CHANGELOG.mdsource parameter in search to scope results to that specific documentconsole.log(JSON.stringify(data)) — analyze first, print findings.ctx_index(content: large_data). Use ctx_index(path: ...) to read files server-side. The content parameter sends data through context as a tool parameter — use it only for small inline text.filename parameter on Playwright tools (browser_snapshot, , ). Without it, the full output enters context.<sandboxed_data_workflow> <critical_rule> When using tools that support saving to a file: ALWAYS use the 'filename' parameter. NEVER return large raw datasets directly to context. </critical_rule> LargeDataTool(filename: "path") → mcp__context-mode__ctx_index(path: "path") → ctx_search() </sandboxed_data_workflow>
This is the universal pattern for context preservation regardless of the source tool (Playwright, GitHub API, AWS CLI, etc.).
const resp = await fetch('http://localhost:3000/api/orders');
const { orders } = await resp.json();
const bugs = [];
const negQty = orders.filter(o => o.quantity < 0);
if (negQty.length) bugs.push(`Negative qty: ${negQty.map(o => o.id).join(', ')}`);
const nullFields = orders.filter(o => !o.product || !o.customer);
if (nullFields.length) bugs.push(`Null fields: ${nullFields.map(o => o.id).join(', ')}`);
console.log(`${orders.length} orders, ${bugs.length} bugs found:`);
bugs.forEach(b => console.log(`- ${b}`));
npm test 2>&1
echo "EXIT=$?"
gh pr list --json number,title,state,reviewDecision --jq '.[] | "\(.number) [\(.state)] \(.title) — \(.reviewDecision // "no review")"'
# FILE_CONTENT is pre-loaded by ctx_execute_file
import json
data = json.loads(FILE_CONTENT)
print(f"Records: {len(data)}")
# ... analyze and print findings
When a task involves Playwright snapshots, screenshots, or page inspection, ALWAYS route through file → sandbox.
Playwright browser_snapshot returns 10K–135K tokens of accessibility tree data. Calling it without filename dumps all of that into context. Passing the output to ctx_index(content: ...) sends it into context a SECOND time as a parameter. Both are wrong.
The key insight : browser_snapshot has a filename parameter that saves to file instead of returning to context. ctx_index has a path parameter that reads files server-side. ctx_execute_file processes files in a sandbox. None of these touch context.
Step 1: browser_snapshot(filename: "/tmp/playwright-snapshot.md")
→ saves to file, returns ~50B confirmation (NOT 135K tokens)
Step 2: ctx_index(path: "/tmp/playwright-snapshot.md", source: "Playwright snapshot")
→ reads file SERVER-SIDE, indexes into FTS5, returns ~80B confirmation
Step 3: ctx_search(queries: ["login form email password"], source: "Playwright")
→ returns only matching chunks (~300B)
Total context: ~430B instead of 270K tokens. Real 99% savings.
Step 1: browser_snapshot(filename: "/tmp/playwright-snapshot.md")
→ saves to file, returns ~50B confirmation
Step 2: ctx_execute_file(path: "/tmp/playwright-snapshot.md", language: "javascript", code: "
const links = [...FILE_CONTENT.matchAll(/- link \"([^\"]+)\"/g)].map(m => m[1]);
const buttons = [...FILE_CONTENT.matchAll(/- button \"([^\"]+)\"/g)].map(m => m[1]);
const inputs = [...FILE_CONTENT.matchAll(/- textbox|- checkbox|- radio/g)];
console.log('Links:', links.length, '| Buttons:', buttons.length, '| Inputs:', inputs.length);
console.log('Navigation:', links.slice(0, 10).join(', '));
")
→ processes in sandbox, returns ~200B summary
Total context: ~250B instead of 135K tokens.
browser_console_messages(level: "error", filename: "/tmp/console.md")
→ ctx_execute_file(path: "/tmp/console.md", ...) or ctx_index(path: "/tmp/console.md", ...)
browser_network_requests(includeStatic: false, filename: "/tmp/network.md")
→ ctx_execute_file(path: "/tmp/network.md", ...) or ctx_index(path: "/tmp/network.md", ...)
filename + path is mandatory| Approach | Context cost | Correct? |
|---|---|---|
browser_snapshot() → raw into context | 135K tokens | NO |
browser_snapshot() → ctx_index(content: raw) | 270K tokens (doubled!) | NO |
browser_snapshot(filename) → ctx_index(path) → ctx_search | ~430B | YES |
ALWAYS use
filenameparameter when callingbrowser_snapshot,browser_console_messages, orbrowser_network_requests. Then process viactx_index(path: ...)orctx_execute_file(path: ...)— neverctx_index(content: ...).Data flow: Playwright → file → server-side read → context. Never: Playwright → context → ctx_index(content) → context again.
Subagents automatically receive context-mode tool routing via a PreToolUse hook. You do NOT need to manually add tool names to subagent prompts — the hook injects them. Just write natural task descriptions.
curl http://api/endpoint via Bash → 50KB floods context. Use ctx_execute with fetch instead.cat large-file.json via Bash → entire file in context. Use ctx_execute_file instead.gh pr list via Bash → raw JSON in context. Use ctx_execute with --jq filter instead.| head -20 → you lose the rest. Use ctx_execute to analyze ALL data and print summary.npm test via Bash → full test output in context. Use to capture and summarize.Weekly Installs
60
Repository
GitHub Stars
6.0K
First Seen
Mar 8, 2026
Security Audits
Gen Agent Trust HubPassSocketFailSnykWarn
Installed on
opencode58
cursor57
gemini-cli57
codex57
kimi-cli57
amp57
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
152,400 周安装
deepTools:NGS数据分析工具包 - ChIP-seq/RNA-seq/ATAC-seq质量控制与可视化
55 周安装
scikit-bio Python生物信息学库:序列分析、系统发育、多样性计算与微生物组数据处理
55 周安装
Python DICOM处理教程:pydicom读取医学影像、元数据操作与格式转换
55 周安装
治疗计划撰写模板与工具 - 专业LaTeX模板、AI图表生成、法规合规
55 周安装
Geniml:基因组区间机器学习Python包,支持BED文件嵌入与单细胞ATAC-seq分析
55 周安装
PennyLane量子计算库:量子机器学习、量子化学与硬件集成全指南
55 周安装
npm test, pytest, go test ./... |
| Git operations | ctx_execute | git log --oneline -50, git diff HEAD~5 |
| Docker/K8s inspection | ctx_execute | docker stats --no-stream, kubectl describe pod |
| Read a log file | ctx_execute_file | Parse access.log, error.log, build output |
| Read a data file | ctx_execute_file | Analyze CSV, JSON, YAML, XML |
| Read source code to analyze | ctx_execute_file | Count functions, find patterns, extract metrics |
| Fetch web docs | ctx_fetch_and_index | Index React/Next.js/Zod docs, then search |
| Playwright snapshot | browser_snapshot(filename) → ctx_index(path) → ctx_search | Save to file, index server-side, query |
| Playwright snapshot (one-shot) | browser_snapshot(filename) → ctx_execute_file(path) | Save to file, extract in sandbox |
| Playwright console/network | browser_*(filename) → ctx_execute_file(path) | Save to file, analyze in sandbox |
| MCP output (already in context) | Use directly | Don't re-index — it's already loaded |
| MCP output (need multi-query) | ctx_execute to save → ctx_index(path) → ctx_search | Save to file first, index server-side |
browser_console_messagesbrowser_network_requestsbrowser_snapshot(filename) → ctx_execute_file(path) | ~250B | YES |
ctx_executebrowser_snapshot() WITHOUT filename parameter → 135K tokens flood context. Always use browser_snapshot(filename: "/tmp/snap.md").browser_console_messages() or browser_network_requests() WITHOUT filename → entire output floods context. Always use the filename parameter.ctx_index(content: ...) → data enters context as a parameter. Always use ctx_index(path: ...) to read server-side. The content parameter should only be used for small inline text you're composing yourself.query-docs, GitHub API, etc.) then passing the response to ctx_index(content: response) → doubles context usage. The response is already in context — use it directly or save to file first.browser_navigate auto-snapshot → navigation response includes a full page snapshot. Don't rely on it for inspection — call browser_snapshot(filename) separately.