AI coding agents are changing how we write software, but they can be incredibly token-hungry. Feeding an entire codebase into an LLM context window every time you ask a question is slow, expensive, and quickly hits context limits.
To solve this, LangChain introduced OpenWiki—an open-source CLI tool that automatically scans your codebase and generates structured, agent-friendly documentation. But running LLM-powered documentation pipelines regularly can quickly add up in API costs.
In this guide, we will show you how to set up and configure OpenWiki for your AI coding agents, and how to optimize the setup with a unified AI gateway like Routeway.ai to keep your LLM costs and security fully optimized.
What is OpenWiki?
Developed by LangChain, OpenWiki is a tool that parses your repository to build a queryable wiki stored directly in your codebase (under the openwiki/ folder).
It acts as an external brain for AI coding assistants (like Claude, Gemini, or cursor agents). Instead of scanning raw source code repeatedly, agents can reference the structured openwiki/ markdown documents to quickly retrieve up-to-date context, saving tokens and speeding up development.
Why Use Routeway.ai with OpenWiki?
OpenWiki relies on LLMs to analyze code structures and summarize changes. Running this manually or in a CI/CD pipeline on every commit can lead to high API bills. Using a unified AI gateway like Routeway.ai offers several key advantages:
- Unified AI API Endpoint: Connect OpenWiki to any LLM provider (OpenAI, Anthropic, Gemini, DeepSeek) through a single, unified interface.
- API Key Security & Spending Limits: Since OpenWiki runs in CI/CD (like GitHub Actions), you don't want to expose your main provider API keys. Routeway lets you generate scoped API keys with strict spending limits and automatic alerts.
- Fallback & Redundancy: If a primary LLM provider experiences downtime during your CI build, Routeway can automatically failover to a backup provider so your builds never break.
Step-by-Step Setup Guide
Here is how to connect OpenWiki to Routeway.ai in five minutes.
Step 1: Install OpenWiki
First, install the OpenWiki CLI globally on your system:
npm install -g openwikiStep 2: Configure Your Routeway.ai API Key
If you haven't already, sign up at Routeway.ai and generate an API key.
Step 3: Set Environment Variables
OpenWiki is fully provider-agnostic and supports OpenAI-compatible endpoints. We can configure OpenWiki to use Routeway.ai by setting two environment variables in your terminal:
# Point the base URL to the Routeway unified gateway endpoint
$env:OPENWIKI_PROVIDER = "openai-compatible"
$env:OPENWIKI_MODEL_ID = "model_id"
$env:OPENAI_COMPATIBLE_BASE_URL = "https://api.routeway.ai/v1"
$env:OPENAI_COMPATIBLE_API_KEY = "your-key"Step 4: Initialize and Run OpenWiki
Initialize OpenWiki in the root of your project repository:
openwiki --initThe setup wizard will guide you through choosing your preferred models. Because you are routing through Routeway.ai, you can choose standard models (like gpt-4o or claude-3-5-sonnet) and Routeway will handle the gateway routing.
Upon initialization, OpenWiki will print output confirming what files it has generated:
* Initialized OpenWiki documentation for this repository.
What I created:
- `openwiki/quickstart.md` — entrypoint and repo overview
- `openwiki/architecture/frontend.md` — structure, styling, and runtime shape
- `openwiki/domain/business.md` — café brand, menu, contact, and content model
Also added the required top-level agent instruction file:
- `AGENTS.md` with the OpenWiki reference sectionStep 5: Chat with Your Codebase Interactively
Now that your wiki is initialized and updated, you can query it and chat about your codebase directly from your terminal. Simply run:
openwikiThis launches OpenWiki's interactive Ink-based CLI chat interface. You can immediately ask questions about your repository's structure, files, and architecture (e.g., "How is routing handled?" or "Where are database models defined?").
Because OpenWiki queries the structured files in openwiki/ instead of raw source code, it answers questions faster, uses fewer tokens, and keeps your coding agent workflow completely local and efficient.
Frequently Asked Questions
Does OpenWiki work with Cursor / Claude Projects?
Yes. OpenWiki automatically updates files like AGENTS.md, which modern AI coding agents and tools (like Cursor or Claude Projects) read for instruction guidelines.
How much does it cost to run?
With Routeway's unified AI gateway and smart routing to cheaper models, document generation for most repositories costs just a few dollars per month.
Can I use open-source models?
Yes. Routeway gives you access to many strong open models (such as Llama 3 and DeepSeek) that you can swap in instantly without changing your code configuration.
Is the documentation human-readable?
Absolutely. Although structured for optimal agent consumption, it is generated as clean, standard markdown that is easy for humans to read.
By pairing LangChain's OpenWiki with Routeway's unified AI gateway, you get the best of both worlds: highly accurate, automated docs for your AI coding agents, and absolute control over your API costs and security.
