Cody Complete Guide: From Beginner to Expert
A comprehensive guide to Cody, Sourcegraph's AI coding assistant with full-repo context awareness for code generation, refactoring, and auto-fixing.
Overview
Cody is an advanced AI-powered coding assistant developed by Sourcegraph, a leader in code search and intelligence. Unlike traditional code completion tools that operate on a file-by-file basis, Cody leverages Sourcegraph’s powerful code graph technology to understand the full context of your entire codebase. This enables it to deliver highly accurate suggestions, refactorings, fixes, and new code generation based on real project semantics — not just syntax patterns.
Whether you're debugging a complex issue, modernizing legacy systems, or accelerating feature development, Cody integrates directly into your existing workflow via popular IDEs like Visual Studio Code, JetBrains (IntelliJ, PyCharm, etc.), and even through the web interface on Sourcegraph. It excels in environments where deep understanding of dependencies, function calls, and cross-file relationships matters — making it especially valuable for large-scale, team-based software projects. With support for both public and private repositories, including self-hosted instances, Cody ensures secure, privacy-preserving assistance without sending sensitive code to third-party LLM providers unless explicitly enabled.
Core Features
Cody stands out from other AI coding assistants due to its unique integration with Sourcegraph’s semantic code graph. Below are its core capabilities:
| Feature | Description | Availability | Supported Context |
|---|---|---|---|
| Full-Repository Context Understanding | Uses Sourcegraph's code graph to analyze relationships across files, functions, and modules for precise AI responses | Free & Pro tiers | Public and private repos (with proper access) |
| AI-Powered Code Generation | Generates new functions, tests, or boilerplate code using natural language prompts | Free & Pro | Based on current file + relevant repo context |
| Smart Code Refactoring | Suggests and executes safe refactorings (e.g., renaming, extracting methods, updating APIs) with impact analysis | Pro tier only | Cross-file changes with dependency tracking |
| Auto-Fix Suggestions | Detects errors in code and proposes targeted fixes using contextual understanding of the codebase | Pro tier only | Integrated with editor diagnostics |
| Natural Language Chat (Cody Chat) | Ask questions about your codebase in plain English ("How do I use this API?", "Why is this failing?") | Free & Pro | Answers grounded in actual code |
| Command Runner (Custom Workflows) | Run predefined or custom commands like “Explain this,” “Generate test,” or “Find usages” with one click | Pro tier only | Editor-integrated shortcuts |
| Local & Remote LLM Support | Choose between fast local models or powerful remote LLMs (e.g., Anthropic, OpenAI) — optional code upload | Configurable | Privacy mode keeps all code local |
| Self-Hostable with Sourcegraph Enterprise | Deploy Cody alongside on-prem Sourcegraph for complete data control | Enterprise plans | Ideal for regulated industries |
These features make Cody more than just a chatbot or autocomplete tool — it's a context-aware programming agent capable of reasoning over real code structures.
How to Use
Using Cody effectively involves several steps: setup, authentication, configuration, and interaction. Follow this step-by-step guide to get started and unlock expert-level usage.
Step 1: Install the Cody Extension
Cody supports multiple IDEs. The most common setups are:
- Visual Studio Code: Open Extensions Marketplace → Search “Cody” → Install “Cody by Sourcegraph”
- JetBrains IDEs (IntelliJ, GoLand, WebStorm, etc.): Go to Preferences → Plugins → Marketplace → Search “Cody” → Install
After installation, restart your IDE.
🔧 Tip: Ensure you have at least VS Code v1.85+ or JetBrains 2023.3+ for full compatibility.
Step 2: Sign In and Connect to Sourcegraph
Launch Cody from the sidebar or command palette (Cmd+Shift+P or Ctrl+Shift+P) and select "Sign In."
You can connect to:
- Sourcegraph.com (free public instance)
- A self-hosted Sourcegraph instance (for enterprise users)
If using a private server, enter the URL when prompted. Authentication uses OAuth or access tokens.
🔐 Security Note: Your code never leaves your machine unless you enable remote LLM processing. You can choose to run everything locally using lightweight models.
Step 3: Grant Repository Access
Cody needs permission to index your codebase. When opening a project:
- Cody will prompt: “Index this repository?”
- Confirm to allow parsing of files for symbol lookup and context building.
- For large repos, indexing may take a few minutes (runs in background).
Once indexed, Cody can answer questions like:
- “Show me all services that call
authenticateUser()” - “What does this config file do?”
- “Generate a unit test for this function”
Step 4: Interact with Cody
Option A: Cody Chat (Natural Language Queries)
Open the Cody panel and type any query:
Explain how the payment processor works in this app.
Cody will:
- Analyze relevant files
- Trace function flows
- Return a concise explanation with links to source
Useful prompts:
- “Help me fix the error in this file”
- “Convert this class to TypeScript”
- “Suggest improvements to this function”
Option B: Inline AI Actions
Highlight code and right-click → "Ask Cody" or use shortcut (Alt+L):
- Explain Selection
- Generate Unit Test
- Fix This Code
- Improve Readability
The assistant generates output directly in the editor.
Option C: Use Predefined Commands
Access the Cody command menu (Cmd+Shift+P → "Cody: Run Command") and choose:
| Command | What It Does |
|---|---|
/test |
Generate test cases for selected code |
/doc |
Add documentation/comments |
/smell |
Identify potential code quality issues |
/edit |
Rewrite code with optimization/refactor suggestions |
/ask |
Open chat focused on current file |
Pro users can create custom commands using templates with variables like ${selection} or ${fileName}.
Step 5: Configure LLM Settings (Advanced)
Go to Settings → Cody → Model Provider to choose:
- Local Models (via Ollama, Hugging Face): Best for privacy; slower but secure
- Remote Models: Faster, smarter (uses Claude 3, GPT-4-turbo), requires opt-in for code sharing
Set default model per task (e.g., use GPT-4 for generation, local model for explanations).
Enable Automatic Context Retrieval to let Cody pull in related files automatically during chats.
🛡️ Enterprise Tip: In regulated environments, disable remote models entirely and use Sourcegraph’s air-gapped deployment.
Pricing
Cody operates on a freemium model, offering robust functionality for individual developers while unlocking team and enterprise capabilities in paid tiers.
| Plan | Cost | Key Features | Best For |
|---|---|---|---|
| Free | $0/month | - Cody Chat (basic) - Code completion (limited context) - Explain/test/generate commands - Local model support |
Individual devs, open-source contributors |
| Pro | $19/user/month (billed annually) or $24/month (monthly) | - Full-repo context AI - Smart refactoring & auto-fix - Custom commands - Priority LLM routing - Remote model access (Claude, GPT) |
Professional developers, startups |
| Enterprise | Contact sales (custom pricing) | - On-prem/self-hosted Cody + Sourcegraph - SSO/SAML integration - Audit logs - Private model hosting - SLA support |
Large organizations, financial/healthcare sectors |
💡 Note: The Free plan includes generous usage limits (up to 500 AI queries/month). Exceeding quota pauses non-critical features until reset.
Academic and open-source projects may qualify for discounts or free Pro licenses via Sourcegraph’s community program.
Use Cases
Cody shines in specific development scenarios where context and accuracy matter. Here are three ideal use cases:
1. Onboarding New Developers
Onboarding onto a large, undocumented codebase is notoriously difficult. With Cody, new engineers can:
- Ask natural language questions: “How do user permissions work?”
- Get instant answers backed by actual code references
- Explore call graphs and data flow without digging manually
This reduces ramp-up time from weeks to days and improves knowledge retention.
2. Legacy Code Modernization
Refactoring old systems (e.g., migrating from Python 2 to 3, React Class → Function components) is risky and time-consuming. Cody helps by:
- Identifying all affected files
- Proposing safe transformations
- Generating migration scripts
- Validating changes against usage patterns
With cross-repo awareness, Cody prevents breaking changes in dependent services.
3. Automated Test Generation & Bug Fixing
QA and reliability engineering benefit greatly from Cody’s automation:
- Highlight a function → Run
/test→ Get Jest/Mocha/Pytest-ready unit tests - Paste an error log → Ask “What could cause this?” → Receive root-cause hypotheses
- Enable auto-fix mode to suggest corrections for common anti-patterns
Teams report up to 40% reduction in manual testing effort when integrating Cody into CI workflows.
Additional niche uses:
- Documentation generation: Turn complex logic into clear comments
- Security audits: Flag insecure API usage (e.g.,
eval(), raw SQL) - API migration: Update deprecated library calls across microservices
Pros & Cons
✅ Pros
| Advantage | Explanation |
|---|---|
| Deep Code Context | Leverages Sourcegraph’s code graph for true semantic understanding beyond token prediction |
| Privacy-First Design | Optional local execution; no forced cloud uploads |
| Cross-File Intelligence | Understands dependencies and impacts across modules |
| IDE-Agnostic | Works seamlessly in VS Code, JetBrains, and web editors |
| Extensible via Commands | Power users can automate repetitive tasks with custom workflows |
| Supports Private Repos | Fully functional with internal monorepos and self-hosted GitLab/GitHub |
❌ Cons
| Limitation | Details |
|---|---|
| Steeper Learning Curve | Requires initial setup (indexing, auth) compared to simpler copilots |
| Resource Intensive | Indexing large repos can consume memory/CPU on developer machines |
| Limited Offline Functionality | While local models help, some features require Sourcegraph backend |
| Smaller Model Ecosystem | Fewer fine-tuned coding models vs. GitHub Copilot or Tabnine |
| Enterprise Cost | Self-hosted deployments require significant infrastructure investment |
Despite these drawbacks, Cody remains one of the most contextually intelligent AI coding assistants available today — particularly valuable in complex, collaborative environments.
Alternatives
While Cody offers unmatched context depth, several alternatives compete in the AI coding space:
| Tool | Key Differentiator | Best For | Comparison to Cody |
|---|---|---|---|
| GitHub Copilot | Deep integration with GitHub, powered by OpenAI | General-purpose autocompletion | Stronger in line-by-line suggestions, weaker in full-repo reasoning |
| Tabnine | Fully local AI coding assistant | Maximum privacy & offline use | Better for isolated file completions, lacks semantic graph insights |
| Amazon CodeWhisperer | AWS-native security scanning & cost-free tier | AWS-centric teams | Good for detecting license risks and generating Lambda functions, less flexible outside AWS ecosystem |
| Cursor.sh | AI-first editor with built-in agent mode | AI-native development workflows | More experimental; Cody wins in enterprise readiness and scalability |
Choose Cody if:
- You work in a large, interconnected codebase
- You need trustworthy, explainable AI outputs
- You value security and self-hosting options
Choose alternatives if:
- You want plug-and-play simplicity (Copilot)
- You require full offline operation (Tabnine)
- You’re deeply embedded in AWS (CodeWhisperer)
Disclaimer
This guide is independently written and not affiliated with Sourcegraph, Inc. Product details, pricing, and features are accurate as of May 2026 based on publicly available documentation and reviews. Cody is a registered product of Sourcegraph, Inc. Always refer to the official website for the latest updates, terms of service, and privacy policies. Use of AI coding tools should be accompanied by code review and testing practices to ensure correctness and security.