CLion 2023.2 Help

AI Assistant

Install the AI Assistant plugin

This functionality relies on the AI Assistant plugin, which you need to install and enable.

  1. Press Control+Alt+S to open the IDE settings and then select Plugins.

  2. Open the Marketplace tab, find the AI Assistant plugin, and click Install (restart the IDE if prompted).

AI Assistant can explain code, answer questions about code fragments, commit messages, and much more.

Log in

To start working with AI Assistant, you need to log in first.

  1. Click the AI Assistant icon on the right toolbar to open AI Assistant.

    AI Assistant icon
  2. Click Log in to JetBrains AI service and follow the steps in the browser.

You can change your account on the Tools | AI Assistant page of the IDE settings Control+Alt+S.

Chat with AI

Use the AI Assistant tool window to have a conversation with the LLM (Large Language Model), ask questions about programming-related topics, or iterate on a task. The AI Assistant takes into consideration the language and technologies used in your project.

  1. Click the AI Assistant icon on the right toolbar to open AI Assistant.

  2. In the input field, type your question and press Enter to submit your query.

    CLion: Asking AI Assistant programming-related questions

AI Assistant keeps the chats during one IDE session. You can find the saved chats in the All Chats list.

All Chats list

Names of the chats are generated automatically and contain the summary of the initial query.

Use prompts to explain and refactor your code

Use pre-written prompts to explain code, find potential problems, and refactor your code. CLion provides project-specific context, such as the languages and technologies used in your project.

You can also define your own custom prompts and add them to the AI Actions menu.

Explain code

  1. Select a code fragment and right-click it to open the context menu.

    Alternatively, select a code fragment and press Alt+Enter.

  2. Select AI actions and then Explain code.

    AI Assistant actions - Explain Code

    The AI Assistant tool window will open to provide you with an explanation.

    CLion AI Assistant explains code

Explain CMake errors

AI Assistant can help you investigate CMake execution problems.

  1. Click Explain with AI in the CMake tool window next to the error message:

    Explain with AI for CMake errors
  2. The AI assistant will explain the error for you and suggest how to fix it:

    The AI Assistant explanation of a CMake error

Explain regex, cron expressions, and SQL queries

AI Assistant can explain regular expressions, SQL queries, cron expressions, and other injected fragments.

  1. Select a code fragment and right-click it to open the context menu.

    Alternatively, select a code fragment and press Alt+Enter.

  2. Select AI actions and then Explain fragment.

    AI Assistant automatically detects the type of injected fragment, so the context menu option for regular expressions will be Explain RegExp fragment and likewise for other fragments.

    CLion: Explain RegExp option in the context menu

    AI Assistant will analyze and explain the fragment.

    CLion: Regex explained with follow up questions

Suggest refactoring

  1. Select a code fragment and right-click it to open the context menu.

    Alternatively, select a code fragment and press Alt+Enter.

  2. Select AI actions and then Suggest refactoring.

    AI Actions menu - suggest refactoring

    The AI chat will open to offer you refactoring suggestions.

    CLion: AI Assistant suggests refactoring

  3. If you like the result, click Insert Snippet at Caret in the field with the refactored code to put the AI-generated code into the editor and replace the originally selected code fragment.

Find potential problems

  1. Select a code fragment and right-click it to open the context menu.

    Alternatively, select a code fragment and press Alt+Enter.

  2. Select AI actions and then Find potential problems.

    AI Actions menu - finds potential problems

    The AI chat will open to show the potential issues you may want to look into.

    CLion: AI Assistant finds potential problems in the selected code

Add your own prompts to prompts library

You can add your own prompts to the prompts library and use them via AI Actions menu.

  1. Press Control+Alt+S to open the IDE settings and then select Tools | AI Assistant | User Prompts Library.

  2. Click App client expui general add to create a new prompt.

    CLion: User prompts library settings
  3. In the text field, write the prompt. If needed, use the following variables:

    • $SELECTION: a Markdown-formatted code block with current code selection and language name.

    • $SELECTION_RAW: selected code fragment.

    • $SELECTION_LANG: the language of the currently selected code fragment.

    • $PRODUCT_NAME: the name of the product that is currently launched, for example, CLion.

  4. In the advanced options, edit the new prompt name.

    Select the first checkbox if you want AI Assistant to wait for you to make additional input in the chat after invoking the prompt.

    Keep the second checkbox if you want your new prompt to be listed in the AI Actions menu.

  5. Click Apply.

After you created a prompt, you can always edit or delete it.

Work with commits

AI Assistant can send your diffs to the LLM, which will generate a commit message describing your changes.

Generate commit messages

  1. Press Alt+0 to open the Commit tool window.

  2. Click the Generate Commit Message with AI Assistant icon.

    CLion: AI Assistant generates commit messages
  3. Edit the message if necessary.

    CLion: AI-generated commit message

Explain commits

AI Assistant can summarize the changes made in one or several commits.

  1. Click App expui toolwindow vcs in the bottom-left corner or press Alt+9 to open the version control tool window.

  2. In the commits pane, select the commit or several commits you want to summarize, right-click them and select Explain Commit with AI Assistant in the context menu.

    Explain Commit with AI Assistant option in VCS log

    AI Assistant provides the summary of the selected commits.

    AI Assistant explains commit

Use AI in the editor

When you rename (Shift+F6) a local variable, AI Assistant suggests context-aware name options.

AI-generated rename suggestions

This feature is enabled by default. To switch it on and off, check the AI Assistant settings.

Enable name suggestions

  1. Press Control+Alt+S to open the IDE settings and then select Tools | AI Assistant.

  2. Select the Provide AI-generated name suggestions checkbox.

    AI Assistant settings

How we handle your code and data

When you use AI features, CLion needs to send your requests and pieces of your code to the LLM (Large Language Model) provider. Besides the prompts you type, it may send additional details, such as file types, frameworks used, and any other information that may be necessary for providing context to the LLM.

In addition, CLion builds with the AI Assistant plugin perform opt-in collection of detailed data about the usage of AI features, including the full communication between you and the LLM (both text and code fragments). This data is kept strictly confidential and is used by JetBrains for product improvement purposes only. It is never shared with any external parties, and it will not be used for training any ML models that generate code or text, or revealed in any form to any other users. The option that controlls detailed data collection can be found in the IDE Settings under Tools | AI Assistant | Data Sharing | Send AI Assistant usage statistics.

For more information about our data collection policies, refer to Data Collection and Use Policy.

Last modified: 05 September 2023