Skip to content

Commit 6b8f3ef

Browse files
authored
Merge pull request #25 from williln/add-claude-files-to-prompt
Add claude files to prompt
2 parents d0e145f + 95349d1 commit 6b8f3ef

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
run: |-
3939
python3 scripts/build_subdir_toc.py aws
4040
python3 scripts/build_subdir_toc.py celery
41+
python3 scripts/build_subdir_toc.py claude
4142
python3 scripts/build_subdir_toc.py cloudflare
4243
python3 scripts/build_subdir_toc.py django
4344
python3 scripts/build_subdir_toc.py django-rest-framework

claude/files-to-prompt.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ default:
55
build-internal-readmes:
66
python3 scripts/build_subdir_toc.py aws
77
python3 scripts/build_subdir_toc.py celery
8+
python3 scripts/build_subdir_toc.py claude
89
python3 scripts/build_subdir_toc.py cloudflare
910
python3 scripts/build_subdir_toc.py django
1011
python3 scripts/build_subdir_toc.py django-rest-framework

0 commit comments

Comments
 (0)