Skip to content

Using Slash Commands ​

Using slash commands

Slash Commands enable you to quickly add context to the chat buffer. They are comprised of values present in the interactions.chat.slash_commands table alongside the prompt_library table where individual prompts have opts.is_slash_cmd = true.

NOTE

Every command on this page is CodeCompanion's own and is triggered with /. An ACP agent such as Claude Code also exposes its own commands, which the plugin discovers from the agent at runtime. Those are triggered with \ to keep the two apart - see ACP Commands.

/acp_session_options ​

NOTE

This command is only relevant for users of ACP adapters

The ACP specification allows users to change config options for an agent session and the acp_session_options slash command provides the interface to do this.

/buffer ​

buffer slash command

NOTE

As of v16.2.0, buffers are now watched by default

The buffer slash command enables you to add the contents of any open buffers in Neovim to the chat buffer. The command has native, Telescope, mini.pick, fzf.lua and snacks.nvim providers available. Also, multiple buffers can be selected and added to the chat buffer as per the video above.

This slash command is also available in the CLI prompt input, where it inserts @path references instead of buffer contents.

/command ​

The command slash command is specific to ACP adapters and allows users to switch between different adapter commands. For instance, some ACP adapters may allow you to run the agent command with a specific flag. Be mindful that switching commands is destructive and essentially resets the chat buffer for the purposes of a conversation with an agent.

/compact ​

The compact slash command, based on Claude Code's corresponding feature, clears the chat buffer's message history whilst preserving a summary, in context.

System prompts, rules and file/buffer shares will be preserved but all user, assistant and tool messages will be removed. The summary is generated by prompting the same LLM to summarize the chat history into a concise format.

/fetch ​

TIP

To better understand a Neovim plugin, send its config.lua to your LLM via the fetch command alongside a prompt

The fetch slash command allows you to add the contents of a URL to the chat buffer. By default, the plugin uses the awesome and powerful jina.ai to parse the page's content and convert it into plain text. You can also use the markitdown adapter for the same purpose, which adds support for local files and various document formats like pdf, docx, etc. For convenience, the slash command will cache the output to disk and prompt the user if they wish to restore from the cache, should they look to fetch the same URL.

The markitdown adapter runs the markitdown CLI, timing out at two minutes. This can be modified with:

lua
require("codecompanion").setup({
  adapters = {
    http = {
      extend = {
        markitdown = { opts = { timeout = 300000 } }, -- milliseconds
      },
    },
  },
})

/file ​

The file slash command allows you to add the contents of a file in the current working directory to the chat buffer. The command has native, Telescope, mini.pick, fzf.lua and snacks.nvim providers available. Also, multiple files can be selected and added to the chat buffer.

The content of a file can be reshaped before the LLM sees it with context formatters.

Searching other directories

Use opts.dirs to give the picker a list of directories to search alongside the current working directory:

lua
require("codecompanion").setup({
  interactions = {
    chat = {
      slash_commands = {
        ["file"] = {
          opts = {
            dirs = { "~/notes", "../shared-library" },
          },
        },
      },
    },
  },
})

Paths may be relative or use ~.

Images

Selecting an image sends it to the LLM as an image rather than as file content, in the same way as the /image slash command.

PDFs

#3218 added support for PDFs for the following http adapters:

  • Anthropic
  • Copilot (currently only supports OpenAI models)
  • OpenAI
  • OpenAI Responses
  • OpenRouter

Simply use the /file slash command and select a PDF file. The plugin will base64 encode the PDF and send it to the LLM.

This slash command is also available in the CLI prompt input, where it inserts @path references instead of file contents.

  • Select a single file: ⏎ enter
  • Select multiple files: ⇥ tab

Please note that these mappings may be different depending on your provider.

/fork ​

The fork slash command, specific to http adapters, allows you to duplicate the current chat buffer, copying the message history and preserving tools and context in the process. This enables you to branch the conversation and experiment with different prompts, models or even adapters without losing the original conversation.

