Use Gemini Code Assist code customization (original) (raw)
Discover
Get started
Configure
Gemini Cloud Assist
Gemini Code Assist
Observability
Troubleshoot
Use Gemini Code Assist code customization
This document describes how to useGemini Code Assist code customizationand provides a few best practices. This feature lets you receive code recommendations, which draw from the internal libraries, private APIs, and the coding style of your organization.
Before you begin
- Set up Gemini Code Assistwith an Enterprise subscription.
- Set up Gemini Code Assist code customizationwith an Enterprise subscription.
The following table lists ways to use Gemini Code Assist code customization:
Form | How to trigger | Notes and resources |
---|---|---|
Natural language chat | Enter a natural language prompt in Gemini Code Assist chat in the IDE. | Consider the following: Chat history is not available. Avoid multi-step queries. You can ask for more details about sources, including links to the specific sources. If you highlight or select code when you send a message in chat, Gemini Code Assist uses that code to improve code customization and chat quality. For more information, seeChat with Gemini Code Assist . |
Generate code | In the quick pick bar in your IDE, either with or without selected code, press Command+Enter (on macOS) orControl+Enter. | For more information, seeGenerate code with prompts. |
Transform code | In the quick pick bar in your IDE, either with or without selected code, enter /fix. | For more information, seeGenerate code with prompts. |
Autocomplete | Code customization is automatically triggered and provides suggestions based on what you write. | Consider the following: Code completion needs a certain level of confidence to propose a suggestion. Ensure that a substantial amount of code is available so that relevant snippets are retrieved. Code completion checks if you have required libraries in order to use certain elements of the function. For more information, seeGet code completions. |
Use cases and prompt examples
The following table provides guidance and examples about using code customization in specific use cases:
Use case | Things worth trying |
---|---|
Writing new code | Try the following to generate code in your IDE or Gemini Code Assist chat: Generate code that would use terms which are already mentioned in your codebase. Paste in your code, such as a functional signature or code withTODO comments, and then ask Gemini Code Assist to fill in or replaceTODO comments with code. Add comments with explanation from context. Try generating code with the following prompts in Gemini Code Assist chat: "Write a main function where a connection toDATABASE is created. Include health checks." "Write a FUNCTION_OR_CLASS in the following structure:EXPLAIN_STRUCTURE." After you generate some code, try using a follow-up prompt to improve it: "Try the /fix command to adjust the generated code—for example, syntax errors." "Add missing imports." "Try /fix on chat-generated code." |
Cleaning, simplifying, and refactoring code | Try the following prompts in Gemini Code Assist chat: "Can you mergeIMPORTS_VARIABLES_OR_NOTE_EXPORTED_FUNCTIONS in this file?" "How would you simplify theFUNCTION_NAME function?" "Can you merge FUNCTION_NAME_1 andFUNCTION_NAME_2 into one function?" "Could you inline some variables inFUNCTION_NAME?" "Could you simplify variable naming in the functionFUNCTION_NAME?" |
Readability | Try the following prompts in Gemini Code Assist chat: "Write the function FUNCTION_NAME in fewer lines of code, if possible." "Add comments to the functionFUNCTION_NAME." "Remove unnecessary whitespaces in the functionFUNCTION_NAME." "Format the function FUNCTION_NAME in a similar way as the rest of the code." |
Code review | Try the following prompts in Gemini Code Assist chat: "Split the code in parts and explain each part using our codebase." "Are there variables or keywords that could be shorter and more self-explanatory?" "Can you give me useful code from theREPOSITORY_NAME_PACKAGE_MODULE context for this code?" "What do you think about the functionFUNCTION_NAME?" |
Debugging | Try the following prompts in Gemini Code Assist chat: "I am getting an error when I try to do X/add Y. Why?" "Can you spot an error in the functionFUNCTION_NAME?" "How would you fix the functionFUNCTION_NAME given this error message?" |
Learning and onboarding | Try the following prompts in Gemini Code Assist chat: "Split this code in parts and explain each of them using our codebase." "Show how to call functionFUNCTION_NAME?" "Show how to run the main function in theENVIRONMENT_NAME environment?" "What is the key technical improvement we can do to make this code more performant?" "Show me the implementation ofFUNCTION_OR_CLASS_NAME to achieve better results and add what that specific element is"—for example, "Show me the implementation of function foo where foo is the name of the function." |
Migration | Try the following prompts in Gemini Code Assist chat: "Give me a strategy for how I can migrateFILE_NAME fromLANGUAGE_1 toLANGUAGE_2"—for example, from Go to Python. "Given the function FUNCTION_NAME in repository REPOSITORY_NAME, find me an equivalent function in languageLANGUAGE_NAME that I can use." Try the following chat-based or code generation transformation workflow using prompts: "Take FILENAME_COMPONENT code already written in LANGUAGE_1 and refactor and migrate it to LANGUAGE_2"—for example, from Go to Python. After you migrate some code, try the following: Select smaller chunks and use /fix to get it into a state that you want. Try the following prompts: "Is there something which can be improved?" "Give me possible pain points." "How would you test this code if that migration is correct?" |
Generating documentation | Try the following prompts in Gemini Code Assist chat: "Summarize the code in package or folderX and provide documentation for the top five important methods." "Generate documentation forFUNCTION_OR_CLASS_NAME." "Shorten the documentation while preserving the key information." |
Unit test generation | Try the following prompts in Gemini Code Assist chat: "Generate unit tests for FILENAME." "Add the most relevant test cases for theFUNCTION_NAME function." "Remove test cases that you think don't bring much value." |
Best practices
- Use relevant variable and function names or code snippets. This guides code customization towards the most pertinent code examples.
- Use index repositories that you want to scale, and avoid adding deprecated functionality. Code customization helps to scale to the code style, patterns, code semantics, knowledge, and implementations across the codebase. Bad examples of repositories to scale are deprecated functionalities, generated code, and legacy implementations.
- For code retrieval use cases, use code generation functionality instead of code completion. Prompt using language such as "Using the definition of
FUNCTION_NAME
, generate the exact same function," or "Generate the exact implementation ofFUNCTION_NAME
." - Have includes or imports present in the file for the code that you want to retrieve to improve Gemini contextual awareness.
- Execute only one action for each prompt. For example, if you want to retrieve code and have this code be implemented in a new function, perform these steps over two prompts.
- For use cases where you want more than just code (such as code explanation, migration plan, or error explanation), use code customization for chat, where you have a conversation with Gemini with your codebase in context.
- Note that AI model generation is non-deterministic. If you aren't satisfied with the response, executing the same prompt again might achieve a better result.
- Note that generating unit tests generally works better if you open the file locally, and then from chat, ask to generate unit tests for this file or a specific function.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-12 UTC.