Prerequisites
- VS Code installed (latest stable version)
- A Sourcegraph Enterprise account with Cody enabled
- A project open in VS Code
Install and connect Cody
Install the Cody extension
Cmd+Shift+X (macOS) or Ctrl+Shift+X (Windows/Linux) to open the Extensions panel.Search for Cody AI and click Install.Alternatively, install it directly from the VS Code Marketplace.After installation, VS Code may prompt you to reload the window to activate the extension.Sign in to your Sourcegraph instance
Generate an access token
- In your Sourcegraph instance, go to Account Settings > Access Tokens
- Click + Generate new token, give it a name, and click Generate
- Copy the token
- Back in VS Code, click Sign In to Your Enterprise Instance, choose Sign In to Sourcegraph Instances v5.1 and above, and paste your token when prompted
Verify the connection
code.js and type:Tab to accept it.Use chat
Chat is the most direct way to interact with Cody. Open the Cody sidebar and type a question in the input field at the top of the panel.Ask a question about your code
- “What does this file do?”
- “Explain this codebase in three to four lines”
- “Are there any performance issues in this code?”
Add more context with @-mentions
@ in the chat input to open the context picker. You can add:@filename— include a specific file@#symbolName— include a function, class, or type definition@filepath:1-50— include a specific line range
Apply a code suggestion
- Click the Copy icon to copy the code to your clipboard
- Click Insert at cursor to insert the code at your current cursor position
- Click Apply to use Smart Apply — Cody will analyze your open file, find the right location, and insert a diff for you to review
Use autocomplete
Cody provides real-time inline code suggestions as you type.Start typing in any file
Accept or dismiss suggestions
- Press
Tabto accept the full suggestion - Press
Escto dismiss it - Continue typing to refine the suggestion
Refactor code with inline edit
You can request code edits inline without opening the chat panel.Select the code you want to change
Open the inline edit input
Opt+K (macOS) or Alt+K (Windows/Linux) to open the Edit Code input field above the selection.Describe the change
Enter. Cody generates a diff in seconds.Review and accept
Debug code
Cody can identify and fix errors directly in your editor.Notice an error in your code
Ask Cody to fix it
Accept or reject the fix
Use prompts
Prompts are pre-built or custom templates that automate common tasks.Open the prompts list
- document-code — Generate inline documentation for a function or class
- explain-code — Get a plain-language explanation of selected code
- find-code-smells — Identify potential issues or anti-patterns
- generate-unit-tests — Generate unit tests for a function
Run a prompt
document-code), Cody applies the result directly to your file.Create a custom prompt