Context Generator (CTX) is a powerful tool that bridges the gap between your codebase and Language Learning Models (LLMs) like ChatGPT or Claude. It automatically builds organized context files from various sources including code files, repositories, web pages, and plain text, allowing AI tools to understand your project better without manually copying code snippets.
Installing CTX is quick and straightforward:
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
.
Start by creating a configuration file in your project directory:
ctx init
This generates a context.yaml
file with a basic structure to help you get started.
Edit the generated context.yaml
file to specify what code or content you want to include. Here's an example configuration:
$schema: 'https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json'
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 collect all PHP files from the src/Auth
directory and any PHP files containing "User" in their name from the src/Models
directory.
Generate your context file by running:
ctx
CTX will process your configuration and create the specified output file (auth-context.md
in our example).
Upload or paste the generated context file to your preferred 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?
CTX includes a built-in MCP (Model Context Protocol) server that allows Claude AI to directly access your codebase information.
To use the built-in MCP server, configure your MCP client (like Claude) to point to the Context Generator server:
{
"mcpServers": {
"ctx": {
"command": "ctx server -c /path/to/your/project"
}
}
}
With this setup, you can ask Claude questions about your codebase without manually uploading context files.
Start the MCP server directly with:
ctx server -c /path/to/your/project
CTX supports various source types:
You can apply modifiers to transform your content, such as extracting PHP signatures without implementation details:
sources:
- type: file
sourcePaths:
- src/Controllers
filePattern: "*.php"
modifiers:
- type: php-signatures
Configure logging for more detailed output:
ctx -v # Verbose logging
ctx -vv # More verbose
ctx -vvv # Debug level logging
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "ctx" '{"command":"ctx server -c /path/to/your/project"}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"ctx": {
"command": "ctx server -c /path/to/your/project"
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"ctx": {
"command": "ctx server -c /path/to/your/project"
}
}
}
3. Restart Claude Desktop for the changes to take effect