files-to-prompt is a CLI tool to collect the content of a multiple files, so that it can be used in a prompt for a LLM.
I have found this to work particularly well for Django development. In a Django app, functionality is often spread across different files, such as views, models, forms, templates etc. files-to-prompt
makes it super easy to provide all the relevant code, along with a description of the feature you want build.
files-to-prompt bookstore/ | \
llm --system "add a book list view to this Django app"
Instead of piping the file content to llm
, it can also be copied to the clipboard and then pasted to your LLM chat interface of choice. I've had some very good results using this method with Anthropic Claude 3.5 Sonnet.
files-to-prompt bookstore/models.py bookstore/views.py | pbcopy
Use relative path of files opened in VS Code
In VS Code, you can use the following steps to feed only selected files to files-to-prompt
:
- Select certain files in the VS Code explorer pane on the left (hold
CMD
to select multiple) - Right-click and select
Copy relative path
- Use the following snippet to feed the clip board content to
files-to-prompt
and copy the output to the clip board
pbpaste | xargs files-to-prompt | pbcopy
I've also added this to my aliases.zsh, so I can use this anywhere.
# file-to-prompt from VS code relative paths
function fpc() {
pbpaste | xargs files-to-prompt "$@" | pbcopy
}
The "$@"
can be used to pass arbitrary arguments for files-to-prompt
, such as --cxml
.
Now, the only thing missing is another command line tool that takes the output from an LLM and writes it directly to files in my workspace, so that I only need to review the diff 😜
Edits
- 2025-01-29: Use
xargs
to feed multiple arguments tofiles-to-prompt
instead of$(pbpaste | tr '\n' ' ')
. Also add the note about aliases.zsh.