Prelude – a tiny CLI tool building context prompts from your code
github.com
github.com
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.
Could you include an example of how you separate files? For example are you using YAML Front Matter or something like that?
--- File: ~/GitRepos/kanot/prelude ---
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.)
They have a leaderboard for models for editing and what mode they use: https://aider.chat/docs/leaderboards/
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...
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.
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 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.
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.
So I built my own GUI version of this (plus a lot of other quality of life features): https://prompt.16x.engineer/
New release https://github.com/aerugo/prelude/releases/tag/v0.3 and pushed to the Homebrew formula
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?
Kitchen sink command: pbcopy-all: git ls-files | xargs tail -n +1 | pbcopy
Works like a charm in Q2 2024.
I’m sure this will be a very solved problem by 2025.
But I will try this once I'm back from PTO!
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.