filesystem-context
它能做什么
这个技能展示如何把长输出、计划和笔记保存到文件中,只在需要时再读取回来,从而让 AI 的工作窗口保持清爽。适合构建长时间运行任务或在智能体之间共享工作的人。
适用场景
- ✓当工具输出或日志占满了智能体的上下文窗口时。
- ✓当智能体需要在一项长任务中保存计划或草稿笔记时。
- ✓当多个智能体必须通过文件而不是直接消息来共享信息时。
技能链接
https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/blob/main/skills/filesystem-context/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请设置我的智能体,让它把很长的命令输出保存到文件中,并且只读取它需要的部分。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能让智能体把结果写入文件,然后按需查找相关部分,而不是把所有内容都保留在提示词中。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Filesystem-Based Context Engineering
Use the filesystem as the primary overflow layer for agent context because context windows are limited while tasks often require more information than fits in a single window. Files let agents store, retrieve, and update an effectively unlimited amount of context through a single interface.
Prefer dynamic context discovery -- pulling relevant context on demand -- over static inclusion, because static context consumes tokens regardless of relevance and crowds out space for task-specific information.
When to Activate
Activate this skill when:
- Tool outputs are bloating the context window
- Agents need to persist state across long trajectories
- Sub-agents must share information without direct message passing
- Tasks require more context than fits in the window
- Building agents that learn and update their own instructions
- Implementing scratch pads for intermediate results
- Terminal outputs or logs need to be accessible to agents
Do not activate this skill for adjacent work owned by other skills:
- Semantic cross-session memory, entity tracking, or temporal knowledge graphs:
memory-systems. - Conversation summarization, compaction, or durable handoff wording:
context-compression. - Token-efficiency tactics that do not require file-backed storage:
context-optimization. - Multi-agent topology or handoff protocol design:
multi-agent-patterns. - Model edits that evict content from the live window itself:
self-managed-context.
Core Concepts
Diagnose context failures against these four modes, because each requires a different filesystem remedy:
- Missing context -- needed information is absent from the total available context. Fix by persisting tool outputs and intermediate results to files so nothing is lost.
- Under-retrieved context -- retrieved content fails to encapsulate what the agent needs. Fix by structuring files for targeted retrieval (grep-friendly formats, clear section headers).
- Over-retrieved context -- retrieved content far exceeds what is needed, wasting tokens and degrading attention. Fix by offloading bulk content to files and returning compact references.
- Buried context -- niche information is hidden across many files. Fix by combining glob and grep for structural search alongside semantic search for conceptual queries.
Use the filesystem as the persistent layer that addresses all four: write once, store durably, retrieve selectively.
Detailed Topics
The Static vs Dynamic Context Trade-off
Treat static context (system instructions, tool definitions, critical rules) as expensive real estate -- it consumes tokens on every turn regardless of relevance. As agents accumulate capabilities, static context grows and crowds out dynamic information.
Use dynamic context discovery instead: include only minimal static pointers (names, one-line descriptions, file paths) and load full content with search tools when relevant. This is more token-efficient and often improves response quality by reducing contradictory or irrelevant information in the window.
Accept the trade-off: dynamic discovery requires the model to recognize when it needs more context. Current frontier models handle this well, but less capable models may fail to trigger loads. When in doubt, err toward including critical safety or correctness constraints statically.
Pattern 1: Filesystem as Scratch Pad
Redirect large tool outputs to files instead of returning them directly to context, because a single web search or database query can dump thousands of tokens into message history where they persist for the entire conversation.
Write the output to a scratch file, extract a compact summary, and return a file reference. The agent then uses targeted retrieval (grep for patterns, read with line ranges) to access only what it needs.
def handle_tool_output(output: str, threshold: int = 2000) -> str:
if len(output) < threshold:
return output
file_path = f"scratch/{tool_name}_{timestamp}.txt"
write_file(file_path, output)
key_summary = extract_summary(output, max_tokens=200)
return f"[Output written to {file_path}. Summary: {key_summary}]"
Use grep to search the offloaded file and read_file with line ranges to retrieve targeted sections, because this preserves full output for later reference while keeping only ~100 tokens in the active context.
Pattern 2: Plan Persistence
Write plans to the filesystem be
常见问题
为什么要把上下文存放在文件中?
文件能容纳的信息远多于上下文窗口,而智能体只加载它需要的部分。
这和长期记忆一样吗?
不一样。跨会话的长期记忆是另一个主题,而这里关注的是任务执行过程中使用的文件。
旧文件会被清理吗?
该技能提到了针对存放在提示词之外的上下文的清理策略。
详情
作者的原始描述
This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.
热度
- GitHub 星标
- 18k
- 排名
- #10642
- 许可证
- MIT
- 更新时间
- 2026/10/11
评论
- …
同一仓库的更多技能
context-engineering-collection
18k帮你的智能体管理输入 AI 模型上下文窗口的内容,涵盖记忆、工具、多智能体配置以及评估。
advanced-evaluation
18k教你的智能体如何用另一个 AI 来评判 AI 的回答,包括打分、并排比较和偏差检查。
bdi-mental-states
18k教你的智能体用 BDI 方法对信念、目标和计划进行建模,使其决策可以被追溯和解释。
context-compression
18k帮你的智能体把很长的 AI 会话压缩成摘要,保留决策、文件、风险和下一步。