Skip to content

A CLI tool to prompt Google Gemini with the contents of a directory.

Notifications You must be signed in to change notification settings

bconnorwhite/chatdir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

chatdir

A CLI tool to prompt Google Gemini with the contents of a directory.

Gemini 1.5 Pro has a 2 million token context window, while Gemini 1.5 Flash has a 1 million token context window. Additionally, both models have a free tier. This makes Gemini 1.5 great for high-level prompts over entire directories of your codebase.

Chatdir lets you easily prompt Gemini with an entire directory.

Setup

jq is required as a dependency:

brew install jq

Usage

API Key

Create an API Key to use the Gemini API.

Then, make sure to include it as an environment variable:

GEMINI_API_KEY="your-api-key" ../path/to/chatdir.sh "What is in this directory?"

Or, use the --env flag to load the key from a .env file:

../path/to/chatdir.sh --env ../path/to/.env "What is in this directory?"

Aliasing

Alternatively, you can create an alias in your .zshrc:

# chatdir
chatdir() {
  ~/path/to/chatdir/chatdir.sh --env ~/path/to/chatdir/.env "$@"
}

Then, simply source your .zshrc or restart your terminal to apply the changes:

source ~/.zshrc

You should now be able to use the chatdir command from anywhere in your terminal.

Options

By default, gitignored files are excluded from the prompt.

You can preview the files that will be included by using the --ls flag. Additionally, you can preview the full prompt by using the --stdout flag, or the curl command that will be sent to Google with the --dry-run flag.

Usage: chatdir [question] [directory]
   -e, --env <file>   Load GEMINI_API_KEY from a .env file
   -m, --model <name> Use the specified model (default: gemini-1.5-pro-latest)
       --flash        Use the gemini-1.5-flash-latest model
       --ls           List all targeted files
       --stdout       Print the generated prompt to stdout
       --tokens       Count the tokens in the generated prompt without prompting the model
       --dry-run      Print the resulting curl command without executing it
   -h, --help         Show this help message

Prompt Format

Prompts use the following format:

Project Directory: /path/to/dir

Included Files:

```
/path/to/dir/file1.ext
/path/to/dir/file2.ext
```

`/path/to/dir/file1.ext`:

```````ext
file1...
```````

`/path/to/dir/file2.ext`:

```````ext
file2...
```````

---

Your question here

Releases

No releases published

Packages

No packages published

Languages