Text of docs.cloud.google.com › code › docs › shell › write-code-gemini as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Code with Gemini Code Assist | Cloud Code for Cloud Shell | Google Cloud Documentation

Skip to main content Code with Gemini Code Assist Stay organized with collections Save and categorize content based on your preferences. This document describes how you can use Gemini Code Assist , an AI-powered collaborator in Google Cloud, to help you do the following in Cloud Shell: Provide guidance to help you solve problems with your code. Generate code for your project. Receive inline suggestions while you're coding.

Learn how and when Gemini for Google Cloud uses your data . To help you comply with any license requirements for your code, Gemini Code Assist provides source citations when its suggestions directly quote at length from a specific source. To learn more about how and when Gemini cites sources, see How Gemini helps you generate code and cites sources . Code customization lets you get code suggestions based on your organization's private codebase directly from Gemini Code Assist.

Learn how to configure code customization . This document is intended for developers of all skill levels. It assumes you have working knowledge of the Cloud Shell Editor and are familiar with Google Cloud. If you prefer, you can also explore Gemini Code Assist in Cloud Workstations , IntelliJ , and VS Code . Connect to Google Cloud and select a project In this section, you'll connect to Google Cloud and select a Google Cloud project with the Gemini for Google Cloud API enabled in the Cloud Shell Editor.

If you select a Google Cloud project without the Gemini for Google Cloud API enabled, you receive a notification that gives you the option to enable the API from the IDE. Select Enable the API in the notification window to enable the API for your project. For more information, see Set up Gemini Code Assist for a project . To connect to Google Cloud in the Cloud Shell Editor, follow these steps: Launch the Cloud Shell Editor .

If prompted to authorize Cloud Shell Editor to make Google Cloud API calls, click Authorize . Follow the prompts to sign into your Google Account. Next to the search bar, click the keyboard_arrow_down Gemini Code Assist dropdown menu. From the menu, select Select Gemini Code Assist Project . This opens the Select Google Cloud project menu. From the Select Google Cloud project menu, select a Google Cloud project that has the Gemini for Google Cloud API enabled.

You're now connected to Google Cloud. Gemini is ready to use. Chat with Gemini Code Assist In this section, learn how to open the Gemini Code Assist pane and chat with Gemini Code Assist to get your code explained. To begin chatting with Gemini, follow these steps: Open a source file. Next to the search bar in Cloud Shell Editor, click chat_spark Open Gemini Code Assist Chat . In the Gemini Code Assist Chat pane, enter the prompt Explain this code to me and click send Send .

Gemini uses your file as context for your prompt and responds with an explanation of your code. To focus on a specific block of code, select that block in your open file before entering your prompt. Reset chat history Gemini Code Assist uses the chat history for additional context when responding to your prompts. If your chat history is no longer relevant to what you're trying to achieve, you can reset the chat history: in the Gemini Code Assist pane, click delete Reset Chat .

Generate code with prompts The following sections show you how to use Gemini Code Assist to generate code with the example prompt Function to create a Cloud Storage bucket inside a file. You can also select a part of your code and then prompt Gemini Code Assist for help through the chat feature, and receive and accept or reject code suggestions while you code. Prompt Gemini Code Assist in a file In a source file, on a new line, enter the comment Function to create a Cloud Storage bucket , and then press Enter (for Windows and Linux) or Return (for macOS).

To generate code, press Control+Enter (for Windows and Linux) or Control+Return (for macOS). Next to your prompt text in your file, Gemini Code Assist generates the code in the form of ghost text. Optional: To accept the generated code, press Tab . Optional: Change keyboard shortcut for generating code If the default keyboard shortcut for generating code isn't working as outlined in the previous section, you can change the keyboard shortcut by following these steps: In the Cloud Shell Editor, click menu Menu , and then navigate to File > Preferences > Keyboard Shortcuts .

In the list of keyboard shortcuts, search for Cloud Code: Generate Code . Click Cloud Code: Generate Code , and then click edit Change Keybinding . In the dialog that appears, enter your own shortcut. Press Enter (for Windows and Linux) or Return (for macOS). You can now use your newly assigned keyboard shortcut to generate code with Gemini. Prompt Gemini Code Assist with selected code using chat Gemini Code Assist can perform tasks or answer your questions based on the code that you select.

To get generated code that's based on a prompt with selected code, follow these steps: Next to the search bar in Cloud Shell Editor, click chat_spark Open Gemini Code Assist Chat . In a source file, select a block of code. In the Gemini Code Assist Chat text field, enter a prompt for the selected code. For example, select a function in your code and enter the prompt Write a unit test for this function . Gemini uses your selected code as reference and responds to your prompt.

Get inline suggestions while you code While you write code, Gemini Code Assist makes inline code suggestions that you can either accept or ignore. To try this feature, follow these steps: In a source file, on a new line, start writing a function. For example, if you're in a Python file, write def . Gemini suggests code in the form of ghost text. To accept the code suggestion from Gemini Code Assist, press Tab . Otherwise, to ignore the suggestion, press Esc or continue writing your code.

Optional: Disable inline suggestions If you prefer to disable inline suggestions in Gemini Code Assist, follow these steps: In the Cloud Shell Editor, select menu Menu , and then navigate to File > Preferences > Settings . On the User tab of the Settings dialog, navigate to Extensions > Cloud Code . Scroll until you find the Cloudcode: Gemini Code Assist: Inline Suggestions: Enable Auto list, and then select Off . This turns off the inline suggestions.

You can still press Control+Enter (for Windows and Linux) or Control+Return (for macOS) to manually trigger inline suggestions. Optional: Exclude files from context with an .aiexclude file You can exclude files from being considered by Gemini Code Assist for context by creating an .aiexclude file. An .aiexclude file follows the similar syntax as a .gitignore file, with the following differences: An empty or nonexistent .aiexclude file blocks no files in its directory and all sub-directories.

An .aiexclude file doesn't support negation, where you prefix patterns with an exclamation point ( ! ). An .aiexclude file matches greedily on the * character. This will match indiscriminately on directories and files. This .aiexclude file doesn't differentiate between ** or * with regards to folders or files. Only a single .aiexclude file is supported currently. To configure your .aiexclude file, create a file titled .aiexclude in the root of your workspace folder.

If you want to place this file outside of the workspace root, or rename the file, the path may be set in the VS Code settings under "Context Exclusion File". The path value provided in this setting will resolve relative to the root folder of your open workspace. Examples The following examples demonstrate how you can configure an .aiexclude file: Block all files named apikeys.txt at or below the workspace directory: apikeys.txt Block all files with the .key file extension at or below the workspace directory: *.key Block only the apikeys.txtfile at the same directory as the .aiexclude file, but not any subdirectories: /apikeys.txt Block all files in the directory my/sensitive/dir a

The rest of this page is on the live site.