Context Generator is a tool designed to solve a common problem when working with LLMs like ChatGPT, Claude: providing sufficient context about your codebase.
There is an article about Context Generator on Medium that explains the motivation behind the project and the problem it solves.
It automates the process of building context files from various sources:
- Code files,
- GitHub repositories,
- Git commit changes and diffs
- Web pages (URLs) with CSS selectors,
- and plain text.
It was created to solve a common problem: efficiently providing AI language models like ChatGPT, Claude with necessary context about your codebase.
When working with AI-powered development tools context is everything.
-
Code Refactoring Assistance: Want AI help refactoring a complex class? Context Generator builds a properly formatted document containing all relevant code files.
-
Multiple Iteration Development: Working through several iterations with an AI helper requires constantly updating the context. Context Generator automates this process.
-
Documentation Generation: Transform your codebase into comprehensive documentation by combining source code with custom explanations. Use AI to generate user guides, API references, or developer documentation based on your actual code.
-
Seamless AI Integration: With MCP support, connect Claude AI directly to your codebase, allowing for real-time, context-aware assistance without manual context sharing.
- Gathers code from files, directories, GitHub repositories, web pages, or custom text.
- Targets specific files through pattern matching, content search, size, or date filters
- Applies optional modifiers (like extracting PHP signatures without implementation details)
- Organizes content into well-structured markdown documents
- Saves context files ready to be shared with LLMs
- Optionally serves context through an MCP server, allowing AI assistants like Claude to directly access project information
Getting started with Context Generator is straightforward. Follow these simple steps to create your first context file for LLMs.
Download and install the tool using our installation script:
curl -sSL https://raw.githubusercontent.com/context-hub/generator/main/download-latest.sh | sh
This installs the ctx
command to your system (typically in /usr/local/bin
).
Want more options? See the complete Installation Guide for alternative installation methods.
Create a new configuration file in your project directory:
ctx init
This generates a context.yaml
file with a basic structure to get you started.
Pro tip: Run
ctx init --type=json
if you prefer JSON configuration format. Check the Command Reference for all available commands and options.
Edit the generated context.yaml
file to specify what code or content you want to include. For example:
documents:
- description: "User Authentication System"
outputPath: "auth-context.md"
sources:
- type: file
description: "Authentication Controllers"
sourcePaths:
- src/Auth
filePattern: "*.php"
- type: file
description: "Authentication Models"
sourcePaths:
- src/Models
filePattern: "*User*.php"
This configuration will gather all PHP files from the src/Auth
directory and any PHP files containing "User" in their
name from the src/Models
directory.
- Learn about Document Structure and properties
- Explore different source types like GitHub, Git Diff, or URL
- Apply Modifiers to transform your content (like extracting PHP signatures)
- Discover how to use Environment Variables in your config
- Use IDE Integration for autocompletion and validation
Generate your context file by running:
ctx
The tool will process your configuration and create the specified output file (auth-context.md
in our example).
Tip: Configure Logging with
-v
,-vv
, or-vvv
for detailed output
Upload or paste the generated context file to your favorite LLM (like ChatGPT or Claude). Now you can ask specific questions about your codebase, and the LLM will have the necessary context to provide accurate assistance.
Example prompt:
I've shared my authentication system code with you. Can you help me identify potential security vulnerabilities in the user registration process?
Next steps: Check out Development with Context Generator for best practices on integrating context generation into your AI-powered development workflow.
That's it! You're now ready to leverage LLMs with proper context about your codebase.
For a more seamless experience, you can connect Context Generator directly to Claude AI using the MCP server:
There is a built-in MCP server that allows you to connect Claude AI directly to your codebase.
Point the MCP client to the Context Generator server:
{
"mcpServers": {
"ctx": {
"command": "ctx server -c /path/to/your/project"
}
}
}
Note: Read more about MCP Server for detailed setup instructions.
Now you can ask Claude questions about your codebase without manually uploading context files!
For better editing experience, Context Generator provides a JSON schema for autocompletion and validation in your IDE:
# Show schema URL
ctx schema
# Download schema to current directory
ctx schema --download
Learn more: See IDE Integration for detailed setup instructions for VSCode, PhpStorm, and other editors.
For complete documentation, including all available features and configuration options, please visit:
This project is licensed under the MIT License.