Gortex Maps a Codebase for AI Coding Agents
In this article
Gortex maps a codebase for AI coding agents by generating a structured, machine-readable overview of your project's architecture, dependencies, and key files. This helps AI agents navigate unfamiliar code faster, reducing errors and improving context. Before you start, ensure your codebase is in a Git repository and you have Gortex installed (via pip install gortex) and a valid OpenAI API key (or another LLM provider key) set in your environment variables.
What You'll Need
- Gortex CLI installed (Python 3.8+ recommended)
- An LLM API key (e.g., OpenAI) with access to the model you plan to use
- Your codebase in a Git repository (Gortex uses Git history for context)
- Basic familiarity with your project's structure and purpose
Step-by-Step
- Install Gortex: Run
pip install gortexin your terminal. Verify installation withgortex --version. - Set up your API key: Export your LLM API key as an environment variable. For OpenAI, run
export OPENAI_API_KEY="your-key"(Linux/macOS) orset OPENAI_API_KEY=your-key(Windows). - Navigate to your project root: Change directory to the top-level folder of your codebase using
cd /path/to/your/project. - Review Gortex configuration: Run
gortex initto create a defaultgortex.config.yamlfile. Open it and adjust settings likemodel,max_tokens, andignore_paths(e.g., addnode_modulesorvenv). - Run the mapping command: Execute
gortex mapin the terminal. Gortex will scan your repository, analyze file relationships, and generate a map file (usuallygortex_map.mdorgortex_map.json). - Specify a focus (optional): If you want to map a specific module or feature, use
gortex map --focus src/authto narrow the analysis to that directory or file. - Review the generated map: Open the output file. It should contain a high-level overview, key files, dependencies, and data flow descriptions. Verify it accurately reflects your project's structure.
- Integrate with your AI agent: Provide the map file to your AI coding agent (e.g., as a context file in your prompt or as a reference in your agent's configuration). For example, you can instruct the agent to read
gortex_map.mdbefore making changes. - Update the map as needed: After significant code changes, re-run
gortex mapto keep the map current. You can also schedule it as part of your CI pipeline.
Common Mistakes
- Running Gortex without Git: Gortex relies on Git history for context. If your project isn't a Git repo, the map may be incomplete or fail.
- Ignoring the config file: Skipping
gortex initmeans you miss the chance to exclude large directories (likebuildordist), which can bloat the map and slow down generation. - Not setting the API key: Forgetting to set the environment variable leads to authentication errors. Always double-check that the key is exported in the same shell session.
- Overlooking the map's limits: The map is a summary, not a full codebase dump. Don't expect it to include every line of code; it's meant to give an AI agent a high-level orientation.
Tips
- Customize the prompt: When using the map with an AI agent, explicitly instruct it to reference the map first. For example, "Read gortex_map.md to understand the project structure before making changes."
- Use the JSON output: If you're building a tool that consumes the map programmatically, prefer the JSON format (
gortex map --format json) for easier parsing. - Keep the map in version control: Commit the map file to your repo so all team members and AI agents see the same version. Update it regularly.
- Combine with other tools: Use Gortex alongside code search tools (like ripgrep) to give agents both a map and the ability to find specific code snippets.
Troubleshooting
- Authentication errors: If you get a 401 error, your API key is wrong or not set. Re-export the key and try again.
- Map generation hangs: This often happens with very large repos or high token usage. Reduce the scope with
--focus, increasemax_tokensin the config, or split the repo into smaller parts. - Missing files in the map: Check the
ignore_pathsin your config; you may have accidentally excluded important directories. Also ensure the files are tracked by Git. - Map is too verbose: Adjust the
detail_levelsetting in the config (e.g., fromhightomedium) to get a more concise summary. - Gortex command not found: If you installed via pip but the command isn't recognized, check your Python scripts directory is in your PATH, or reinstall with
python -m pip install gortex.
Frequently Asked Questions
Does Gortex work with any AI coding agent?
Yes, Gortex generates a generic map file (Markdown or JSON) that can be fed into any AI agent that accepts context files, such as GitHub Copilot, Cursor, or custom agents.
Can I use Gortex with a local LLM?
Gortex is designed to work with OpenAI-compatible APIs. If your local LLM (like Ollama) exposes an OpenAI-compatible endpoint, you can configure it in the gortex.config.yaml by setting the api_base and model.
How long does mapping take?
It depends on the size of your codebase and the model used. For a typical mid-sized project (e.g., 10k lines), it might take 1-3 minutes. Larger repos can take longer, so consider using --focus for quicker runs.
Will Gortex expose my code to third parties?
Gortex sends code snippets to the LLM API you configure. If you use a cloud provider like OpenAI, your code is processed by their servers. For sensitive code, use a local LLM or a private cloud deployment.
Can I map a monorepo with multiple services?
Yes, Gortex can handle monorepos. It will generate a single map that covers all services. You can also run gortex map --focus services/auth to get a map for a specific service.
How often should I update the map?
Update the map whenever there are significant architectural changes or before starting a large AI-assisted refactor. For active development, consider generating a fresh map daily or weekly.