|
| 1 | +--- |
| 2 | +title: "How to copy projects for Claude" |
| 3 | +categories: |
| 4 | + - Blog |
| 5 | +tags: |
| 6 | + - Programming |
| 7 | + - Tech |
| 8 | + - Python |
| 9 | + - MacOS |
| 10 | + - Claude |
| 11 | + - AI |
| 12 | +--- |
| 13 | + |
| 14 | +*This is meant to be an explanation of my workflow for providing Claude with context about specific Python packages so that I can ask questions about it. Note that this workflow is best suited for smaller packages because not all packages will fit into Claude's context window. I wrote it for my brother.* |
| 15 | + |
| 16 | +## The Toolkit |
| 17 | + |
| 18 | +The main thing I want to get across is that using `files-to-prompt` is a great way to quickly grab context about a bunch of files in a folder and provide it to an LLM. I also pair this with `ttok` because that tells you the number of tokens that that's going to take when it's provided to the chatbot, and there are limits to how much they can actually read. |
| 19 | + |
| 20 | +Usually, I'll make a query with `files-to-prompt` and see how many tokens that takes before I pipe it into `pbcopy` instead, so that I get it copied, and then I can take it over to Claude and paste it into its context. |
| 21 | + |
| 22 | +## Basic File Selection with `files-to-prompt` |
| 23 | + |
| 24 | +If I need to be more granular about what files I'm selecting, I have two courses of action. The first is to use the built-in file selection mechanisms that come with `files-to-prompt`. |
| 25 | + |
| 26 | +Typically, if you want to include all the files, you might do something like: |
| 27 | + |
| 28 | +```bash |
| 29 | +files-to-prompt . |
| 30 | +files-to-prompt --include-hidden . |
| 31 | +``` |
| 32 | + |
| 33 | +The first one selects all the non-hidden files in the current directory. The second also includes the hidden files. |
| 34 | + |
| 35 | +If I'm working with Python files specifically and I just want to select the Python files in a directory, then I would specify the extension that I want to select for: |
| 36 | + |
| 37 | +```bash |
| 38 | +files-to-prompt -e py . |
| 39 | +``` |
| 40 | + |
| 41 | +## A Complete Workflow Example |
| 42 | + |
| 43 | +Let me break down step-by-step how I might get access to and then get a copy-paste version of a Python package that I need to ask Claude questions about: |
| 44 | + |
| 45 | +```bash |
| 46 | +$ git clone https://github.com/Westwood-Robotics/PyBEAR.git |
| 47 | +Cloning into 'PyBEAR'... |
| 48 | +remote: Enumerating objects: 244, done. |
| 49 | +remote: Counting objects: 100% (48/48), done. |
| 50 | +remote: Compressing objects: 100% (44/44), done. |
| 51 | +remote: Total 244 (delta 10), reused 18 (delta 2), pack-reused 196 (from 1) |
| 52 | +Receiving objects: 100% (244/244), 66.22 KiB | 105.00 KiB/s, done. |
| 53 | +Resolving deltas: 100% (137/137), done. |
| 54 | + |
| 55 | +$ files-to-prompt -e py PyBEAR | ttok |
| 56 | +19885 |
| 57 | + |
| 58 | +$ files-to-prompt -e py PyBEAR | pbcopy |
| 59 | +``` |
| 60 | + |
| 61 | +In the first step, I clone the project I'm interested in. In the next step, I use `files-to-prompt` and select for the Python file extension and pipe that into `ttok` to see how many tokens it would take up in the context window. 20k is less than Claude's limit, so I know that it's safe to move forward with this. The final command, `pbcopy`, copies the output so that I can paste it later. |
| 62 | + |
| 63 | +## Advanced File Selection with `fd` |
| 64 | + |
| 65 | +There are a number of tools that you can use to improve this workflow. For example, instead of using the file selection tools provided by `files-to-prompt`, which are pretty rudimentary, you can use a slightly more sophisticated file selection tool called `fd`. The output from `fd` can be piped into `files-to-prompt` because `files-to-prompt` is designed to be able to do that. |
| 66 | + |
| 67 | +Here is a working example: |
| 68 | + |
| 69 | +```bash |
| 70 | +$ fd --type file "\.py" PyBEAR |
| 71 | +PyBEAR/examples/set_position.py |
| 72 | +PyBEAR/examples/spring2damper.py |
| 73 | +PyBEAR/pybear/CONTROL_TABLE.py |
| 74 | +PyBEAR/pybear/CRC.py |
| 75 | +PyBEAR/pybear/Manager.py |
| 76 | +PyBEAR/pybear/Packet.py |
| 77 | +PyBEAR/pybear/TIMING_TABLE.py |
| 78 | +PyBEAR/pybear/__init__.py |
| 79 | +PyBEAR/pybear/__main__.py |
| 80 | +PyBEAR/setup.py |
| 81 | +PyBEAR/useful_tools/ID_Setup.py |
| 82 | +PyBEAR/useful_tools/Search_N_Change_ID.py |
| 83 | +PyBEAR/useful_tools/bulk_comm_freq_test.py |
| 84 | +PyBEAR/useful_tools/ping.py |
| 85 | + |
| 86 | +$ fd --type file "\.py" PyBEAR | files-to-prompt | ttok |
| 87 | +19885 |
| 88 | + |
| 89 | +$ fd --type file "\.py" PyBEAR | files-to-prompt | pbcopy |
| 90 | +``` |
| 91 | + |
| 92 | +In this example, I use `fd` so that I can see the files I'm selecting before I go and read their contents with `files-to-prompt`, and the advantage of this is that I can scan the list and see if there's something that I want to exclude beforehand. This example doesn't showcase some of the more advanced selection tools that `fd` has available to it, but I'm not going to get into that in this write-up. |
| 93 | + |
| 94 | +## Installing the Tools |
| 95 | + |
| 96 | +I'm going to cover how to do this on the Mac, and I think you can figure out with assistance from Claude how to adapt this for other platforms as necessary. |
| 97 | + |
| 98 | +The core tools in this workflow, `files-to-prompt` and `ttok`, are distributed as Python packages and can be installed with the Python package manager (and much more), `uv`. |
| 99 | + |
| 100 | +To install `uv`, look up how to install `uv` because I don't want to include instructions in here that might become outdated. |
| 101 | + |
| 102 | +Once you have `uv` installed, you can install the tools with `uv tool install <toolname>`: |
| 103 | + |
| 104 | +```bash |
| 105 | +uv tool install files-to-prompt |
| 106 | +uv tool install ttok |
| 107 | +``` |
| 108 | + |
| 109 | +`pbcopy` is what you can use on Mac (and I think on Unix more generally) to take something and copy it. I'm not sure what the equivalent is on Windows. |
| 110 | + |
| 111 | +`fd` is an optional portion of this guide, so I won't be including download instructions. In my setup, I install it with homebrew (command `brew`), the package manager for macOS (and Linux). |
| 112 | + |
| 113 | +## Example |
| 114 | + |
| 115 | +[Claude chat where I ask questions about PyBEAR](https://claude.ai/share/5efbdc62-ab54-4e8d-b117-5f86b0d7c509) |
| 116 | + |
| 117 | +*If you encounter any issues with this workflow, I recommend troubleshooting with Claude.* |
0 commit comments