Enabling Cody on Sourcegraph Enterprise

Cody on self-hosted Sourcegraph Enterprise


  • Sourcegraph 5.0.1 or above
  • An Anthropic or OpenAI API key (we can help you get one, see below)
  • Optionally: An OpenAI API key for embeddings to power code graph context

There are two steps required to enable Cody on your enterprise instance:

  1. Enable your Sourcegraph instance
  2. Configure the VS Code extension

Step 1: Enable Cody on your Sourcegraph instance

Note that this requires site-admin privileges.

  1. Cody uses one or more third-party LLM (Large Language Model) providers. Make sure you review the Cody usage and privacy notice. In particular, code snippets will be sent to a third-party language model provider when you use the Cody extension.

  2. To turn Cody on, you will need to set an access token for Sourcegraph to authenticate with the third-party large language model provider. Currently, this can be Anthropic or OpenAI. Reach out to your Sourcegraph Technical Advisor or Customer Engineer to get an Anthropic key through Sourcegraph with our zero-retention policy. Alternatively, you can create your own key with Anthropic here or with OpenAI here.

  3. Once you have the key, go to Site admin > Site configuration (/site-admin/configuration) on your instance and set:

      // [...]
      "completions": {
        "enabled": true,
        "provider": "anthropic", // or "openai" if you use OpenAI
        "model": "claude-v1", // or one of the models listed [here](https://platform.openai.com/docs/models) if you use OpenAI
        "accessToken": "<key>"
  4. You're done!

  5. Cody can be configured to use embeddings for code graph context to significantly improve the quality of its responses. This involves sending your entire codebase to a third-party service to generate a low-dimensional semantic representation, that is used for improved context fetching. See the codebase-aware answers section for more.

Step 2: Configure the VS Code extension

Now that Cody is turned on on your Sourcegraph instance, any user can configure and use the Cody VS Code extension. This does not require admin privilege.

  1. If you currently have a previous version of Cody installed, uninstall it and reload VS Code before proceeding to the next steps.

  2. Search for “Sourcegraph Cody” in your VS Code extension marketplace, and install it.

    Sourcegraph Cody in VS Code Marketplace
  3. Reload VS Code, and open the Cody extension. Review and accept the terms.

  4. Now you'll need to point the Cody extension to your Sourcegraph instance. On your instance, go to settings / access token (https://<your-instance>.sourcegraph.com/users/<your-instance>/settings/tokens). Generate an access token, copy it, and set it in the Cody extension.

  5. In the Cody VS Code extension, set your instance URL and the access token

  6. See this section on how to enable codebase-aware answers.

You're all set!

Step 3: Try Cody!

These are a few things you can ask Cody:

  • "What are popular go libraries for building CLIs?"
  • Open your workspace, and ask "Do we have a React date picker component in this repository?"
  • Right click on a function, and ask Cody to explain it
  • Try any of the Cody recipes!

See more Cody use cases here.


Cody on Sourcegraph Cloud

On Sourcegraph Cloud, Cody is a managed service and you do not need to follow the step 1 of the self-hosted guide above.

Step 1: Enable Cody for your instance

Cody can be enabled on demand on your Sourcegraph instance by contacting your account manager. The Sourcegraph team will refer to the handbook.

Step 2: Configure the VS Code extension

See above.

Step 3: Try Cody!

See above.

Learn more about running Cody on Sourcegraph Cloud.

Enabling codebase-aware answers

Pre-requisite: In order to enable codebase-aware answers for Cody, you must first configure code graph context.

The Cody: Codebase setting in VS Code enables codebase-aware answers for the Cody extension. By setting this configuration option to the repository name on your Sourcegraph instance, Cody will be able to provide more accurate and relevant answers to your coding questions, based on the context of the codebase you are currently working in.

  1. Open the VS Code workspace settings by pressing Cmd/Ctrl+,, (or File > Preferences (Settings) on Windows & Linux).
  2. Search for the Cody: Codebase setting.
  3. Enter the repository name as listed on your Sourcegraph instance.
    1. For example: github.com/sourcegraph/sourcegraph without the https protocol

Turning Cody off

To turn Cody off, set embeddings and completions site-admin settings to enabled:false (or remove them altogether).

Turning Cody on, only for some users

To turn Cody on only for some users, for example when rolling out a Cody POC, follow all the steps in Step 1: Enable Cody on your Sourcegraph instance. Then use the feature flag cody-experimental to turn Cody on selectively for some users. To do so:

  1. Go to site-admin/feature-flags
  2. Add a feature flag called cody-experimental. Select the boolean type and set it to false.
  3. Once added, click on the feature flag and use add overrides to pick users that will have access to Cody.
Add overides