This project provides a set of tools to analyze and interact with a codebase using Claude AI. It extracts the contents of a codebase into a single file and allows for interactive conversations about the code using Claude's advanced language model.
- Features
- Installation
- Usage
- Project Structure
- Dependencies
- Configuration
- Troubleshooting
- Contributing
- License
- Extract and compile codebase contents into a single file
- Interactive chat interface with Claude AI about the codebase
- Utilizes prompt caching for improved performance
- Displays token usage and API call time information
-
Clone this repository:
git clone https://github.com/ghsaboias/chat-with-codebase.git cd chat-with-codebase
-
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up your Anthropic API key as an environment variable:
export ANTHROPIC_API_KEY=your_api_key_here
-
Run the
get_codebase.py
script:python utils/get_codebase.py
-
When prompted, enter the path to the directory containing your codebase, or press Enter to use the current directory.
-
Optionally, specify an output file name, or press Enter to use the default
output.txt
.
The script will create a single file containing the contents of all code files in the specified directory, ignoring certain files and directories (like .git
, node_modules
, etc.).
-
Ensure you have run
get_codebase.py
and have anoutput.txt
file containing your codebase. -
Run the main script:
python -m src.main
-
Enter your questions or comments about the codebase when prompted. Type 'exit' to end the conversation.
Claude AI will analyze the codebase and respond to your queries, providing insights and explanations based on the code contents.
src/
: Main source code directory__init__.py
: Package initializerclaude_chat.py
: Handles interactions with the Claude APIconversation_history.py
: Manages the conversation historymain.py
: Main script to run the chat application
utils/
: Utility scripts__init__.py
: Package initializerget_codebase.py
: Script to extract and compile codebase contents
tests/
: Directory for test files (currently empty)config.py
: Contains configuration variablesrequirements.txt
: List of Python package dependenciessetup.py
: Setup script for the projectREADME.md
: This file, containing project documentation
This project relies on several Python packages, including:
- anthropic
- pydantic
- httpx
- tqdm
For a complete list of dependencies and their versions, refer to the requirements.txt
file.
- The
config.py
file contains theMODEL_NAME
variable, currently set to"claude-3-5-sonnet-20240620"
. You can modify this to use a different Claude model if desired. - The chat functionality uses prompt caching to improve performance. This is configured with the
extra_headers
parameter in the API call within theClaudeChat
class.