简介
files-to-prompt 是 Simon Willison 的 CLI —— 遍历目录树把每个文件拼成一份 LLM 就绪的 prompt,带路径标记、识别 gitignore、可选 Claude 风格 XML 包装。天然管道接 Simon 的 LLM CLI 或任何吃 stdin 的模型。适合「把整个仓库粘给 Claude」工作流、代码库问答、重构 briefing、自定义 RAG 入库。任何 shell、Python 3.10+ 都行。装机时间 1 分钟。
安装 + 基础用
pip install files-to-prompt
# 拼整个仓库
files-to-prompt . > prompt.txt
# 指定扩展名
files-to-prompt . --extension .py --extension .ts > code.txt
# 遵守 .gitignore
files-to-prompt . --ignore-gitignore=false > clean.txt管道接 Claude / LLM CLI
# 通过 Simon 的 llm CLI
files-to-prompt src/ | llm -m claude-3-5-sonnet "auth bug 在哪?"
# 通过 curl 直接打 Anthropic
files-to-prompt src/ | jq -Rs '{model:"claude-3-5-sonnet-20241022",max_tokens:4096,messages:[{role:"user",content:.}]}' \
| curl -X POST https://api.anthropic.com/v1/messages \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "content-type: application/json" \
-d @-Claude 友好的 XML 包装
files-to-prompt src/ --cxml > prompt.xml
# 每个文件包成 <document index="N"><source>路径</source><document_content>...</document_content></document>
# 这格式 Claude 引用最干净排除噪音
files-to-prompt . \
--extension .py \
--ignore "*test*" \
--ignore "*.pyc" \
--ignore "venv/" \
--ignore "node_modules/" \
> prompt.txt输出格式
path: src/main.py
---
def main():
...
path: src/utils.py
---
def helper():
...LLM 对这种格式处理稳定 —— 每个 chunk 内联带来源文件路径。
FAQ
Q: 能 dump 多大的 repo? A: 受模型上下文窗口限制。Claude 200K 上下文约能装 50 万字符。1M+ 上下文模型(Grok-3 / Gemini)整个中型 repo 都装得下。更大就分块 + RAG,或者用 Claude prompt cache。
Q: 跟 repomix / aider 比? A: 更简单。repomix 带 token 计数和 AI 感知分割;aider 是交互式编码 agent。files-to-prompt 只做一件事 —— 拼接。输出管道到任何地方。要 token 数学选 repomix,要真正编码 agent 选 aider。
Q: 二进制文件?
A: 自动跳过。files-to-prompt 检测二进制内容并默认排除。--include-binary 强制全包(LLM prompt 很少需要)。