Skip to content

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

FeatureDescription
Code GraphUnderstands code relationships and dependencies
Codebase SearchFind relevant code across your entire project
Smart ApplyApplies changes with awareness of code structure
RecipesPre-built prompts for common tasks
Enterprise FeaturesSSO, audit logs, custom model hosting

Installation

VSCode

  1. Open Extensions marketplace
  2. Search “Sourcegraph Cody”
  3. Install

JetBrains

  1. Settings > Plugins > Marketplace
  2. Search “Cody”
  3. Install and restart

Neovim

-- Using lazy.nvim
{
'sourcegraph/cody',
config = function()
require('cody').setup()
end
}

CLI

Terminal window
npm install -g @sourcegraph/cody

Configuration

Account Setup

  1. Sign up at sourcegraph.com
  2. Generate access token
  3. Add to VSCode settings or environment:
Terminal window
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

ActionShortcut
Open chatCmd/Ctrl+Shift+C
AutocompleteAutomatic
Run recipeCmd/Ctrl+Shift+Enter
Accept suggestionTab

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:

RecipeDescription
Explain CodeExplains selected code
Generate Unit TestsCreates test cases
Generate DocstringAdds documentation
Smell CodeFinds code smells
Translate to Different LanguageConverts code
Improve Variable NamesRefactors 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

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, explains

Refactoring

User: "Rename this function across the codebase"
Cody: Finds all references, applies changes

Adding Features

User: "Add pagination to this API endpoint"
Cody: Finds API code, implements pagination pattern

Debugging

User: "Why is this test failing?"
Cody: Analyzes test, finds related code, suggests fix

Pricing

PlanPriceFeatures
Free$0500 autocomplete + 20 chat requests/month
Pro$9/moUnlimited autocomplete + 500 chat requests/month
EnterpriseCustomUnlimited + 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

FeatureCodyCopilotCursorContinue
Codebase context⚠️⚠️
Code graph
Self-hostedPartial
Open sourcePartial
Price$9/mo$10/mo$20/moFree

Best Practices

  1. Index your repos - Connect Sourcegraph for full codebase understanding
  2. Use recipes - Leverage pre-built prompts for common tasks
  3. Ask specific questions - Clear queries get better results
  4. Review suggestions - Always verify generated code
  5. Set up enterprise - For teams, use SSO and audit features

Resources