I was feeling bogged down by the repetitive copy-paste routine to build context prompts for debugging or generating code. This simple solution ended up saving me a lot of time, so I thought I'd share my workflow.
With the large context windows of OpenAI and Anthropic models, you can keep entire code repositories in context. But copy-pasting the file-tree and code from lots of places is annoying. Prelude is a tiny CLI tool that creates a context prompt from files in your directory and its subdirectories, then copies it to your clipboard or saves it to a text file. Prelude creates a prompt containing the file tree of your specified directory, minus the files you ignored in .gitignore and .preludeignore, followed by the content of each file. It adds a bit of context prompting at the end, and that's it. Ready to copy-paste into a new chat with your favorite AI-chat. Nothing more, nothing less. Here’s how it works:
Install Prelude with Homebrew:
brew tap aerugo/prelude
brew install prelude
Simply run prelude in your working directory. Need files from a specific subdirectory? Use prelude -p dir. Want to specify a filename to save the prompt? Use prelude -f prompt.txt. Lots of files you don't want in the prompt? Put them in a .preludeignore file in the root folder where you run Prelude
Say that you know the names of the files you want to include, for example FooBar.py and BarFoo.md and they are somewhere in your file hierarchy.
Just run
prelude -M "foobar|barfoo"
and you will get a prompt with only those files. It also works with * wildcards.
Of course, it also works with the -P option, so you can also run something like
prelude -P backend/src -M "*.py"
To get all python files in the src directory of your backend.
PS. I'm sure this already exists. Lots of people must have done this. But nevertheless, I couldn't find a simple CLI tool to do just this, so I wrote one for myself, and then thought to share it.
I know this is a bit heavier since it's a whole program:
https://aider.chat/ generates a repo map, suggests related files, then makes your request and does the editing for you. (with intelligent diff for models that work well.)
EDIT: Oh, it looks like you're dumping the entire repo. Well, sure, I guess. Once it seems too big you can select just what you need.
Also gui tools like the open source https://www.continue.dev/ lets you pick files, search codebase via RAG, add docs, etc...
Yes, the whole point of this tool is just to make it extremely simply to make a prompt out of a part of your repo, with some pattern matching on filenames. It's just 200 lines of bash, so obviously nothing fancier than that.
However, I just had a go at using Aider, and WOW - I have tried a bunch of these auto-commit tools before (GPT Engineer, Fume, etc) but I found them to be clunky and unintuitive. Aider has fixed a lot of these problems, and I absolutely love it. Can't believe I hadn't heard of it until now. Thanks! I see myself using this quite a bit, and using Prelude when I need to debug something where the Aider workflow gets stuck.
Oh yeah, I hadn’t seen code2prompt - that’s indeed really similar. Prelude is a lot simpler though, just around 200 lines of bash in a single file, with only a single dependency (a CLI tool called tree). code2prompt, in contrast, requires you to install Rust and use Cargo.
Prelude is meant to really just do a single thing. I haven’t felt the need for things like templates, but I will give code2prompt a spin if I need more fancy things.
I was asked in a PM how I use the prompts. Basically, whenever I need to write some new code for a project, I start by making a prompt out of the relevant parts of the repo, paste it into GPT or Claude, and follow up with something like (random made up example):
——
I want to add a feature to my Content.js component. In the table that displays names of animals, I want to add an Edit button in a new column on each row. When clicked, it should bring up a modal that allows me to edit the name and emoji of the animal.
Review my codebase to see how CRUD actions are implemented for other features. Make sure you follow the established code patterns in the project.
Before starting to code, consider best practices for UX of a feature like this and make sure the implementation is user friendly and follows best practices.
After reviewing the code, describe how you will implement the feature make a plan for how to implement. After that, write the complete code for the implementation.
I've been maintaining my own script that does something like this. A few things I've found to be useful: It can also pull in context from git history (prioritize based on which files have been most recently worked on, include recent git commit messages which can help the LLM know more about what's going on), and optionally it can go do multiple stages... for long files, first summarizing them, then including the summary in the final prompt.
Interesting! Did you publish it?
It’s a great idea to prioritize based on git history.
As for multiple stages, it means the tool itself is doing a few calls to the model. What do the code summaries look like? Just function and class doctrings? Getting the model to write summaries that are comprehensive enough to guide development but still more compact than the code itself seems like it may not be a trivial problem.
I personally think a GUI tool would provide better user experience since you can see the files, pick which ones to include as context, and check the prompt generated in real-time.
So I built my own GUI version of this (plus a lot of other quality of life features): https://prompt.16x.engineer/
Just FYI if anyone runs into this:
I made a few updates to Prelude in the last few days.
It now allows including only files tracked by git by using the -g option.
You can also toggle case sensitivity of pattern matching (case insensitive by default) with the -c option.
I made something like this too to use myself. It's called `describe dot` and builds a context by recursing over . and putting all the content into the clipboard. It respects the .gitignore files in each folder and I can add .dignore files to ignore more files. At the end it creates a text file folder structure followed by the contents of all the files. It also logs the files in size order so that you can trim down the total size by ignoring them. It's been useful for small projects but I imagine that a whitelist based approach might be more useful for larger ones.
Wrote something similar[1] using Go a while back, but I love that this one only uses shell tools. Extremely useful when working with LLMs for small to medium projects.
For bigger ones on the other hand, I wish I could just get the exact context I need. Maybe something like only the files open in vim?
Have a bunch of Makerile commands (pbcopy-api, pbcopy-ui, pbcopy-curr) that use some mishmash of git ls-files, grep, xargs tail -n +1 piped into pbcopy.
To pile on, I was also going to make something similar for a very similar need (surprisingly hard to find prior art in this area that's good, probably due to so many people doing this)
Something like Prelude seems like it could complement steps before, or after it with a tool like CrewAI. Is anyone using CrewAI, or something like it in their workflow as well?
This is also neat, like simpler minimal version of Fume or GPT-Engineer. It seems really useful. Good job!
Prelude is rather meant for when you are pair-programming with a chat model and find yourself pasting a lot of context to remind the model of the state of your code. I always have terminals open anyway, so having it as a CLI tool rather than needing to make requests to a server, makes sense for me.
With the large context windows of OpenAI and Anthropic models, you can keep entire code repositories in context. But copy-pasting the file-tree and code from lots of places is annoying. Prelude is a tiny CLI tool that creates a context prompt from files in your directory and its subdirectories, then copies it to your clipboard or saves it to a text file. Prelude creates a prompt containing the file tree of your specified directory, minus the files you ignored in .gitignore and .preludeignore, followed by the content of each file. It adds a bit of context prompting at the end, and that's it. Ready to copy-paste into a new chat with your favorite AI-chat. Nothing more, nothing less. Here’s how it works:
Install Prelude with Homebrew:
brew tap aerugo/prelude brew install prelude
Simply run prelude in your working directory. Need files from a specific subdirectory? Use prelude -p dir. Want to specify a filename to save the prompt? Use prelude -f prompt.txt. Lots of files you don't want in the prompt? Put them in a .preludeignore file in the root folder where you run Prelude
Say that you know the names of the files you want to include, for example FooBar.py and BarFoo.md and they are somewhere in your file hierarchy.
Just run
prelude -M "foobar|barfoo"
and you will get a prompt with only those files. It also works with * wildcards.
Of course, it also works with the -P option, so you can also run something like
prelude -P backend/src -M "*.py"
To get all python files in the src directory of your backend.
PS. I'm sure this already exists. Lots of people must have done this. But nevertheless, I couldn't find a simple CLI tool to do just this, so I wrote one for myself, and then thought to share it.