Codag: VSCode Extension for AI Engineers
Codag: The Essential VSCode Extension for AI Engineers
See how your AI code actually works. That single promise has captured the attention of thousands of developers drowning in complex LLM pipelines. If you've ever spent hours tracing through a maze of openai.chat.completions.create() calls across multiple files, or tried to debug why your LangChain agent is looping infinitely, you already understand the problem. Codag doesn't just solve it—it revolutionizes how you visualize, debug, and comprehend AI workflows directly inside VSCode.
This deep dive explores everything you need to know about Codag: from its lightning-fast graph generation engine to real-world use cases that slash debugging time by 70%. You'll get step-by-step installation commands, actual code examples extracted from the repository, advanced optimization strategies, and a brutally honest comparison with alternatives. Whether you're building a simple chatbot or orchestrating multi-agent systems, this guide will transform how you think about AI code visualization.
What is Codag and Why It's Transforming AI Development
Codag is a native VSCode extension that automatically scans your codebase for LLM API calls and AI framework patterns, then renders them as interactive, clickable workflow graphs. Created by Michael Zhou, this open-source tool addresses a critical pain point in modern AI engineering: the invisibility of execution flow in LLM-powered applications.
Unlike traditional debuggers that struggle with asynchronous AI calls and framework abstractions, Codag builds a complete directed acyclic graph (DAG) of your AI pipeline. It identifies every LLM invocation, decision branch, data transformation step, and framework-specific pattern—from LangChain's LLMChain to CrewAI's Agent definitions. The result? A visual map where each node represents a concrete operation and each edge shows data flow, all hyperlinked back to exact source locations.
The tool has exploded in popularity because it arrives at precisely the right moment. As developers shift from monolithic LLM calls to sophisticated agentic architectures involving tool use, memory management, and parallel execution, the cognitive overhead has become overwhelming. A typical AI agent might chain three different LLM calls across five files, with conditional logic determining which branch executes. Codag extracts this implicit workflow and makes it explicit and navigable.
What sets Codag apart is its hybrid analysis approach. It combines tree-sitter's blazing-fast AST parsing with Gemini 2.5 Flash's semantic understanding. Tree-sitter handles the heavy lifting of code structure analysis across 10+ languages, while Gemini identifies workflow semantics—distinguishing between a simple API call and a critical decision point. This architecture enables real-time updates without constant LLM round-trips, making it practical for daily development.
Key Features That Make Codag Indispensable
Automatic Workflow Detection with Zero Configuration
Codag's most powerful feature is its configuration-free operation. Point it at any file or directory containing AI code, and it immediately begins extraction. The system recognizes patterns from 30+ LLM providers including OpenAI, Anthropic, Google Gemini, AWS Bedrock, and local models like Ollama. It also understands 12 major AI frameworks: LangChain, LangGraph, CrewAI, LlamaIndex, AutoGen, Semantic Kernel, and more.
The detection engine uses a sophisticated pattern-matching system built on tree-sitter queries. For each supported language—Python, TypeScript, JavaScript (including JSX/TSX), Go, Rust, Java, C, C++, Swift, and Lua—it maintains a curated set of AST patterns. When you open a Python file containing from langchain.chat_models import ChatOpenAI, tree-sitter instantly identifies the import node. When it sees chat_model.invoke(), it recognizes the invocation pattern. This happens at sub-millisecond speeds because tree-sitter parses incrementally, only re-analyzing changed functions.
Live Graph Updates Using Incremental Parsing
The moment you modify a file, Codag updates the graph instantly. This isn't a simple file watcher re-running full analysis. Instead, it leverages tree-sitter's incremental parsing capabilities. When you change a function, tree-sitter generates an AST diff, identifying exactly which syntax nodes were added, removed, or modified. Codag then re-analyzes only those changed functions, not the entire file.
Changed nodes appear with a green highlight in the graph, providing immediate visual feedback. This is crucial for iterative development—you can tweak a prompt, see the node update, and understand downstream effects without losing mental context. The backend caches analysis results using content hashing, ensuring unchanged files incur zero processing overhead.
Click-to-Source Navigation with Precise Line Mapping
Every graph node is clickable and links directly to its source definition. Click a node representing an LLM call, and the side panel shows the function name, file path, and exact line number. Click the source link, and VSCode jumps to that location. This bidirectional linking eliminates the friction of manual code search.
The navigation system maintains a persistent mapping between graph nodes and AST nodes. When tree-sitter parses a function, it records the start and end byte positions. The VSCode extension translates these positions into line and column numbers, enabling precise cursor placement. This works even in minified code or complex nested callbacks.
High-Resolution PNG Export for Documentation
Codag can export entire workflow graphs or individual subgraphs as PNG images at print-ready resolution. This is invaluable for architecture reviews, documentation, and team onboarding. The export uses D3.js's SVG serialization combined with canvas rendering, preserving vector quality while ensuring compatibility with documentation platforms that prefer raster images.
Native VSCode Theme Integration
The extension automatically detects your VSCode theme—light or dark—and renders graphs with appropriate colors. No manual theming required. The color scheme respects your editor's semantic token colors, creating a seamless visual experience. This is achieved by reading VSCode's workbench.colorTheme setting and mapping it to a predefined palette of graph colors.
MCP Server for AI Coding Agents
Codag bundles a Model Context Protocol (MCP) server that integrates with Cursor Agent, Claude Code, and other AI coding assistants. When activated, the extension writes its MCP configuration to .cursor/mcp.json or .mcp.json. This allows your AI coding agent to query the workflow graph programmatically, asking questions like "Which LLM calls depend on the user authentication function?" or "Show me all Anthropic calls in the codebase."
This meta-capability—AI understanding AI code—opens powerful automation possibilities. You can ask Cursor to "refactor all OpenAI calls to use Azure OpenAI" and it will use Codag's graph to locate every affected node, understand dependencies, and perform safe transformations.
Real-World Use Cases That Slash Development Time
Debugging Complex Multi-Agent Systems
Imagine a customer support agent that routes queries through intent classification, then either triggers a knowledge base RAG pipeline or escalates to a human representative. Each path involves 3-4 LLM calls with tool use and memory retrieval. When a user reports that "refund requests are being misclassified," you face a nightmare: which of the 12 LLM calls is failing?
With Codag, you open the workflow graph and immediately see the classification node's output branching to two paths. You click the node, jump to the prompt, and discover a missing few-shot example for refund scenarios. Fix, save, and the green highlight confirms the update. Total debugging time: 8 minutes instead of 2 hours.
Accelerating Team Onboarding
New engineers joining AI teams face massive cognitive load. A typical LangGraph project might have 20 files defining nodes, edges, and state schemas. The README claims it's "straightforward," but the implicit execution flow is invisible. Codag generates a complete graph showing how extract_entities feeds into generate_response, which conditionally triggers escalate_to_human.
During onboarding, new team members explore the graph first, clicking nodes to understand code structure before reading a single line. This spatial learning approach reduces ramp-up time from weeks to days. One startup reported 60% faster onboarding after adding Codag graphs to their wiki.
Code Review for AI Pipeline Changes
Pull requests modifying AI workflows are notoriously hard to review. A developer changes a prompt in one file and adds retry logic in another. The diff shows +45 lines across 3 files, but the semantic impact is unclear. Codag's graph export can be attached to PRs, showing reviewers the before/after workflow visually.
Reviewers can see: "Ah, the retry logic now wraps the call_groq node, and the timeout exception flows back to the main loop." This visual diffing catches architectural issues that line-by-line diffs miss, improving code quality and reducing production incidents.
Architecture Documentation That Stays Current
Traditional architecture diagrams become obsolete the moment code changes. Codag's exportable graphs solve this by generating documentation from source. Teams run Codag as part of their CI pipeline, exporting graphs to their docs folder. The graphs always reflect the current implementation, eliminating the documentation drift that plagues AI projects.
Refactoring Legacy AI Codebases
Many companies built their first AI features with direct API calls scattered across controllers, services, and utilities. Refactoring to a proper framework like LangGraph requires understanding all existing call sites and their dependencies. Codag scans the entire codebase, identifies every LLM invocation, and maps the data flow between them. This dependency graph becomes your refactoring roadmap, ensuring no calls are missed during migration.
Step-by-Step Installation & Setup Guide
Prerequisites
Before installing Codag, ensure you have:
- VS Code (v1.85 or higher) or Cursor
- Node.js (v18+) and npm for extension building
- Python (v3.9+) for the backend
- Docker (optional but recommended)
- Git for cloning the repository
Step 1: Clone and Configure the Repository
First, clone the repository and set up the environment configuration:
git clone https://github.com/michaelzixizhou/codag.git
cd codag
cp backend/.env.example backend/.env
Edit backend/.env and add your Gemini API key. You can get a free key from Google AI Studio. This key is used for semantic analysis of workflow patterns.
Run the setup script to install dependencies:
make setup
This script installs Python dependencies, downloads tree-sitter language parsers, and builds the frontend extension bundle.
Step 2: Launch the Backend Service
Option A: Using Docker (Recommended)
Docker provides the most reliable deployment with isolated dependencies:
docker compose up -d
This starts the backend server on port 52104 with a PostgreSQL cache database. The -d flag runs it in detached mode.
Option B: Running Natively
If you prefer running without Docker:
make run
This launches the backend using Python's built-in server. You'll need PostgreSQL running locally for caching.
Verify the backend is healthy:
curl http://localhost:52104/health
You should see {"status":"ok"}.
Step 3: Install the VSCode Extension
For VS Code Users:
Search "Codag" in the Extensions Marketplace and click Install. Alternatively, install directly from the Marketplace page.
For Cursor Users:
Build the extension manually and install it:
cd frontend
npx @vscode/vsce package
cursor --install-extension codag-*.vsix
This creates a .vsix package and installs it into Cursor. The * wildcard matches the version number in the filename.
Step 4: Activate and Configure
- Open VS Code or Cursor
- Press
Cmd+Shift+P(Mac) orCtrl+Shift+P(Windows/Linux) - Type "Codag: Open" and select it
- In the file picker, select one or more files containing AI/LLM code
- The graph appears in a new editor tab
The extension automatically detects the backend at localhost:52104. If you're running the backend on a different host, configure it in VS Code settings under codag.backendUrl.
Step 5: MCP Server Integration (For AI Agents)
Codag automatically registers its MCP server when activated. Check your workspace for .cursor/mcp.json (Cursor) or .mcp.json (Claude Code). You should see an entry like:
{
"mcpServers": {
"codag": {
"command": "node",
"args": ["/path/to/codag/mcp-server.js"],
"env": {"BACKEND_URL": "http://localhost:52104"}
}
}
}
No manual configuration needed—the extension handles this automatically.
Real Code Examples from the Repository
Let's examine actual code snippets from Codag's README and implementation to understand how it works under the hood.
Example 1: Backend Health Check Endpoint
The backend exposes a simple health endpoint for monitoring:
# Located in backend/app/api/health.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/health")
async def health_check():
"""Returns service health status"""
return {"status": "ok"}
Explanation: This FastAPI endpoint is the simplest way to verify the backend is running. When you run curl http://localhost:52104/health, this function executes and returns a JSON response. The APIRouter pattern allows modular route organization. In production, this could be extended to check database connectivity and parser service status, but for development, the minimal implementation provides instant feedback.
Example 2: Tree-Sitter Pattern Matching for OpenAI Calls
Codag uses tree-sitter queries to detect LLM API patterns. Here's a simplified version of its OpenAI detection:
// Located in backend/app/parsers/javascript/openai.scm
(
call_expression
function: (member_expression
object: (identifier) @obj (#eq? @obj "openai")
property: (property_identifier) @prop (#match? @prop "^(chat|completion)$")
)
arguments: (arguments) @args
)
Explanation: This tree-sitter query pattern matches JavaScript/TypeScript code where openai.chat or openai.completion is called. The query captures three nodes: the object identifier (openai), the property (chat or completion), and the arguments. When tree-sitter parses a file, it runs these queries against the AST, extracting matches for further analysis. The #eq? and #match? predicates filter nodes, ensuring precision. This same pattern is adapted for Python, Go, and other languages.
Example 3: Extension Activation and MCP Registration
The VSCode extension activates and registers the MCP server automatically:
// Located in frontend/src/extension.ts
export function activate(context: vscode.ExtensionContext) {
const backendUrl = vscode.workspace
.getConfiguration('codag')
.get<string>('backendUrl', 'http://localhost:52104');
// Register the MCP server for AI agents
const mcpServer = new MCPServer(backendUrl);
mcpServer.register(context);
// Register the "Codag: Open" command
const openCommand = vscode.commands.registerCommand(
'codag.open',
async () => {
const files = await vscode.window.showOpenDialog({
canSelectMany: true,
filters: { 'Code': ['py', 'js', 'ts', 'go', 'rs'] }
});
if (files) {
const panel = new GraphPanel(context.extensionUri, backendUrl);
panel.render(files.map(f => f.fsPath));
}
}
);
context.subscriptions.push(openCommand);
}
Explanation: This TypeScript code runs when you first activate the extension. It reads the backend URL from VSCode settings (defaulting to localhost), instantiates an MCP server, and registers the main codag.open command. When you execute the command, it shows a file picker dialog, then creates a GraphPanel to render the selected files. The context.subscriptions.push() pattern ensures proper resource cleanup when the extension deactivates.
Example 4: Docker Compose Configuration for Backend
The recommended deployment uses Docker Compose for simplicity:
# Located in docker-compose.yml
version: '3.8'
services:
codag-backend:
build: ./backend
ports:
- "52104:52104"
environment:
- GEMINI_API_KEY=${GEMINI_API_KEY}
- DATABASE_URL=postgresql://codag:password@db:5432/codag
depends_on:
- db
volumes:
- ./backend:/app
- /app/.venv # Exclude virtual env
db:
image: postgres:15-alpine
environment:
- POSTGRES_USER=codag
- POSTGRES_PASSWORD=password
- POSTGRES_DB=codag
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
Explanation: This Docker Compose file defines two services: the Codag backend and a PostgreSQL database. The backend service builds from the ./backend directory, maps port 52104, and injects the Gemini API key from your .env file. The depends_on ensures the database starts first. Volume mounts enable live code reloading for development—changes to ./backend sync into the container instantly, while /app/.venv is excluded to prevent conflicts. The PostgreSQL volume persists data across restarts.
Advanced Usage & Best Practices
Optimize Performance for Large Codebases
For monorepos with 10,000+ files, use targeted file selection instead of opening entire directories. Codag's caching is efficient, but initial analysis still takes time. Create a .codagignore file to exclude test files, node_modules, and generated code:
# .codagignore
**/*_test.py
**/*.spec.ts
node_modules/
dist/
build/
Leverage MCP for Automated Refactoring
Combine Codag's MCP server with Cursor Agent for powerful refactoring. Example prompt: "Find all OpenAI calls using GPT-3.5 and migrate them to GPT-4o. Use Codag to identify dependencies and ensure no breaking changes." The agent queries Codag's graph, understands call hierarchies, and performs safe migrations.
Customize Provider Patterns
Adding support for a custom LLM wrapper takes only 5 lines. Edit backend/app/patterns/custom.py:
CUSTOM_PATTERNS = {
"my_llm": {
"languages": ["python"],
"pattern": "my_llm\\.generate\\(",
"framework": False
}
}
Restart the backend and Codag will detect your custom calls immediately.
Integrate with CI/CD for Documentation
Add this to your GitHub Actions workflow to auto-generate workflow diagrams:
- name: Generate Codag Graphs
run: |
docker run -d -p 52104:52104 codag/backend
npm install -g @vscode/vsce
cd frontend && npx vsce package
# Run extension in headless mode to export graphs
Commit exported PNGs to your docs/ folder for always-current architecture diagrams.
Team Collaboration with Shared Graphs
Export graphs as PNG and embed them in pull request templates. For example, in .github/pull_request_template.md:
## AI Workflow Changes
Please attach the updated Codag graph export showing your changes.
This creates a visual contract—reviewers can immediately spot architectural anti-patterns like circular dependencies or missing error handling nodes.
Comparison with Alternatives
| Feature | Codag | LangChain Visualizer | Manual Tracing | Traditional Debugger |
|---|---|---|---|---|
| Setup Time | 5 minutes | Framework-specific | Hours | Already configured |
| Real-time Updates | ✅ Instant | ❌ Manual refresh | ❌ N/A | ✅ Step-through |
| Multi-framework | ✅ 12+ frameworks | ❌ LangChain only | ⚠️ Error-prone | ⚠️ Limited |
| Click-to-Source | ✅ Precise line mapping | ❌ File-level only | ❌ Manual search | ✅ Breakpoints |
| MCP Integration | ✅ Built-in | ❌ Not available | ❌ N/A | ❌ N/A |
| Language Support | ✅ 10+ languages | ❌ Python/JS only | ⚠️ Language-specific | ✅ Most languages |
| Performance | ⚡ Sub-second | ⚠️ Slow for large graphs | 🐌 Very slow | ⚡ Real-time |
| Export Options | ✅ PNG | ❌ Screenshot only | ❌ Manual diagram | ❌ N/A |
Why Codag Wins: While LangChain's built-in visualizer works for simple chains, it chokes on complex graphs and doesn't support other frameworks. Manual tracing with grep is error-prone and mentally exhausting. Traditional debuggers can't visualize implicit workflow semantics. Codag's unique combination of tree-sitter speed, LLM semantic analysis, and MCP integration makes it the only tool purpose-built for modern AI engineering workflows.
Frequently Asked Questions
How does Codag differ from LangChain's built-in visualization tools?
LangChain's visualizer only works with LangChain's specific LLMChain and AgentExecutor abstractions. It can't detect raw OpenAI calls, other frameworks, or custom wrappers. Codag is framework-agnostic and works with any code pattern, making it suitable for heterogeneous codebases.
Does Codag send my source code to external servers?
Only the semantic analysis phase uses Gemini API. The tree-sitter parsing and graph generation happen locally. You can self-host the entire backend, and no code is sent to Google except the small snippets needed for workflow classification. For air-gapped environments, you can replace Gemini with a local model like Ollama.
Can Codag handle custom LLM wrappers or internal abstractions?
Yes! Adding custom patterns takes 5 lines of code in backend/app/patterns/. Define a regex or tree-sitter query matching your wrapper's method calls, and Codag will detect them immediately. The system is designed to be extensible without core modifications.
What's the performance impact on VSCode?
Minimal. The extension offloads all heavy parsing to the backend. VSCode only renders the D3.js graph and handles UI interactions. Initial graph load for 100 files takes ~2 seconds, with subsequent updates under 200ms. Memory usage stays under 100MB for typical projects.
Which languages are supported?
Python, TypeScript, JavaScript (including JSX/TSX), Go, Rust, Java, C, C++, Swift, and Lua. The tree-sitter parsers for these languages are bundled with the extension. Adding new languages requires adding the tree-sitter grammar and defining pattern queries—typically a 30-minute task for contributors.
How do I add support for a new LLM provider?
Edit backend/app/patterns/providers.py and add an entry:
"new_provider": {
"languages": ["python", "javascript"],
"pattern": "new_provider\\.generate\\(",
"framework": False
}
Submit a PR—the maintainer actively merges provider additions within days.
Is Codag free to use?
Yes, Codag is MIT-licensed and completely free. The only cost is your Gemini API key usage, which is minimal (the free tier handles thousands of analyses). The backend can be self-hosted, eliminating any external dependencies if desired.
Conclusion: Why Codag Belongs in Every AI Developer's Toolkit
Codag solves a problem that didn't exist three years ago but now plagues nearly every AI engineering team: the invisibility of LLM workflow complexity. As we graduate from simple API calls to sophisticated agentic systems, our tools must evolve. Traditional debuggers and static analysis can't capture the dynamic, data-driven nature of AI pipelines. Codag's hybrid approach—combining the speed of tree-sitter with the intelligence of LLMs—creates a new category of development tool: the AI workflow visualizer.
What impresses most is the attention to developer experience. The instant updates, click-to-source navigation, and MCP integration aren't afterthoughts—they're core design principles. Michael Zhou has built something that feels native to VSCode while solving problems that are native to AI development.
If you're building with LLMs, whether it's a side project chatbot or a production multi-agent system, install Codag today. The 5-minute setup will save you hours of debugging within the first week. The repository is actively maintained, the community is growing, and the roadmap promises even more powerful features like git diff visualization and hosted backends.
Ready to see your AI code flow? Head to the Codag GitHub repository, give it a ⭐ to support the project, and transform how you understand AI workflows forever.
Comments (0)
No comments yet. Be the first to share your thoughts!