Prompts and Commands
Learn how prompts and commands can kick-start your workflow with Cody.
Prompts
Cody offers 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 Sourcegraph's web UI.
From here, you can easily create, edit, share, and discover prompts you’ve created or have been shared within your organization. You can also search for prompts, filter the list to find a specific prompt by owner, and sort by name or recently updated.
Create and edit a prompt
Click the New prompt button on the Prompt Library page to create a new prompt.
- Select the Owner and Prompt Name
- Next, write a prompt description
- Finally, fill out the Prompt template box with all your prompt instructions
- You can also add dynamic context that will allow your prompt to use content from different sources like current selection and current file
- Select the visibility of the prompt, either Public or Private
- Once done, click the Create prompt button
A few advanced options exist to create a prompt that you can configure. They are in the Advanced section.
The prompt is visible to and usable by:
- The prompt's owner: If the prompt's owner is a user
- All members of the organization: If the prompt's owner is an organization
- Everyone: If the prompt is marked Public (which only site admins can do)
Completing this process will do the following:
- The new prompt will be added to the Prompt Library page
- The prompt will appear in the Prompts list in the Cody chat panel (in the editor and on the web)
Draft prompts
You can mark your prompt as a draft. A draft prompt is not visible to everyone. You can only see and modify your draft prompts via the Prompt Library via the Sourcegraph's Web UI.
Editing a prompt
To edit a prompt, click the Edit button next to the prompt in the Prompt Library and make the necessary changes. You can also use this interface to transfer ownership of the prompt or delete it from this view.
Using prompts
Prompts work in the same way as commands. Inside Cody's chat window is a drop-down called prompts next to the LLM selector. Use this to select a prompt and run on your codebase.
Promoted Prompts
Promoted Prompts allow admins to highlight Prompts to users at the top of a Prompt list in Cody chat, directing users to use specific Prompts that encourage best practices within the organization. Admins can promote a Prompt by checking the Promoted box in the Prompt edit screen.
Promoted Prompts are marked with an icon next to their name and appear at the top of the Prompt list in the Cody chat window in an IDE and the Prompt Library.
Commands
Cody offers quick, ready-to-use commands for common actions to write, describe, fix, and smell code. These allow you to run predefined actions with smart context-fetching anywhere in the editor. Like autocomplete and chat, commands will search for context in your codebase to provide more contextually aware and informed answers.
Commands are available in VS Code, JetBrains, Visual Studio, and the Sourcegraph web app. Commands can handle tasks like:
- Edit Code
- Document Code
- Explain Code
- Generate Unit Tests
- Find Code Smells
Running commands
Commands are available in the Cody chat panel under the Prompts drop-down in the editor extensions and on the web. You can run the commands via:
- Select code in the editor and use the Cody commands from the Prompts drop-down to run a command:
- Right-click in the editor and select a command in the Cody submenu.
Custom commands
Custom Commands allow you to create your own commands for Cody that are tailored to your development workflows. They are defined in JSON
format and will enable you to call CLI tools, write custom prompts, and select context to be sent to Cody. This provides a flexible way to configure Cody to handle use cases like:
- Integrate with your build system to suggest fixes for errors/warnings in the latest build
- Analyze software dependencies output to explain compatibility or suggest upgrades
- Read test command failures to explain and suggest fixes
- Explain code quality output like linter warnings
Creating a Custom Command
You can create a custom command by editing the configuration JSON file or using the command builder within the VS Code editor. To access the command builder within VS Code:
- Go to Cody settings, then select Custom Commands Settings
- Select New Custom Command
- Enter the name for your new custom command, such as
my-custom-command
- Choose the method about how the command should be executed
- Provide the relevant instructions for Cody to follow. This is the
prompt
that Cody will use to pass relevant context to the LLM - Then, select one or more options for the context Cody should use to generate responses
- Finally, choose whether to save the command locally or share it with your workspace
- Press Enter to complete the process, and your custom command is successfully created
- You can hit
esc
key at any time to discard a new custom command
Configuring file paths
Custom Commands can be defined in the following two file paths:
- User Settings (
~/.vscode/cody.json
): Stored locally. Use this for personal commands to use across all your projects - Workspace Settings (
.vscode/cody.json
): Stored in your project’s repository. Use this to share commands with others working on the same codebase and for project-specific commands
If you select User Settings, the new custom command will only be available to you. If you choose Workspace Settings (as an enterprise user), your teammates will also be able to use the custom command.
For more details on configuring custom commands, see the examples and configuration properties below.