Azer Koçulu Nov 11, 2024

llmcat - Copy Code from CLI to LLMs

I frequently need to feed parts of my codebase to LLMs. Manually going into the directories, finding the files, and preparing them in the right format for LLMs was taking me away from what I really want to do.

I built llmcat to automate this part. It reads files or directories, formats them properly and copies to clipboard as one large Markdown document, respecting .gitignore.

It's very simple to use.

$ llmcat . # Copies entire directory
$ llmcat foo/bar.txt # Copies single file

When you run it, the content will be copied in following format:

# Directory: src/state

[file tree]

## File: src/state/config.ts
---
[file contents]

...

Interactive Mode

Suppose you work in a large repository and want to copy multiple files/directories. Instead of going into each directory and formatting/copying/pasting manually, you can use llmcat's interactive mode to fuzzy search and copy files.

Just run llmcat without parameters to open interactive mode:

$ llmcat

And press tab to select files & directories, like below:

llmcat 3

When done, press enter and everything will be copied in following format:

## File: assets/js/state/config.js
---
[content]

## File: README.md
---
[content]

...

A longer video that shows full workflow and the output: Watch on X.

Using with LLM CLI

You can pipe llmcat's output to Simon Willison's LLM tool by running it in print mode (-p, --print):

$ llmcat -p assets/js/state | llm "explain this code"

You can pipe output in interactive mode:

$ llmcat -p | llm "Fix typing issues"

Install

llmcat is just a bash script that works in both OSX and Linux. To install:

# Download the script
curl -o llmcat https://raw.githubusercontent.com/azer/llmcat/main/llmcat

# Make it executable
chmod +x llmcat

# Move to your PATH
sudo mv llmcat /usr/local/bin/

You'll need following dependencies (brew install fzf bat or apt install fzf bat):

Check out github.com/azer/llmcat for more details about available options.

Hope it's useful! Let me know how your experience goes: @azerkoculu

Back