Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Gortex Maps a Codebase for AI Coding Agents

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Install Gortex: Run pip install gortex in your terminal. Verify installation with gortex --version.
  2. 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) or set OPENAI_API_KEY=your-key (Windows).
  3. Navigate to your project root: Change directory to the top-level folder of your codebase using cd /path/to/your/project.
  4. Review Gortex configuration: Run gortex init to create a default gortex.config.yaml file. Open it and adjust settings like model, max_tokens, and ignore_paths (e.g., add node_modules or venv).
  5. Run the mapping command: Execute gortex map in the terminal. Gortex will scan your repository, analyze file relationships, and generate a map file (usually gortex_map.md or gortex_map.json).
  6. Specify a focus (optional): If you want to map a specific module or feature, use gortex map --focus src/auth to narrow the analysis to that directory or file.
  7. 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.
  8. 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.md before making changes.
  9. Update the map as needed: After significant code changes, re-run gortex map to 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 init means you miss the chance to exclude large directories (like build or dist), 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, increase max_tokens in the config, or split the repo into smaller parts.
  • Missing files in the map: Check the ignore_paths in your config; you may have accidentally excluded important directories. Also ensure the files are tracked by Git.
  • Map is too verbose: Adjust the detail_level setting in the config (e.g., from high to medium) 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.