CLI Tools2026年5月11日·1 分钟阅读

files-to-prompt — Concat Files Into LLM-Ready Prompts

Simon Willison's CLI that walks a directory and concats files into one LLM-ready prompt with path markers. Pipes straight into Claude or LLM CLI.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Stage only · 5/100Stage only
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:New
入口
Asset
通用 CLI 安装命令
npx tokrepo install 65aa017c-0160-45d9-adab-e5191c9f00be

简介

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 很少需要)。


🙏

来源与感谢

Built by Simon Willison. Licensed under Apache-2.0.

simonw/files-to-prompt — ⭐ 750+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产