Using Gemini CLI in VS Code: The Companion Extension
Gemini CLI runs in VS Code’s terminal, and the Gemini CLI Companion extension connects the two: the CLI sees your open files and selection, and its edits open in VS Code’s diff viewer. How to install and enable it, what it shares, which editors it supports, and how to fix a connection that will not start.
7 min read
To use Gemini CLI in VS Code, run gemini in VS Code’s integrated terminal, then type /ide install to add the Gemini CLI Companion extension and /ide enable to connect. From then on the CLI knows which files you have open, where your cursor is and what you have selected, and when it proposes a change, the change opens in VS Code’s own diff viewer, where you can edit it, accept it or close it. The conversation stays in the terminal: the companion adds no chat panel and no completions. It works in VS Code, VS Code-compatible editors and Antigravity. Before any of that, check you can still sign in, because personal Google sign-in has ended.
Who can still sign in
The companion changes nothing about accounts. Google’s deprecation notice for consumer accounts (opens in a new tab) says that from 18 June 2026 the Login with Google option stopped working for Gemini CLI for Gemini Code Assist for individuals, Google AI Pro and Google AI Ultra, and points those users to the Antigravity family of products. Code Assist Standard and Enterprise subscriptions are unchanged, and a Gemini API key or Vertex AI still works. The options, and how to set each one up, are in Gemini CLI best practices.
What the companion is, and what it is not
Google’s IDE integration guide (opens in a new tab) describes the Gemini CLI Companion as the extension that links a Gemini CLI session in the editor’s terminal to the editor itself. It does two things: it tells the CLI what you are looking at, and it shows the CLI’s edits as native diffs. Everything else, the prompts, the plan, tool approvals, /mcp, happens in the terminal as usual.
It is easy to confuse with Gemini Code Assist, Google’s IDE assistant with completions, a chat panel and its own agent mode. They are different products, and you need neither to use the other. How the two relate, including shared settings and quotas for licensed users, is in Gemini CLI vs Gemini Code Assist.
Install it
Gemini CLI needs Node.js 20 or later. Google’s installation page (opens in a new tab) gives npm, Homebrew, MacPorts and npx routes. Then open your project folder in VS Code, open the integrated terminal and start the CLI there, not in a separate terminal window:
npm install -g @google/gemini-cli # or: brew install gemini-cli gemini # then, inside Gemini CLI: /ide install # finds your editor and installs the companion /ide enable # connects this session to the editor /ide status # shows the connection and the context it received
When Gemini CLI starts inside a supported editor it detects that and offers to connect, so the first run often prompts you before you type anything. If /ide install cannot find an installer for your editor, install the extension by hand: from the Visual Studio Marketplace in VS Code, or from the Open VSX Registry in VS Code forks that use it. Search for Gemini CLI Companion.
Enable it and keep it on
/ide enable connects the current session and /ide disable disconnects it. To connect every session without asking, set it in your settings file. The configuration reference (opens in a new tab) lists ide.enabled, off by default, and notes that changing it needs a restart of the CLI:
{
"ide": {
"enabled": true
}
}Put it in ~/.gemini/settings.json to apply it everywhere, or in a project’s .gemini/settings.json to apply it only there. Run /ide status whenever you are not sure: it says whether the session is connected and shows the context the CLI has received from the editor.
What it shares from the editor
- Recent files: the 10 files you most recently opened in the workspace.
- Cursor position: where your cursor is in the active file.
- Selection: the text you have selected, up to 16 KB. Longer selections are cut off.
In practice that means you can select a function, switch to the terminal and ask “why does this return null when the list is empty?” without pasting it or naming the file. It also means the CLI is told about whatever you open, so if a file you would not want sent to a model is open in the editor, close it before you ask. For files the CLI should always read, such as your build and test rules, GEMINI.md is still the place.
Native diffs
Without the companion, Gemini CLI shows a proposed edit in the terminal and asks for approval. With it, the edit opens in VS Code’s diff viewer, where you can change the proposed text before accepting it. There are several ways to answer:
- Accept: click the tick icon in the diff editor, save the file, run Gemini CLI: Accept Diff from the Command Palette, or answer yes in the CLI.
- Reject: click the x, close the diff tab, run Gemini CLI: Close Diff Editor, or answer no in the CLI.
- Edit first: change the right-hand side of the diff, then accept. The CLI receives the file as you left it.
Which editors are supported
- Visual Studio Code, through the companion from the Visual Studio Marketplace.
- VS Code-compatible editors, through the same companion from the Open VSX Registry.
- Antigravity, which Google lists alongside VS Code.
- JetBrains IDEs such as IntelliJ IDEA, PyCharm and GoLand, and Zed: not through the companion. Google documents a separate route for these, the Agent Client Protocol (ACP), and says they can discover and install Gemini CLI from the ACP Agent Registry.
When it will not connect
The CLI finds the companion by working out which editor process it is running inside, and the CLI’s working folder must match one of the editor’s open workspace folders or the connection is rejected. Google’s companion specification (opens in a new tab) describes the mechanics, which explain most of the errors:
- “Failed to connect to IDE companion extension”: make sure the extension is installed and enabled, then open a new terminal in the editor and start again.
- “Directory mismatch”: the CLI is running in a different folder from the workspace.
cdto the folder open in VS Code. - “Please open a workspace folder”: open a folder, not just a file.
- “IDE integration is not supported in your current environment”: you started the CLI in a terminal outside the editor. Start it in the integrated terminal. If you must use a separate terminal, the
GEMINI_CLI_IDE_PIDenvironment variable names the editor process to attach to. - “The connection was lost unexpectedly”: run
/ide enableagain, or restart the terminal or the editor. - Sandboxed sessions: on macOS the sandbox profile must allow network access for the CLI to reach the editor; in Docker or Podman the CLI looks for the editor at
host.docker.internal.
Your board in the same terminal
The companion sends the CLI what is in front of you. The task you are working on is not in any open file, so it helps to have that within reach too. fenbs connects to Gemini CLI as an MCP server in the same settings.json, under mcpServers with httpUrl set to https://fenbs.ai/api/mcp, and /mcp auth fenbs signs you in through the browser. Gemini can then read the task, write its approach into the task’s plan, and comment on what it changed, with each change recorded in History under the assistant’s name. The diffs you accept in VS Code and the comment on the task then tell the same story.
Related
Connect the board: Gemini CLI on fenbs. Agree the approach before any diff appears: Gemini CLI plan mode. The editor-first alternatives: GitHub Copilot agent mode not working and Cursor agent not working.