Installing Cody for JetBrains

Learn how to use Cody and its features with JetBrains editors.

The Cody plugin by Sourcegraph enhances your coding experience in your IDE by providing intelligent code suggestions, context-aware completions, and advanced code analysis. This guide will walk you through the steps to install and set up Cody within your JetBrains environment.

Cody for JetBrains

JetBrains Extension

Install Cody's free extension for JetBrains.

Prerequisites

Install the JetBrains Cody plugin

Follow these steps to install the Cody plugin:

  • Open a supported JetBrains editor on your local machine
  • Open Settings (macOS: ⌘+, Windows: Ctrl+Alt+S) and select Plugins
  • Search for Cody: AI Coding Assistant with Autocomplete & Chat in the marketplace and click Install

cody-for-intellij

Alternatively, you can also download and install the plugin from the JetBrains marketplace directly.

Connect the plugin to Sourcegraph

After a successful installation, the Cody icon appears in the Tool Windows Bar.

Cody Free or Cody Pro Users

Cody Free and Pro users can sign in to their Sourcegraph.com accounts using SSO through GitHub, GitLab, or Google.

cody-for-intellij-login

Sourcegraph Enterprise Cody Users

Sourcegraph Enterprise users should connect Cody to their Enterprise instance by clicking Sign in with an Enterprise Instance.

To connect the plugin with your Enterprise instance,

  • Click Sign in with an Enterprise Instance
  • Enter the URL of your Enterprise instance. If you are unsure, please get in touch with your administrator
  • Select Authorize in Browser. You'll be directed to an authorization page on your instance in the browser

Alternatively, you can access advanced authorization settings by clicking Show Advanced. You can manually enter a token generated from your User Settings in your Sourcegraph Enterprise instance or add optional custom request headers.

Verifying the installation

Once connected, click the Cody icon from the sidebar again. The Cody plugin will open in a configurable side panel.

Let's create an autocomplete suggestion to verify that the Cody plugin has been installed and works as expected.

Cody provides intelligent code suggestions and context-aware autocompletion for numerous programming languages, such as JavaScript, Python, TypeScript, Go, etc.

  • Create a new file in your JetBrains IDE, for example, code.js
  • Next, type the following algorithm function to sort an array of numbers
JS
function bubbleSort(array){ }
  • As you start typing, Cody will automatically provide suggestions and context-aware completions based on your coding patterns and the code context
  • These autocomplete suggestions appear as grayed text. To accept the suggestion, press the Tab key

Chat

Cody chat in JetBrains is available in a unified interface that opens right next to your code. Once connected to Sourcegraph, a new chat input field opens with the default @-mention context chips.

All your previous and existing chats are stored for later use and can be accessed via the History icon from the top menu. You can download them to share or use later in a .json file or delete them.

Chat interface

The chat interface is designed intuitively. Your very first chat input lives at the top of the panel, and the first message in any chat log will stay pinned to the top of the chat. After your first message, the chat input window moves to the bottom of the sidebar.

Since your first message to Cody anchors the conversation, you can return to the top chat box anytime, edit your prompt, or rerun it using a different LLM model.

chat-interface

Users must be on JetBrains v2023.2 and Cody plugin v7.0.0 or above to get the new and improved chat UI.

Chat History

A chat history icon at the top of your chat input window allows you to navigate between chats (and search chats) without opening the Cody sidebar.

Changing LLM model for chat

You need to be a Cody Free or Pro user to have multi-model selection capability. You can view which LLMs you can access on our supported LLMs page. Enterprise users with the new model configuration can use the LLM selection dropdown to choose a chat model.

For Chat:

  • Open chat or toggle between editor and chat
  • Click on the model selector (which by default indicates Claude 3.5 Sonnet)
  • See the selection of models and click the model you desire. This model will now be the default model for any new chats

For Edit:

  • On any file, select some code and right-click
  • Select Cody > Edit Code (optionally, you can do this with Opt+K/Alt+K)
  • Select the default model available
  • See the selection of models and click the model you desire. This model will now be the default model for any new edits

Selecting Context with @-mentions

Cody's chat allows you to add files as context in your messages.

  • Type @-file and then a filename to include a file as a context.

The @-file also supports line numbers to query the context of large files. You can add ranges of large files to your context by @-mentioning a large file and appending a number range to the filename, for example, @filepath/filename:1-10.

When you @-mention files to add to Cody’s context window, the file lookup takes files.exclude, search.exclude, and .gitgnore files into account. This makes the file search faster as a result up to 100ms.

Moreover, when you @-mention files, Cody will track the number of characters in those files against the context window limit of the selected chat model. As you @-mention multiple files, Cody will calculate how many tokens of the context window remain. When the remaining context window size becomes too small, you'll receive File too large errors when attempting to @-mention additional files.

You can read more about context limits when selecting context here.

Context retrieval

When you start a new Cody chat, the input window opens with default @-mention context chips for all the context it intends to use. This context is based on your current repository and current file (or a file selection if you have code highlighted).

jb-context-retrieval

At any point in time, you can edit these context chips, add additional context chips, or remove them completely if you do not want to use these as context. Any chat without a context chip will instruct Cody to use no codebase context. However, you can always provide an alternate @-mention file to let Cody use it as a new context source.

When you have both a repository and files @-mentioned, Cody will search the repository for context while prioritizing the mentioned files.

Rerun prompts with different context

