Attachment Inject
/install attachment-inject
Attachment Inject — 动态附件注入
参考 Claude Code 的 attachments.ts,将动态内容作为attachment消息注入而非嵌入system prompt。
问题
每次注入技能列表、Agent列表等动态内容到system prompt会:
- 增加每次请求的token消耗
- 内容变化时破坏prompt cache
- 无法动态更新
解决方案
模式1: 按需读取(当前OpenClaw支持)
不预注入内容,而是在需要时读取:
用户提到"调度Agent" → 读 agents/*.md → 选择合适的Agent
用户提到"调试" → 读 skills/systematic-debugging/SKILL.md → 激活技能
模式2: 注册表文件(轻量注入)
维护一个注册表文件,包含名称+描述,不包含完整内容:
# agents/registry.md(自动生成)
| Agent | 描述 |
|-------|------|
| code-reviewer | 代码质量+安全审查 |
| planner | 实现规划(Opus) |
| chief-of-staff | 多渠道消息分诊 |
...
# skills/registry.md(自动生成)
| 技能 | 描述 |
|------|------|
| coordinator | 三层多Agent协调 |
| compact | 长会话压缩 |
...
模式3: 动态注入点
在AGENTS.md中定义占位符,每次会话开始时替换:
\x3C!-- INJECT:SKILLS_REGISTRY -->
\x3C!-- INJECT:AGENTS_REGISTRY -->
\x3C!-- INJECT:MEMORY_SUMMARY -->
注册表生成脚本
# 生成技能注册表
for dir in skills/*/; do
name=$(basename "$dir")
desc=$(grep "^description:" "$dir/SKILL.md" 2>/dev/null | head -1 | sed 's/description: *//' | cut -c1-60)
echo "| $name | $desc |"
done
# 生成Agent注册表
for f in agents/*.md; do
name=$(grep "^name:" "$f" | head -1 | sed 's/name: *//')
desc=$(grep "^description:" "$f" | head -1 | sed 's/description: *//' | cut -c1-60)
echo "| $name | $desc |"
done
最佳实践
- 注册表 \x3C 500 token — 只含名称和一行描述
- 完整内容按需加载 — 匹配到任务时才读SKILL.md
- 变化时只更新注册表 — 不动system prompt
- 核心技能始终加载 — 9个核心技能的描述直接在AGENTS.md中
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install attachment-inject - After installation, invoke the skill by name or use
/attachment-inject - Provide required inputs per the skill's parameter spec and get structured output
What is Attachment Inject?
动态附件注入 — 在不修改system prompt的情况下注入动态内容。参考Claude Code的Attachment消息机制。 It is an AI Agent Skill for Claude Code / OpenClaw, with 80 downloads so far.
How do I install Attachment Inject?
Run "/install attachment-inject" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Attachment Inject free?
Yes, Attachment Inject is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Attachment Inject support?
Attachment Inject is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Attachment Inject?
It is built and maintained by wangxiaofei860208-source (@wangxiaofei860208-source); the current version is v1.0.0.