To save every fork as a session as soon as it's created:

lua
require("codecompanion").setup({
  interactions = {
    chat = {
      slash_commands = {
        ["fork"] = {
          opts = {
            auto_save_session = true,
          },
        },
      },
    },
  },
})

/help ​

The help slash command allows you to add content from a vim help file (:h helpfile), to the chat buffer, by searching for help tags. Currently this is only available for Telescope, mini.pick, fzf_lua and snacks.nvim providers. By default, the slash command will prompt you to trim a help file that is over 1,000 lines in length.

/image ​

The image slash command allows you to add images into a chat buffer via remote URLs and through your file system. In the config for the slash command, you can specify a group of directories (with opts.dirs) that the image picker will always search in, alongside the current working directory. Currently the image picker is only available with snacks.nvim and the vim.ui.select.

/rules ​

The rules slash command allows you to add rules groups to the chat buffer.

/mcp ​

The mcp slash command allows you to start and stop Model Context Protocol (MCP) servers manually from within a chat buffer. This is applied at a global level, so starting/stopping servers in one chat buffer will affect all other chat buffers. A snacks.nvim and vim.ui.select provider is available for selecting which MCP servers to start/stop.

/mcp-prompts ​

The mcp-prompts slash command adds a prompt from a running MCP server to the chat buffer, ready for you to edit before sending. After selecting a prompt, you'll be asked for each of its arguments in turn. Optional arguments can be left blank, and cancelling at any point adds nothing.

NOTE

Only the text from a prompt's user messages is added. Images, resources and assistant messages are skipped

/mode ​

The mode slash command is specific to ACP adapters and allows users to switch between different agent operating modes, as per the protocol docs.

/now ​

The now slash command simply inserts the current datetime stamp into the chat buffer.

/rename ​

The rename slash command is specific to http adapters. It allows you to rename the title of the conversation in the chat buffer. This can be useful to keep track of different conversations via open chats in the action palette.

/resume ​

The resume slash command lists your past chat sessions and restores the selected one into the chat buffer.

What it lists depends on the adapter. On an ACP adapter that supports the session/list capability, it asks the agent for its own sessions. On an http adapter, it lists the sessions saved to disk.

NOTE

The /resume command must be used before sending any messages. It is only available on a fresh chat buffer.

/save ​

The save slash command is specific to http adapters. It saves the chat to disk as a session, which you can restore later with /resume. You'll be asked for a title if the chat doesn't already have one.

Chats are saved automatically by default, so /save is for when you want to name one yourself or save it before the LLM has responded.

/share ​

The share slash command allows you to share the conversation in the chat buffer as a secret GitHub Gist. You'll need to ensure that you set a token in your configuration with permission to create gists:

lua
require("codecompanion").setup({
  interactions = {
    chat = {
      slash_commands = {
        ["share"] = {
          opts = {
            token = os.getenv("GITHUB_GIST_TOKEN"),
          },
        },
      },
    },
  },
})

/skills ​

The skills slash command adds skills to the chat buffer. Multiple skills can be selected at once, depending on the picker you've configured.

/skills-group ​

The skills-group slash command adds a group of skills in one go. It's hidden if you haven't configured any groups.

/symbols ​

NOTE

If a filetype isn't supported please consider making a PR to add the corresponding Tree-sitter queries from aerial.nvim

The symbols slash command uses Tree-sitter to create a symbolic outline of a file to share with the LLM. This can be a useful way to minimize token consumption whilst sharing the basic outline of a file. The plugin utilizes the amazing work from aerial.nvim by using their Tree-sitter symbol queries as the basis. The list of filetypes that the plugin currently supports can be found in the Tree-sitter queries directory.

The command has native, Telescope, mini.pick, fzf.lua and snacks.nvim providers available. Also, multiple symbols can be selected and added to the chat buffer.

Released under the Apache-2.0 License.