Skip to content

Zed integration - #4266

Merged
mattKorwel merged 2 commits into
google-gemini:mainfrom
zed-industries:zed-integration
Jul 17, 2025
Merged

mattKorwel merged 2 commits into
google-gemini:mainfrom
zed-industries:zed-integration

Conversation

@ConradIrwin

@ConradIrwin ConradIrwin commented Jul 15, 2025 •

Copy link
Copy Markdown
Contributor

This PR introduces an experimental mode for Gemini to allow it to be used to
power the Agent panel within Zed.

Co-Authored-By: Agus Zubiaga [email protected]
Co-Authored-By: Ben Brandt [email protected]
Co-authored-by: mkorwel [email protected]

TLDR

This integration allows Zed to provide an alternative UI for Gemini that is
tightly integrated with the editor, showing diffs and file changes in context,
and letting the user edit files as they go.

Zed takes responsibility for the life-cycle, and boots Gemini with
--experimental-acp. In this mode Gemini will run a JSONRPC protocol over
stdin/stdout instead of launching the existing terminal UI.

Dive Deeper

The primary change here is the new --experimental-acp flag and the accompanying acp/ directory.

There are two parts to the implementation:

  • acp.ts contains an experimental implementation of a JSONRPC protocol designed to allow UIs (like Zed) to control Agents (like Gemini). Based on feedback and improvements on how this works we would like to extract this out in the future, but for now we've just implemented the pieces we need to make the Zed/Gemini integration work.

  • agentPeer.ts contains the logic that uses the existing core package to communicate over this protocol, replacing the existing terminal UI with one that can talk to Zed over stdin/stdout.

The remaining changes are mostly to tools to add icons that we can show in the UI, and toolLocations
so that Zed can show the user where the agent's attention is focused.

Reviewer Test Plan

To fully test the integration, you'll need the latest version of Zed preview, and to add the following to your settings:

{
  "agent_servers": {
    "gemini": {
      "command": "node",
      "args": ["/<PATH>/<TO>/gemini-cli/packages/cli", "--experimental-acp"]
    }
  },
}

You will also need to be in the feature flag on the Zed side. Please ask @ConradIrwin, or @agu-z to be added.

To test this, you can open the Agent panel in Zed (the AI icon in the bottom right) and then click + in the top right. You should see "New Gemini Thread". Once you click this, you can verify that Gemini works correctly, but that the Zed UI is used instead of the CLI.

Testing Matrix

🍏 🪟 🐧
npm run ❓ ❓ ❓
npx ❓ ❓ ❓
Docker ❓ ❓ ❓
Podman ❓ - -
Seatbelt ❓ - -

Linked issues / bugs

N/A

@ConradIrwin
ConradIrwin requested a review from a team as a code owner July 15, 2025 22:51
@google-cla

google-cla Bot commented Jul 15, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @ConradIrwin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant architectural change by implementing an experimental Agent Communication Protocol (ACP) within the Gemini CLI. This protocol enables external graphical user interfaces, specifically the Zed editor, to seamlessly integrate with and control the Gemini agent. The core impact is a shift from a terminal-based interaction to a more robust, structured JSON-RPC communication, allowing for a richer and more integrated user experience within IDEs by providing detailed tool execution feedback, visual cues, and contextual file information.

Highlights

  • Zed Integration: Implemented a new --experimental-acp CLI flag that allows Gemini to run in a headless mode, communicating over stdin/stdout to power the Agent panel within the Zed editor, providing a tightly integrated user experience.
  • Enhanced Tooling Metadata: All core tools now include icon and toolLocations properties, enabling external UIs to display relevant visual cues and contextual file information (paths and line numbers) for tool actions.
  • Improved Diff Representation: Updated data structures for file diffs (FileDiff, ToolEditConfirmationDetails) to explicitly include originalContent and newContent, facilitating richer and more accurate diff visualizations in integrated UIs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR introduces a significant new feature: an experimental mode for integrating Gemini with the Zed editor via a JSON-RPC protocol. The changes are extensive, adding new files for the protocol (acp.ts) and the agent peer implementation (acpPeer.ts), and modifying many core tool files to support the new UI capabilities like icons and file locations.

The implementation of the JSON-RPC layer and the agent logic looks solid, but I've identified a critical issue with error handling in the communication channel that could lead to silent failures. I've also pointed out a high-risk area in the acpPeer where brittle string parsing could lead to correctness issues down the line.

Overall, this is a well-structured PR for a complex feature. Addressing the identified issues will improve the robustness and maintainability of this new integration.

