|
| 1 | +# Using `files-to-prompt` to generate an XML file for your Claude context |
| 2 | + |
| 3 | +## Links |
| 4 | + |
| 5 | +- [simonw/files-to-prompt](https://github.com/simonw/files-to-prompt) |
| 6 | +- [Building files-to-prompt entirely using Claude 3 Opus](https://simonwillison.net/2024/Apr/8/files-to-prompt/) |
| 7 | +- [Use XML tags to structure your prompts](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags) |
| 8 | +- [Claude Desktop](https://claude.ai/download) |
| 9 | +- [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) |
| 10 | +- [aider](https://aider.chat) |
| 11 | + |
| 12 | +## Notes |
| 13 | + |
| 14 | +I've really seen the benefit of using [files-to-prompt](https://github.com/simonw/files-to-prompt) to zip up code files so [Claude can better consume them](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags) in my prompts. |
| 15 | + |
| 16 | +My workflow is usually this: |
| 17 | + |
| 18 | +1. Set up a `prompt.md` in my repo. |
| 19 | +2. `pip install files-to-prompt` |
| 20 | +3. Add an XML `<background>` tag with notes on the project, whatever background I want the AI to focus on, whatever expertise I want to reflect |
| 21 | +4. Add an XML `<instructions>` tag with very specific instructions on what I want to accomplish (Something like "Use a custom template for this view `MyView`" or "Write a test that the `MyView` endpoint returns a 200") |
| 22 | +5. Run `files-to-prompt -e py --cxml path/to/file1.py path/to/file2.py` and capture the output |
| 23 | +6. Copy the output and paste it at the bottom of the `prompt.md` |
| 24 | +7. Upload the `prompt.md` to [Claude Desktop](https://claude.ai/download), or pass it to whatever CLI tool (like [aider](https://aider.chat)) I am using to interact with Claude. |
| 25 | +8. My prompt is usually something like "Read `prompt.md` and follow the instructions." |
| 26 | + |
| 27 | +```md |
| 28 | +# prompt.md |
| 29 | +<background> |
| 30 | +- You are a [whatever background I specify] |
| 31 | +</background> |
| 32 | + |
| 33 | +<instructions> |
| 34 | +- Look at [whatever class or file I need] |
| 35 | +- Do [very specific small task] |
| 36 | +</instructions> |
| 37 | + |
| 38 | +<documents> |
| 39 | +This is the part where I paste in the output from `files-to-prompt` |
| 40 | +</documents> |
| 41 | +``` |
| 42 | + |
| 43 | +I use Claude Desktop a lot, and I like being able to reduce the number of files I need to upload because the Desktop app limits the number of files you can upload at once. |
| 44 | + |
| 45 | +Some options to consider: |
| 46 | + |
| 47 | +- `--ignore <pattern>`: Specify a pattern to ignore. This could be useful in getting whole apps but excluding everything in `migrations/`. |
| 48 | +- `--ignore-ditignore`: Ignore the `gitignore`, and include all files. |
| 49 | +- `-c/--cxml`: Output in Claude XML |
| 50 | +- `-m/--markdown`: Output as Markdown |
| 51 | +- `-o/--output <file>`: Output to a file |
| 52 | + |
| 53 | +The [README](https://github.com/simonw/files-to-prompt?tab=readme-ov-file) has several examples of how to use different options to get the files you want in the format you want. |
0 commit comments