跳到正文
Skillpedia
智能体33k · #8510

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/mksglu/context-mode/blob/main/skills/context-mode/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能