Skip to content

instilled/intellij-gemini-cli

Repository files navigation

IntelliJ Gemini CLI Plugin

This plugin integrates the Gemini CLI into IntelliJ IDEA, providing seamless editor integration through the MCP (Model Context Protocol) IDE Companion Specification.

Features

  • Terminal Integration: Opens a dedicated "Gemini" terminal tab that runs the Gemini CLI with automatic IDE server discovery.
  • Real-time Context Streaming: Automatically streams workspace context to Gemini via Server-Sent Events (SSE), including:
    • Open files and their paths
    • Active file and cursor position (line/column)
    • Selected text in the active editor
  • Native Diff Viewer: Gemini can open diffs directly in IntelliJ's native diff viewer using the openDiff MCP tool.
  • Keyboard Shortcut: Trigger with Shift+Cmd+Esc twice (or Shift+Cmd+Esc then Esc).
  • Auto-Discovery: The plugin automatically registers an MCP server that Gemini discovers via a JSON file in the system temp directory.

Requirements

  • Gemini CLI: You must have the gemini CLI tool installed and in your PATH.
  • IntelliJ IDEA 2023.2 or later (with Terminal plugin enabled).

How It Works

The plugin starts a local HTTP server (MCP) on a dynamic port when your project opens. When you trigger the plugin via keyboard shortcut:

  1. A new terminal tab named "Gemini" is created (or focused if it already exists)
  2. The gemini CLI is launched with the GEMINI_CLI_IDE_SERVER_PORT environment variable set
  3. Gemini discovers the IDE server via a discovery file at $TMPDIR/gemini/ide/gemini-ide-server-{pid}-{port}.json
  4. The CLI connects to the MCP server to receive real-time context updates and use IDE tools like openDiff

As you work in IntelliJ, the plugin automatically sends context updates to Gemini whenever you:

  • Switch between files
  • Move your cursor
  • Select text

Using IntelliJ as Your Default Editor for Gemini

To make Gemini open files directly in IntelliJ when it needs to edit them, set the EDITOR environment variable to idea:

export EDITOR=idea

Add this to your shell profile (~/.zshrc, ~/.bashrc, etc.) to make it permanent.

Setting up the idea command-line launcher

The idea command is a shell script that launches IntelliJ IDEA. You can create it via:

  1. Open IntelliJ IDEA
  2. Go to ToolsCreate Command-line Launcher...
  3. Accept the default path (/usr/local/bin/idea) or customize it

This creates a simple shell wrapper (on macOS):

#!/bin/sh
open -na '/Applications/IntelliJ IDEA.app' --args "$@"

Note: The exact path and script content may differ based on your IntelliJ installation (Community vs Ultimate, custom install location, or OS platform).

Once configured, when Gemini needs to open a file for editing, it will launch IntelliJ and open the file directly, providing a seamless workflow between the CLI and IDE.

Installation

  1. Build the plugin: ./gradlew buildPlugin
  2. Install from disk: Settings -> Plugins -> Gear Icon -> Install Plugin from Disk -> select build/libs/intellij-gemini-cli-1.0-SNAPSHOT.zip

Development

Run the plugin in a sandboxed IDE:

./gradlew runIde

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages