CoPa is a simple CLI tool for creating structured prompts for Large Language Models (LLMs) using file references. It offers two main functionalities:
- Processing LLM prompt templates with file references
- Copying file contents in an LLM-friendly format
- Process template files with dynamic file references
- Copy an entire folder or a single file to clipboard in a LLM friendly format
- Support for Git repositories and respect for
.gitignore
- Built-in token counting
- Easy-to-use CLI utility
- Inline ignore patterns for fine-grained control over included files
Use CoPa directly with npx
(recommended) or install it globally.
Process a template file:
npx copa t prompt.copa
Install CoPa globally:
npm install -g copa
Then use it as:
copa t prompt.copa
Create a template file (e.g., prompt.copa
) using {{@filepath}}
to reference files or directories:
Analyze this code:
```
{{@src/main.js}}
```
And its test:
```
{{@tests/main.test.js}}
```
Review the entire 'utils' directory:
```
{{@utils}}
```
Review the 'src' directory, excluding .test.js files:
```
{{@src:-*.test.js}}
```
Review all files in the current directory, excluding markdown files and the 'subdir' directory:
```
{{@.:-*.md,-**/subdir/**}}
```
[new feature description / instructions for the LLM]
Process the template and copy to clipboard:
copa template prompt.copa
# or use the short alias
copa t prompt.copa
You can use inline ignore patterns to exclude specific files or patterns within a directory reference:
{{@directory:-pattern1,-pattern2,...}}
Examples:
{{@src:-*.test.js}}
includes all files in the 'src' directory except for files ending with '.test.js'{{@.:-*.md,-**/subdir/**}}
includes all files in the current directory, excluding markdown files and the 'subdir' directory{{@.:-**/*dir/**,-*.y*}}
excludes all files in any directory ending with 'dir' and all files with extensions starting with 'y'
Ignore patterns support:
- File extensions:
-*.js
- Specific files:
-file.txt
- Directories:
-**/dirname/**
- Glob patterns:
-**/*.test.js
- Hidden files and directories:
-.*
-
t, template <file>
: Process a template file- Option:
-v, --verbose
(Display detailed file and token information)
- Option:
-
c, copy [directory]
: Copy files to clipboard (legacy mode)- Options:
-ex, --exclude <extensions>
(Exclude file types)-v, --verbose
(List copied files)-f, --file <filePath>
(Copy a single file)
- Options:
CoPa uses a format that's easy for LLMs to understand:
Analyze this code:
```
===== src/main.js =====
File contents here...
```
And its test:
```
===== tests/main.test.js =====
...
- Control over what's included in a prompt
- Repeatable complex prompts with complex file imports
- Sharing project wide prompt templates
- Any task requiring code context from multiple files
- Use relative paths in templates for better portability
- Create a "prompts" directory in project root
- Create a library of templates for common tasks
- Use inline ignore patterns for fine-grained control over included files
Create ~/.copa
to set default exclude patterns:
ignore: jpg,png,gif
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.