---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://sourcecraft.dev/portal/docs/en/code-assistant/operations/jb-agent.md
  - https://sourcecraft.dev/portal/docs/ru/code-assistant/operations/jb-agent.md
  - href: en/code-assistant/operations/jb-agent.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
title: SourceCraft Code Assistant agent mode in the JetBrains IDE
description: How to use the Code Assistant agent mode in the JetBrains IDE via the SourceCraft CLI.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# SourceCraft Code Assistant agent mode in the JetBrains IDE

{% note warning %}

The agent mode in the JetBrains IDE is at the _Preview stage_ and available for testing.

{% endnote %}

In the JetBrains IDE, the Code Assistant agent mode is based on the [SourceCraft CLI](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/cli-quickstart.md) with an integrated [OpenCode](https://opencode.ai/docs/en) AI agent. The agent runs in the IDE terminal, enhanced with editor capabilities.

IDE integration unlocks the following features:
* Displaying `diff` when editing files with an option to apply or discard changes.
* Getting diagnostics from files, such as errors, warnings, etc.
* Access to the active file and list of opened files.
* Opening and closing tabs.

{% note info %}

The AI assistant [chat](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat.md) feature is unaffected and remains available by clicking ![image](../../_assets/code-assistant/chat-logo.svg) **SourceCraft Code Assistant Chat** in the editor’s right-hand panel.

{% endnote %}

<iframe width="640" height="360" src="https://runtime.strm.yandex.ru/player/video/vplvxc7xql4sqbdydmat?autoplay=0&mute=0" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" frameborder="0" scrolling="no"></iframe>

To use the agent mode:
1. [Install](https://sourcecraft.dev/portal/docs/en/code-assistant/index.md#install-plugin) the SourceCraft Code Assistant plugin for the JetBrains IDE and get authenticated in SourceCraft.
1. If you have already installed the plugin, [update](https://sourcecraft.dev/portal/docs/en/code-assistant/index.md#update-plugin) to its latest version.
1. In the editor’s top panel, click ![image](../../_assets/code-assistant/jb-agent-button.svg) **SourceCraft Code Assistant Agent [Beta]**.

    ![image](../../_assets/code-assistant/jb-agent-button-screen.png)

    Alternatively, you can enable the agent mode from the top panel of the [chat](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat.md) by clicking ![image](../../_assets/code-assistant/jb-agent-button.svg) **Open Agent**.

    This opens a tool window and automatically starts the SourceCraft CLI installation.

    {% note tip %}

    If the automatic installation fails for any reason, close the IDE and [install](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/cli-quickstart.md) the SourceCraft CLI manually via the terminal. When prompted, confirm the OpenCode installation.

    {% endnote %}

    Once the installation is complete, the agent will start in the tool window.

    ![image](../../_assets/code-assistant/jb-agent-tui.png)

1. One by one, submit natural-language requests to the AI agent.

    To restart the agent, click ![image](../../_assets/console-icons/arrow-rotate-right.svg) **Restart** in the top panel of the tool window.

For more information about working with the SourceCraft CLI and OpenCode, see these guides:
* [Getting started with the SourceCraft CLI](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/cli-quickstart.md)
* [OpenCode documentation](https://opencode.ai/docs/en)

## Working with file changes {#diff}

When editing a file, the agent displays a `diff` view highlighting the proposed changes. Here is what you can do:
* ![image](../../_assets/console-icons/xmark.svg) **Reject**: Discard the changes.
* ![image](../../_assets/console-icons/xmark.svg) **Apply**: Accept the changes.
* ![image](../../_assets/console-icons/check.svg) **Auto Apply**: Automatically apply all changes within the current session.

![image](../../_assets/code-assistant/jb-agent-edits.png)

{% note tip %}

To automatically apply changes suggested by the agent, click ![image](../../_assets/console-icons/check.svg) **Auto-apply** in the top panel of the tool window.

![image](../../_assets/code-assistant/jb-agent-auto-apply.png)

You can also enable auto-approval in the editor settings. In the top-right corner, click ![image](../../_assets/console-icons/gear.svg) → ![image](../../_assets/console-icons/gear.svg) **Settings...** → **SourceCraft Code Assistant** → **Auto-apply code agent edits**.

{% endnote %}

## Useful links {#see-also}

* [Getting started with SourceCraft Code Assistant](https://sourcecraft.dev/portal/docs/en/code-assistant/index.md)
* [SourceCraft Code Assistant overview](https://sourcecraft.dev/portal/docs/en/code-assistant/concepts/index.md)
* [SourceCraft Code Assistant chat interface in the JetBrains IDE](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat.md)
* [Getting started with the SourceCraft CLI](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/cli-quickstart.md)