Comment thread packages/cli/src/acp/acp.ts Outdated
Comment on lines 219 to 222

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The current implementation of the .catch() block swallows errors from writer.write(). If the underlying stream is closed or encounters an error (e.g., the Zed process crashes), all subsequent attempts to send messages will fail silently.

This creates a failure mode that is very difficult to debug, as the agent will appear to be working but no messages will reach the client.

At a minimum, the error should be logged to stderr. A more robust solution might involve marking the connection as failed and stopping any further attempts to write to the broken stream.

      .catch((error) => {
        // Log the error to aid in debugging a broken pipe.
        // This avoids silent failures if the client process has exited.
        console.error('ACP write error:', error);
      });

Comment thread packages/cli/src/acp/acpPeer.ts Outdated
Comment on lines 550 to 566

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This logic for parsing the output of the read_many_files tool using a regular expression is quite brittle. It creates a tight coupling between this component and the specific string format produced by the tool. If the separator format in read_many_files changes in the future, this parsing logic will break, leading to malformed context being sent to the LLM.

A more robust approach would be for the read_many_files tool to return a more structured result (e.g., an array of {path: string, content: Part} objects) instead of a formatted string that needs to be parsed back into its components. This would make the communication between components more reliable and easier to maintain.

@chrstnb

chrstnb commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

What's the reasoning behind using ACP versus A2A?

@ConradIrwin

Copy link
Copy Markdown
Contributor Author

@chrstnb A2A is designed for a very different use-case (potentially untrusted agents distributed across the internet. It mandates things that don't make sense (like https transport with valid certificates) and doesn't provide things that are necessary for a good user experience for coding agents (currently diffs in tool output, but we're working on a mode for proxied file system and other mode editor specific concerns).

@LiberQuack

Copy link
Copy Markdown

Amazing feature, attaching my recording to make it easier to understand how it works

Screencast_20250716_153629.mp4

@LiberQuack

Copy link
Copy Markdown

one thing I noted .

I have my own MCPs on zed; if it was possible to somehow use ACP to also override/add MCPs in that gemini session it would be amazing

For context, those are my zed MCPs
image

@ConradIrwin

Copy link
Copy Markdown
Contributor Author

@LiberQuack yes! although not implemented in this PR, we're also working on Zed's MCP server support to allow this.

@LiberQuack

LiberQuack commented Jul 16, 2025 •

Copy link
Copy Markdown

Hey @ConradIrwin, that's awesome!

Between us... I used same IDE for the last 10 years, but now my primary one is Zed, you guys are doing a brilliant job!!!

❤️ ❤️ ❤️

NTaylorMullen
NTaylorMullen previously approved these changes Jul 17, 2025

@NTaylorMullen NTaylorMullen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super excited for Zed's amplification here + that these changes are IDE agnostic and enable all IDEs to do the same. In addition I appreciate the effort in trying to limit the blast radius of a change like this.

All that said I can see some overlap between ACP and A2A but it's far too early to be able to understand which path makes the most sense. Because of this lets get this in and experiment! We may end up needing to swap to A2A OR swap more of our stack to ACP, experimentation will tell all!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Icon, // Import from core
Icon,

@NTaylorMullen

Copy link
Copy Markdown
Collaborator

Looks like you'll need to address some conflicts as well before merge

ConradIrwin and others added 2 commits July 17, 2025 15:33
This PR introduces an experimental mode for Gemini to allow it to be used to
power the Agent panel within Zed.

This integration allows Zed to provide an alternative UI for Gemini that is
tightly integrated with the editor, showing diffs and file changes in context,
and letting the user edit files as they go.

Zed takes responsibility for the life-cycle, and boots Gemini with
`--experimental-acp`, before talking to it over our experimental ACP protocol.

Based on our experience making this work with Gemini and Zed, we hope (in the
future) to be able to re-use for multiple agents and IDEs. It currently covers
just what we needed to make this work: initialization and authorization, and the
ability to stream assistant messages and tool calls (including permission
prompts) to the UI.

Co-Authored-By: Agus Zubiaga <[email protected]>
Co-Authored-By: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
@mattKorwel
mattKorwel added this pull request to the merge queue Jul 17, 2025
Merged via the queue into google-gemini:main with commit 761ffc6 Jul 17, 2025
skeshive pushed a commit that referenced this pull request Jul 18, 2025
Co-authored-by: Agus Zubiaga <[email protected]>
Co-authored-by: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
galdawave pushed a commit that referenced this pull request Jul 22, 2025
Co-authored-by: Agus Zubiaga <[email protected]>
Co-authored-by: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
@mymark21

Copy link
Copy Markdown

Amazing feature, attaching my recording to make it easier to understand how it works

Screencast_20250716_153629.mp4

hi, can you give a detailed guide on this ? I try to config it in ZED , but failed, Thanks

@versecafe

Copy link
Copy Markdown

@mymark21 if you build zed from scratch with the following git diff you'll see Gemini & Claude Code appear as options when creating a new agent thread

diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs
index 7f2fbce189..055cef1753 100644
--- a/crates/agent_ui/src/agent_panel.rs
+++ b/crates/agent_ui/src/agent_panel.rs
@@ -1900,9 +1900,7 @@ impl AgentPanel {
                 let active_thread = active_thread.clone();
                 Some(ContextMenu::build(window, cx, |mut menu, _window, cx| {
                     menu = menu
-                        .when(cx.has_flag::<feature_flags::AcpFeatureFlag>(), |this| {
-                            this.header("Zed Agent")
-                        })
+                        .header("Zed Agent")
                         .action("New Thread", NewThread::default().boxed_clone())
                         .action("New Text Thread", NewTextThread.boxed_clone())
                         .when_some(active_thread, |this, active_thread| {
@@ -1918,24 +1916,22 @@ impl AgentPanel {
                                 this
                             }
                         })
-                        .when(cx.has_flag::<feature_flags::AcpFeatureFlag>(), |this| {
-                            this.separator()
-                                .header("External Agents")
-                                .action(
-                                    "New Gemini Thread",
-                                    NewExternalAgentThread {
-                                        agent: Some(crate::ExternalAgent::Gemini),
-                                    }
-                                    .boxed_clone(),
-                                )
-                                .action(
-                                    "New Claude Code Thread",
-                                    NewExternalAgentThread {
-                                        agent: Some(crate::ExternalAgent::ClaudeCode),
-                                    }
-                                    .boxed_clone(),
-                                )
-                        });
+                        .separator()
+                        .header("External Agents")
+                        .action(
+                            "New Gemini Thread",
+                            NewExternalAgentThread {
+                                agent: Some(crate::ExternalAgent::Gemini),
+                            }
+                            .boxed_clone(),
+                        )
+                        .action(
+                            "New Claude Code Thread",
+                            NewExternalAgentThread {
+                                agent: Some(crate::ExternalAgent::ClaudeCode),
+                            }
+                            .boxed_clone(),
+                        );
                     menu
                 }))
             });

this just removes the feature flag check

for gemini you can do this in your zed settings.json

  "agent_servers": {
    "gemini": {
      "command": "gemini",
      "args": ["--experimental-acp"],
      "env": { "GEMINI_API_KEY": "<key here>" }
    }
  }

and for claude code support it should just work as long as your cli is already set up

@ConradIrwin

Copy link
Copy Markdown
Contributor Author

FYI this is likely to break again over the next few releases as we are making some big changes to how it works.

@LiberQuack

Copy link
Copy Markdown

@versecafe my approach is a little bit different, in case you are interested, that's the change I do locally. Im basically enabling all flags

diff --git a/crates/feature_flags/src/feature_flags.rs b/crates/feature_flags/src/feature_flags.rs
--- a/crates/feature_flags/src/feature_flags.rs
+++ b/crates/feature_flags/src/feature_flags.rs
@@ -19,15 +19,7 @@ pub static ZED_DISABLE_STAFF: LazyLock<bool> = LazyLock::new(|| {

 impl FeatureFlags {
     fn has_flag<T: FeatureFlag>(&self) -> bool {
-        if T::enabled_for_all() {
-            return true;
-        }
-
-        if self.staff && T::enabled_for_staff() {
-            return true;
-        }
-
-        self.flags.iter().any(|f| f.as_str() == T::NAME)
+        return true;
     }
 }

jkcinouye pushed a commit that referenced this pull request Jul 25, 2025
Co-authored-by: Agus Zubiaga <[email protected]>
Co-authored-by: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
@ezotrank

Copy link
Copy Markdown

Hey there! @ConradIrwin or @agu-z Could you add me to the feature flag?

JunYang-tes pushed a commit to JunYang-tes/gemini-cli.nvim that referenced this pull request Aug 9, 2025
Co-authored-by: Agus Zubiaga <[email protected]>
Co-authored-by: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
involvex pushed a commit to involvex/gemini-cli that referenced this pull request Sep 11, 2025
Co-authored-by: Agus Zubiaga <[email protected]>
Co-authored-by: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
reconsumeralization pushed a commit to reconsumeralization/gemini-cli that referenced this pull request Sep 19, 2025
Co-authored-by: Agus Zubiaga <[email protected]>
Co-authored-by: Ben Brandt <[email protected]>
Co-authored-by: mkorwel <[email protected]>
@sripasg sripasg added the size/xl An extra large PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xl An extra large PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants