Sourcegraph Cody | AI Coding Assistant Setup Guide
Sourcegraph Cody - AI Coding Assistant
Cody is Sourcegraph’s AI coding assistant that leverages code intelligence to provide context-aware suggestions, code generation, and refactoring across your entire codebase.
Overview
Cody stands out with:
- Code intelligence - Deep understanding from Sourcegraph’s code graph
- Entire codebase context - Knows your whole repository, not just open files
- Codebase-wide search - Finds relevant code across your project
- Auto-completion | AI-powered code suggestions
Key Features
| Feature | Description |
|---|---|
| Code Graph | Understands code relationships and dependencies |
| Codebase Search | Find relevant code across your entire project |
| Smart Apply | Applies changes with awareness of code structure |
| Recipes | Pre-built prompts for common tasks |
| Enterprise Features | SSO, audit logs, custom model hosting |
Installation
VSCode
- Open Extensions marketplace
- Search “Sourcegraph Cody”
- Install
JetBrains
- Settings > Plugins > Marketplace
- Search “Cody”
- Install and restart
Neovim
-- Using lazy.nvim{ 'sourcegraph/cody', config = function() require('cody').setup() end}CLI
npm install -g @sourcegraph/codyConfiguration
Account Setup
- Sign up at sourcegraph.com
- Generate access token
- Add to VSCode settings or environment:
export SRC_ACCESS_TOKEN="sgp_..."VSCode Settings (settings.json)
{ "cody.serverEndpoint": "https://sourcegraph.com", "cody.accessToken": "${SRC_ACCESS_TOKEN}", "cody.autocomplete.enabled": true, "cody.autocomplete.triggerDelay": 100, "cody.chat.preInstruction": "Always use TypeScript strict mode"}Config File (~/.cody/config.json)
{ "serverEndpoint": "https://sourcegraph.com", "accessToken": "${SRC_ACCESS_TOKEN}", "autocomplete": { "enabled": true, "triggerDelay": 100 }, "chat": { "preInstruction": "", "defaultModel": "claude-3-sonnet-20240229" }, "recipes": { "enabled": true }}Usage
Keyboard Shortcuts
| Action | Shortcut |
|---|---|
| Open chat | Cmd/Ctrl+Shift+C |
| Autocomplete | Automatic |
| Run recipe | Cmd/Ctrl+Shift+Enter |
| Accept suggestion | Tab |
Chat Interface
Ask questions about your code:
- “What does this function do?”
- “Find all usages of this method”
- “Explain this error”
- “How is this component used?”
Recipes
Pre-built commands for common tasks:
| Recipe | Description |
|---|---|
Explain Code | Explains selected code |
Generate Unit Tests | Creates test cases |
Generate Docstring | Adds documentation |
Smell Code | Finds code smells |
Translate to Different Language | Converts code |
Improve Variable Names | Refactors naming |
Custom Recipes
Create your own in .cody/recipes.json:
{ "recipes": [ { "id": "add-logging", "title": "Add Logging", "prompt": "Add appropriate logging statements to this code" } ]}Provider Configuration
Sourcegraph Cloud (Default)
Uses Sourcegraph’s hosted models:
{ "serverEndpoint": "https://sourcegraph.com", "accessToken": "sgp_..."}Self-hosted Sourcegraph
{ "serverEndpoint": "https://sourcegraph.company.com", "accessToken": "sgp_..."}Custom LLM (Enterprise)
{ "completions": { "provider": "anthropic", "model": "claude-3-sonnet-20240229", "apiKey": "${ANTHROPIC_API_KEY}" }}Enterprise Features
Self-hosted Deployment
Host Cody on your infrastructure:
- Full data control
- Custom model hosting
- SSO integration
- Audit logging
Custom Models
Connect to your own LLM endpoints:
- OpenAI-compatible APIs
- Azure OpenAI
- Anthropic Claude
- Local models via vLLM
Security
- SAML/SSO authentication
- Audit logs for all actions
- Data residency options
- VPC deployment
Code Intelligence
Code Graph
Cody understands:
- Function definitions and calls
- Type hierarchies
- Import relationships
- Symbol references
Codebase Search
Find code across your entire project:
- Semantic search (natural language)
- Symbol search
- Cross-repository search (with Sourcegraph)
Context Window
Unlike other agents limited to open files, Cody can:
- Search entire codebase
- Include relevant files automatically
- Reference documentation
Common Workflows
Understanding Code
User: "What does this service do?"Cody: Searches codebase, finds service definition, explainsRefactoring
User: "Rename this function across the codebase"Cody: Finds all references, applies changesAdding Features
User: "Add pagination to this API endpoint"Cody: Finds API code, implements pagination patternDebugging
User: "Why is this test failing?"Cody: Analyzes test, finds related code, suggests fixPricing
| Plan | Price | Features |
|---|---|---|
| Free | $0 | 500 autocomplete + 20 chat requests/month |
| Pro | $9/mo | Unlimited autocomplete + 500 chat requests/month |
| Enterprise | Custom | Unlimited + SSO + audit logs + custom models |
Troubleshooting
”Authentication failed”
- Verify access token: Check at sourcegraph.com/user/settings/tokens
- Check server endpoint URL
- Regenerate token if needed
”No context found”
- Ensure code is indexed by Sourcegraph
- Check file is in git repository
- Verify repository is public or you have access
Autocomplete not working
- Check “cody.autocomplete.enabled” setting
- Verify you’re in a supported language
- Try restarting VSCode
Slow responses
- Check your plan’s rate limits
- Switch to faster model in settings
- Reduce codebase size context
Comparison
| Feature | Cody | Copilot | Cursor | Continue |
|---|---|---|---|---|
| Codebase context | ✅ | ⚠️ | ⚠️ | ❌ |
| Code graph | ✅ | ❌ | ❌ | ❌ |
| Self-hosted | ✅ | ❌ | ❌ | Partial |
| Open source | Partial | ❌ | ❌ | ✅ |
| Price | $9/mo | $10/mo | $20/mo | Free |
Best Practices
- Index your repos - Connect Sourcegraph for full codebase understanding
- Use recipes - Leverage pre-built prompts for common tasks
- Ask specific questions - Clear queries get better results
- Review suggestions - Always verify generated code
- Set up enterprise - For teams, use SSO and audit features