liam.pm

Feeding files into an LLM

Source: https://news.ycombinator.com/item?id=43048831

Basic approach

find . -print -exec cat {} \; -exec echo \;

This returns the filename and content for each file, which you can pipe to pbcopy to paste into an LLM.

Improved version

find . \
    -type d \( -path ./bin -o -path ./debug -o -path ./obj \) -prune -o \
    -type f \( -name "*.cs" -o -name "*.md" \) \
    ! \( -name "Program.cs" -o -name "*Temp*.cs" \) \
    -exec echo -n $'```\n// ' \; \
    -print -exec cat {} \; \
    -exec echo $'```\n' \; | pbcopy

Breakdown

  1. find . - Start from current directory
  2. -type d \( -path ./bin -o -path ./debug -o -path ./obj \) -prune -o - Skip specified directories (build artifacts)
  3. -type f \( -name "*.cs" -o -name "*.md" \) - Include only specific file types
  4. ! \( -name "Program.cs" -o -name "*Temp*.cs" \) - Exclude specific files
  5. -exec echo -n $'```\n// ' \; - Start code block with comment prefix
  6. -print - Print filename
  7. -exec cat {} \; - Print file contents
  8. -exec echo $'```\n' \; - End code block
  9. | pbcopy - Copy it all to the clipboard