Skip to content

Sourcegraph Cody

Sourcegraph

An AI programming assistant from Sourcegraph, skilled at understanding large codebases.

Official Site
01

Overview

Cody is Sourcegraph's AI programming assistant, focused on understanding large codebases. Its core advantage is leveraging Sourcegraph's code search and indexing technology to understand the context of an entire codebase. Cody supports code completion, AI chat, commands, code search, and other features. Unlike ordinary AI assistants, Cody can answer questions about the entire codebase, such as 'where is this function called?'. It supports multiple LLM backends, including Claude, GPT-4, local models, and more.

02

Installation

Cody is installed via IDE plugins. It supports VS Code, JetBrains, Neovim, Emacs, and more. After installation, you need to log in to a Sourcegraph account (free version) or configure an enterprise instance.

bash
# VS Code installation
# 1. Open the extension store
# 2. Search for "Cody"
# 3. Click install
# 4. Restart VS Code
# 5. Log in to your Sourcegraph account

# JetBrains installation
# Settings -> Plugins -> Search for "Cody"
04

Autocomplete

Cody provides smart code completion, supporting single-line and multi-line completion. It provides suggestions based on codebase context, understanding project structure and patterns. Completion is fast with low latency. It supports completion for multiple languages.

bash
# Cody configuration
{
  "cody.autocomplete.enabled": true,
  "cody.autocomplete.languages": {
    "*": true,
    "python": true,
    "typescript": true
  },
  "cody.autocomplete.smartThrottle": true
}
05

Chat

Cody Chat provides a conversational AI assistant that can answer questions about the codebase. Chat understands the entire codebase context and can reference multiple files. It supports code generation, explanation, refactoring, debugging, and more. Chat history can be saved and searched.

bash
# Use Chat
# Shortcut: Alt+C

# Example conversations:
# "Explain what this function does"
# "What is the call chain of this API?"
# "Add error handling to this function"
# "Which places need to be modified to support the new requirement?"
06

Commands

Cody provides predefined commands to quickly perform common operations, such as explaining code, generating tests, fixing bugs, generating documentation, and more. Custom commands are also supported. Commands can be executed against selected code or the current file.

bash
# Built-in commands
# /explain - explain code
# /test - generate tests
# /smell - detect code smells
# /doc - generate documentation

# Custom commands
# .vscode/cody.json
{
  "commands": {
    "refactor": {
      "description": "Refactor the selected code",
      "prompt": "Refactor the following code to improve readability: {selection}"
    }
  }
}
07

Context

Cody's core advantage is context understanding. It can use the entire codebase as context to provide accurate answers. It supports multiple context sources: current file, open files, search results, custom context, and more. You can manually add or remove context files.

bash
# Context configuration
{
  "cody.context": {
    "currentFile": true,
    "openTabs": true,
    "searchResults": true,
    "customPatterns": [
      "**/*.ts",
      "**/*.tsx"
    ]
  }
}
08

Enterprise

Cody Enterprise connects to a Sourcegraph instance, providing enterprise-grade code understanding capabilities. It supports private codebases, SSO, audit logs, access control, and more. The enterprise version can leverage Sourcegraph's code graph to provide deeper code understanding. It is suitable for large enterprises.

bash
# Enterprise configuration
{
  "cody.serverEndpoint": "https://sourcegraph.company.com",
  "cody.enterprise": true,
  "cody.codebase": "github.com/company/repo"
}
09

Configuration

Cody provides rich configuration options. You can choose the LLM backend (Claude, GPT-4, local models), adjust completion behavior, configure context, and more. Project-level configuration is supported.

bash
# Full configuration example
{
  "cody.autocomplete.enabled": true,
  "cody.chat.model": "claude-3-5-sonnet",
  "cody.autocomplete.model": "starcoder-2",
  "cody.context.currentFile": true,
  "cody.telemetry": "off"
}

Ready to try Sourcegraph Cody?

Visit the official site for the latest version and full documentation.

Visit Sourcegraph Cody