Chat
Use Cody's chat to get contextually-aware answers to your questions.
You can chat with Cody to ask questions about your code, generate code, and edit code. By default, Cody has the context of your open file and entire repository, and you can use @
to add context for specific files, symbols, remote repositories, or other non-code artifacts.
You can do it from the chat panel of the supported editor extensions (VS Code, JetBrains, Visual Studio, Eclispe) or in the web app.
Prerequisites
To use Cody's chat, you'll need the following:
- A Free or Pro account via Sourcegraph.com or a Sourcegraph Enterprise account
- A supported editor extension (VS Code, JetBrains, Visual Studio) installed
How does chat work?
Cody answers questions by searching your codebase and retrieving context relevant to your questions. Cody uses several methods to search for context, including Sourcegraph's native search and keyword search. Finding and using context allows Cody to make informed responses based on your code rather than being limited to general knowledge. When Cody retrieves context to answer a question, it will tell you which code files it reads to generate its response.
Cody can assist you with various use cases, such as:
- Generating an API call: Cody can analyze your API schema to provide context for the code it generates
- Locating a specific component in your codebase: Cody can identify and describe the files where a particular component is defined
- Handling questions that involve multiple files, like understanding data population in a React app: Cody can locate React component definitions, helping you understand how data is passed and where it originates
Chat features
There are several features that you can use to make your chat experience better. These features may vary depending on the client you are using. You can learn more about the support for these functionalities in the feature parity reference.
Default context
When you start a new Cody chat, the input window opens with a default @-mention
context chips for the opened file and the current repository.
At any point in time, you can edit these context chips or remove them entirely 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 or symbols 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.
Add new context
You can add new custom context by adding @-mention
context chips to the chat. At any point, you can use @-mention
a repository, file, line range, or symbol, to ask questions about your codebase. Cody will use this new context to generate contextually relevant code.
OpenCtx context providers
OpenCtx is an open standard for bringing contextual info about code into your dev tools. Cody Free and Pro users can use OpenCtx providers to fetch and use context from the following sources:
You can use @-mention
web URLs to pull live information like docs. You can connect Cody to OpenCtx to @-mention
non-code artifacts like Google Docs, Notion pages, Jira tickets, and Linear issues.
Run offline
Cody chat can run offline with Ollama. The offline mode does not require you to sign in with your Sourcegraph account to use Ollama. Click the button below the Ollama logo, and you'll be ready to go.
You can still switch to your Sourcegraph account whenever you want to use Claude, OpenAI, Gemini, Mixtral, etc.
LLM selection
Cody allows you to select the LLM you want to use for your chat, optimized for speed versus accuracy. Cody Free and Pro users can select multiple models. Enterprise users with the new model configuration can use the LLM selection dropdown to choose a chat model.
You can read about these supported LLM models here.
Smart Apply and Execute code suggestions
Cody lets you dynamically insert code from chat into your files with Smart Apply. Whenever Cody provides a code suggestion, you can click the Apply button. Cody will then analyze your open code file, find where that relevant code should live, and add a diff. For chat messages where Cody provides multiple code suggestions, you can apply each in sequence to go from chat suggestions to written code.
Smart Apply also supports the executing of commands in the terminal. When you ask Cody a question related to terminal commands, you can now execute the suggestion in your terminal by clicking the Execute
button in the chat window.
Chat history
Cody keeps a history of your chat sessions. You can view it by clicking the History button in the chat panel. You can Export it to a JSON file for later use or click the Delete all button to clear the chat history.
Prompts
Cody offers quick, ready-to-use prompts for common actions to write, describe, fix, and smell code. Read more about prompts here.
Ask Cody to write code
Cody chat can also write code for your questions. For example, in VS Code, ask Cody to "write a function that sorts an array in ascending order".
You are provided with code suggestions in the chat window and the following options for using the code.
- The Copy Code icon to your clipboard and paste the code suggestion into your code editor
- Insert the code suggestion at the current cursor location by the Insert Code at Cursor icon
- The Save Code to New File icon to save the code suggestion to a new file in your project
If Cody's answer isn't helpful, you can try asking again with a different context:
- Public knowledge only: Cody will not use your own code files as context; it’ll only use knowledge trained into the base model.
- Current file only: Re-run the prompt again using just the current file as context.
- Add context: Provides @-mention context options to improve the response by explicitly including files, symbols, remote repositories, or even web pages (by URL).