context-mode
它能做什么
这个技能指导 AI 智能体通过 context-mode 工具处理大型命令输出和文件,而不是完整阅读它们。适合处理长日志、大型 API 响应和构建输出的开发者。
适用场景
- ✓当智能体被要求分析日志、总结命令输出或解析大型 JSON 响应的时候。
- ✓当构建或依赖检查可能产生需要过滤的长输出的时候。
- ✓当页面快照或浏览器结构太大,无法直接阅读的时候。
技能链接
https://github.com/mksglu/context-mode/blob/main/skills/context-mode/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请分析这些构建日志,只告诉我其中的错误,不要显示完整输出。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能设定了一条默认规则:凡是读取、查询、获取、列出或构建的操作,都使用 context-mode 工具;只有小型、安全的操作才保留普通 shell 命令。然后智能体只展示重要的部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Context Mode: Default for All Large Output
MANDATORY RULE
<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):
- File mutations:
mkdir,mv,cp,rm,touch,chmod - Git writes:
git add,git commit,git push,git checkout,git branch,git merge - Navigation:
cd,pwd,which - Process control:
kill,pkill - Package management:
npm install,npm publish,pip install - Simple output:
echo,printf
Everything 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.
Decision Tree
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)
When to Use Each Tool
| 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 |
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 |
常见问题
哪些命令仍可以直接运行?
创建文件夹、移动文件、git 写入操作、切换目录和 echo 等小型安全操作,仍可以在 shell 中运行。
遇到大量输出时会怎样处理?
它会在沙箱中处理输出,只把相关结果返回到对话中。
它适用于每一个命令吗?
它适用于大多数命令。规则是:只要智能体不确定输出会有多大,就使用 context-mode。
详情
作者的原始描述
Use context-mode tools (ctx_execute, ctx_execute_file) instead of Bash/cat when processing large outputs. Triggers: "analyze logs", "summarize output", "process data", "parse JSON", "filter results", "extract errors", "check build output", "analyze dependencies", "process API response", "large file analysis", "page snapshot", "browser snapshot", "DOM structure", "inspect page", "accessibility tree", "Playwright snapshot", "run tests", "test output", "coverage report", "git log", "recent commits", "diff between branches", "list containers", "pod status", "disk usage", "fetch docs", "API referen
repo: mksglu/context-mode
热度
- GitHub 星标
- 33k
- 排名
- #8510
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
context-mode
33k教你的智能体使用 context-mode 工具来读取、搜索和运行大量数据的任务,让大型输出不占用主对话空间。
context-mode
33k教你的智能体在沙箱中处理数据密集型的工作,只输出答案,让原始文件和网页不会淹没对话。
ctx-doctor
33k运行 context-mode 诊断,检查运行环境、钩子、搜索存储、插件设置和版本,然后显示清晰的通过或失败报告。
ctx-index
33k让你的智能体把本地项目或文件夹索引到可搜索的存储中,之后提问时可以直接找到相关片段,而无需重新阅读每个文件。