If Cody's answer isn't helpful, you can try asking again with a different context:

  • Public knowledge only: Cody will not use your code files as context; it’ll only use knowledge trained into the base model.
  • Current file only: Rerun the prompt using just the current file as context.
  • Add context: Provides @-mention context options to improve the response by explicitly including files, remote repositories, or web pages (URL).

jb-rerun-context

Context fetching mechanism

JetBrains users on the Free or Pro plan use local context.

Enterprise users can leverage the full power of the Sourcegraph search engine as Cody's primary context provider.

Read more about Context fetching mechanisms in detail.

Context sources

You can @-mention files and web pages in Cody. Cody Enterprise also supports @-mentioning repositories to search for context in a broader scope.

Cody Free and Pro offer single-repo context, and Cody Enterprise supports multi-repo context.

Cody Context Filters

Context Filters is available for all Cody Enterprise users running Cody JetBrains plugin version >=6.0.0.

Admins on the Sourcegraph Enterprise instance can use Cody Context Filters to determine which repositories Cody can use as the context in its requests to third-party LLMs. Inside your site configuration, you can define a set of include and exclude rules that will be used to filter the list of repositories Cody can access.

For repos mentioned in the exclude field, Cody prompts are disabled, and you cannot use them for context fetching. If you try running any of these, you'll be prompted with an error message. However, Cody chat will still work, and you can use it to ask questions.

Read more about Cody Context Filters here →

Autocomplete

Cody provides multi-line autocomplete as you type. Autocomplete suggestions appear as inlay suggestions and are enabled by default in your JetBrains IDE. This setting lists the programming languages supported and enabled by default.

To manually configure the Autocomplete feature,

  • Go to the Cody Settings... from the Cody icon in the sidebar
  • Next, click the Sourcegraph & Cody dropdown and select Cody
  • The Autocomplete settings will appear with the list of Enabled Languages

Autocomplete suggestions use the same color as inline parameter hints according to your configured editor theme. However, you can optionally enable the Custom color for completions checkbox to customize the color of your choice.

In addition, you can use the following keyboard shortcuts to interact with Cody's autocomplete suggestions:

  • Tab to accept a suggestion
  • Alt + [ (Windows) or Opt + [ (macOS) to cycle suggestions
  • Alt + \ (Windows) or Opt + \ (macOS) to manually trigger autocomplete if no suggestions have been returned

Prompts

Cody allows you create quick, ready-to-use prompts to automate key tasks in your workflow. Prompts are created and saved in the Prompt Library and can be accessed from the Tools > Prompt Library in the top navigation bar in your Sourcegraph instance.

To help you get started, there are a few prompts that are available by default. These can assist you to:

  • Document code
  • Explain code
  • Detect code smells
  • Generate unit tests

jb-default-prompts

Inline code edits

You can directly perform inline edits on your code without opening the chat window.

  • Select the code you want to edit
  • Then right-click and select Cody > Edit Code
  • Alternatively, you can press Opt+K (macOS) or Alt+K (Windows) to open the inline editor

Here, you can describe the change you want to make and select the LLM model you want to use.

Once you enter your prompt, Cody will perform inline edits that you can Accept, Undo, or Show diff for the change. Click Edit & Retry to iterate your prompt and get alternate suggestions.

jb-inline-code-edit

Inline code fix

Cody with JetBrains can also propose fixes and updates to errors in your code. The inline Ask Cody to Fix functionality alerts a user when it notices an issue. It provides a workflow to suggest a fix, review the suggestion, and accept the change, all within the editor.

All you need to do is select and highlight the code line with the error and click the lightbulb icon. Then select Ask Cody to Fix. You can then view the diff and accept or undo the suggested change.

Updating the plugin

JetBrains IDEs will typically notify you when updates are available for installed plugins. Follow the prompts to update the Cody AI plugin to the latest version.

Change the update channel for stable or nightly releases

Our nightly release channel gets updated much more frequently, which might help verify bug fixes that will be included in the next stable release. To update your update channel, you can do the following:

  1. Open your JetBrains IDE settings by selecting IDE Name | Settings on macOS or File | Settings on Windows and Linux from the main menu.
  2. Get to the Cody Settings by navigating to Tools -> Sourcegraph & Cody
  3. Under the update channel, select Stable or Nightly

Supported LLM models

Cody Free and Pro users can choose from a list of supported LLM models for chat.

llm-selection-cody

Enterprise users who have model configuration configured can also select from the available models for their instance. On instances with the "completions" configuration, a site admin determines the LLM, which cannot be changed within the editor.

Read and learn more about the supported LLMs and token limits on Cody Free, Pro and Enterprise.

Add/remove account

To add or remove an account, you can do the following:

  1. Open Cody by clicking the Cody icon on the toolbar
  2. On the open sidebar, select the Account icon
  3. Select Sign Out to remove an account

Alternatively, you can also manage multiple accounts in Cody Settings:

  1. Open your IDE settings by selecting IDE | Settings on macOS or File | Settings on Windows and Linux from the main menu.
  2. Go to the Cody Settings by navigating to Tools -> Sourcegraph & Cody
  3. Under authentication, see the accounts that are currently logged in
  4. To remove, select your account and hit -. To add click + and choose the appropriate login method

Find Cody features

You can find and discover all Cody features and actions using the Search Everywhere option in JetBrains IDEs. Press Shift twice to open the Search Everywhere window. Then, type in the Cody: prefix to get a list of all supported Cody actions.

search-everywhere

Previous
Cody for VS Code