Configure Gemini Code Assist code customization Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Gemini Code Assist code customization allows you to receive code recommendations based on your organization's internal libraries, private APIs, and coding style.
Setting up code customization involves meeting prerequisites such as an Enterprise subscription and specific IAM roles, as well as configuring access to your private code repositories through Developer Connect.
You can choose which repositories and even which files within those repositories are indexed to control the data used for code recommendations.
Code customization can be configured through the Google Cloud Console, Google Cloud CLI, or Terraform by creating an index and managing repository groups.
Indexing status can be checked through the Logs Explorer in the Console or by using the
gcloud logging readcommand in the CLI.Once set up, developers with appropriate access will receive code customization suggestions in their IDEs and can check the status.
Code customization can be turned off by deleting the index through the Console or by deleting repository groups and optionally the index using the CLI.
This document describes how to set upGemini Code Assist code customizationin the Google Cloud console, with the Google Cloud CLI, or withTerraform by connecting Gemini Code Assist to your private coderepositories. Gemini Code Assist code customization feature letsyou receive code recommendations, which draw from the internal libraries,private APIs, and coding style of your organization.
Before you begin
Verify that you have the following Identity and Access Management roles onthe project that owns the subscription:
- Code Repository Indexes Admin (
roles/cloudaicompanion.codeRepositoryIndexesAdmin) - Gemini for Google Cloud User (
roles/cloudaicompanion.user)
- Code Repository Indexes Admin (
Create or configure user accounts. Every developer in your organizationwho is using Gemini Code Assist must have a user identity inGoogle Cloud that has permission to access your Google Cloud project.For more information, seeGrant roles in the Google Cloud console.Verify each user has the following roles:
The code customization feature uses Developer Connect toaccess and index your private repositories. Ensure that theDeveloper Connect region where yourDeveloper Connect repository connection is located is also asupported location for code customization. The code customizationfeature cannot be used if the Developer Connect connection isin an unsupported region. For the list of supported regions, seecode customization limitations.
Choose which repositories are indexed
As a best practice, you should index repositories that have the followingcharacteristics:
- Code that's of a similar style or structure to what you want yourdevelopers to write.
- Private libraries or APIs that you would like to call from your currentcodebase.
Optional: Choose which files are not indexed
By default, code customization indexes all thesupported code filesin your specified repositories.
To prevent exposure of code that you don't want to index, you can use branchpatterns tocontrol access to your indexand use a stable branch, such asmain.
Alternatively, you can also exclude files from the index bycreating an.aiexclude file.
Configure Gemini Code Assist code customization
Select one of the following options:
Console
In the Google Cloud console, go to theCode Customization page.
Go to Code customization for Gemini Code Assist
TheCode customization for Gemini Code Assist page loads.
Create an index. Code customization relies on an index to analyze and parseyour repository for quicker code generation suggestions and lookups.
ClickCreate and configure the index details:
- Select the region that is configured inDeveloper Connect in your Cloud project.
- Enter a name for your index. Note your index name. You needit for several steps in this document.
ClickCreate.
Index creation generally takes 30 minutes to complete, but it might takeup to an hour. When indexing completes, you receive a notification inthe Google Cloud console.
Google limits the number of code repository indexes to one for eachproject and organization.
Control access to your index using repository groups.
A repository group is a container for the indexing configuration, whichincludes repositories and their branch patterns. Repository groups aredesigned for granular IAM control, giving developers accessto the indexed data from those groups, where they have the
cloudaicompanion.repositoryGroups.usepermission.Repository groups contain Developer Connect repositories,or links, from the same project and location.
On theCode customization for Gemini Code Assist page, clickAdd repositories, and then selectAdd source repositories.
A list displays of existing repositories in Developer Connect forthe region you configured in the previous step to create the index.
If you need to add new repositories to the repository group, then clickLink repository and follow the steps in the Google Cloud console.
Additionally, you can select and then edit one or more repositories to adda new branch.
Select the repository group to which you want to add new repositories.Alternatively, clickCreate a new repository group to create andconfigure a new repository group.
To begin indexing the selected repositories, clickIndex.
Indexing time varies depending on the size of repositories.
CLI
- Verify that you have configuredDeveloper Connectand connected to your repository:
In a shell environment, run the
gcloud components updatecommandto verify that you have updated all installed components of thegcloud to the latest version.For this step, you can install and initialize the gcloud, oryou can useCloud Shell Editor.gcloudcomponentsupdateCreate an index. Code customization relies on an index to analyze and parseyour repository for quicker code generation suggestions and lookups.
To create the index, in a shell environment, use the
gemini code-repository-indexes createcommand:gcloud gemini code-repository-indexes createINDEX_NAME \ --project=PROJECT_ID \ --location=REGIONReplace the following:
INDEX_NAME: your index name.Important:Note your index name. You need it for several steps in thisdocument.PROJECT_ID: your Google Cloud project ID.REGION: the region that is configured inDeveloper Connect in your Cloud project.For commands to succeed, you must specify asupported region.
Index creation generally takes 30 minutes to complete, but it might takeup to an hour.
Google limits the number of code repository indexes to one for eachproject and organization.
Control access to your index using repository groups. A repository group isa container for the indexing configuration, which includes repositories andtheir branch patterns. Repository groups are designed for granularIAM control, giving developers access to the indexed datafrom those groups, where they have the
cloudaicompanion.repositoryGroups.usepermission.Repository groups contain Developer Connect repositories, orlinks, from the same project and location.
Administrators perform the following actions:
- Create the Code Repository Index resource.
- In the same project and location, configure a newDeveloper Connect connection.
- Link Git repos in the connection.
- Get links' resource names, pick branch pattern to index for eachlink, and put it to one or multiple repository groups.
To create a repository group, in a shell environment, use the
gemini code-repository-indexes repository-groups createcommand: Note: You can use regular expression inRE2 syntax to specifybranch names.gcloud gemini code-repository-indexes repository-groups createREPOSITORY_GROUP \ --project=PROJECT_ID \ --location=REGION \ --code-repository-index=INDEX_NAME \ --repositories='[{"resource": "REPOSITORY_RESOURCE_NAME", "branchPattern": "BRANCH_NAMES"}]'Replace the following:
REPOSITORY_GROUP: name of the repositorygroup, such asdefault.REPOSITORY_RESOURCE_NAME: name of therepository inside the Developer Connect connection.To find the name of the repository, go to theGit repositories pagein the Google Cloud console, and in theRepositories tab,look for the Connection ID under theConnection column in thetable. To copy the resource name, click themore_vert menu for more options,and selectCopy resource path.BRANCH_NAMES: name of the branches you wantto index, such asmain|dev.
You also can create a repository group with repositories defined in aJSON (or YAML) file, formatted as follows:
JSON
[{"resource":"REPOSITORY_RESOURCE_NAME","branchPattern":"main|dev"},{"resource":"REPOSITORY_RESOURCE_NAME","branchPattern":"dev"}]YAML
-resource:REPOSITORY_RESOURCE_NAMEbranchPattern:main|dev-resource:REPOSITORY_RESOURCE_NAMEbranchPattern:devTo create a repository group based on a JSON or YAML file, in a shellenvironment, use the
gemini code-repository-indexes repository-groups createcommand:JSON
gcloudgeminicode-repository-indexesrepository-groupscreateREPOSITORY_GROUP\--project=PROJECT_ID\--location=REGION\--code-repository-index=INDEX_NAME\--repositories=FILEPATH.jsonYAML
gcloudgeminicode-repository-indexesrepository-groupscreateREPOSITORY_GROUP\--project=PROJECT_ID\--location=REGION\--code-repository-index=INDEX_NAME\--repositories=FILEPATH.yamlIf preferred, you can encrypt and control your data with acustomer-managed encryption key (CMEK) throughCloud Key Management Service. To learn more about using aCMEK, seeEncrypt data with customer-managed encryption keys.
Grant IAM roles to the repository group on a project.
You only receive suggestions from repositories in the index. Eachrepository belongs to one or multiple repository groups. To accesssuggestions, you must grant the Cloud AI Companion Repository Groups UserIAM role(
roles/cloudaicompanion.repositoryGroupsUser)—which contains therequiredcloudaicompanion.repositoryGroups.userIAMpermission—to the repository group by one of the following ways:- Grant principals permission to access the entire index.
Grant principals access to a subset of the index.
Entire index
To bind an IAM policy for a project, in a shellenvironment, use the
projects add-iam-policy-bindingcommand:gcloudprojectsadd-iam-policy-bindingPROJECT_ID\--member='PRINCIPAL'\--role='roles/cloudaicompanion.repositoryGroupsUser'Replace the following:
PRINCIPAL: the email address of theprincipal that needs access—for example,user:test-user@gmail.comfor an individual, orgroup:admins@example.comfor a group.
For more information, see
gcloud projects set-iam-policy.When prompted to specify a condition, enter
None.
Subset of the index
You can create multiple repository groups and assignIAM roles to different IAM principals.
In order to set up an IAM policy, you must prepare theIAM policy JSON or YAML file, which will contain alist of IAM groups and assigned roles. For example:
bindings: - members: - group:my-group@example.com - user:test-user@example.com role: roles/cloudaicompanion.repositoryGroupsUserFor additional details and syntax, seeUnderstanding allow policies.
Note: You can assign custom roles to your IAM groups,but the custom role must contain all permissions of theroles/cloudaicompanion.repositoryGroupsUserrole.To set the IAM policy, in a shell environment, usethe
gemini code-repository-indexes repository-groups set-iam-policycommand:gcloud gemini code-repository-indexes repository-groups set-iam-policyGROUP_NAMEPOLICY_FILE \ --project=PROJECT_ID \ --location=REGION \ --code-repository-index=INDEX_NAMEReplace the following:
GROUP_NAME: the repository group name youcreated in a preceding step to control access to your index usingrepository groups.POLICY_FILE: the IAM policy.For more information, see
gcloud gemini code-repository-indexes repository-groups set-iam-policy.
Terraform
Verify that you have configuredDeveloper Connectand connected to your repository:
Create an index. Code customization relies on an index to analyze and parseyour repository for quicker code generation suggestions and lookups.
resource"google_gemini_code_repository_index""example"{location="REGION"code_repository_index_id="INDEX_NAME"}Replace the following:
INDEX_NAME: your index name.Important:Note your index name. You need it for several steps in this document.PROJECT_ID: your Google Cloud project ID.REGION: the region that is configured inDeveloper Connect in your Cloud project.For commands to succeed, you must specify asupported region.
Index creation generally takes 30 minutes to complete, but it might takeup to an hour.
Google limits the number of code repository indexes to one for eachproject and organization.
Control access to your index using repository groups. A repository groupis a container for the indexing configuration, which includes repositoriesand their branch patterns. Repository groups are designed for granularIAM control, giving developers access to the indexed datafrom those groups, where they have the
cloudaicompanion.repositoryGroups.usepermission.Repository groups contain Developer Connect repositories,or links, from the same project and location.
Administrators perform the following actions:
- Create Code the Repository Index resource.
- In the same project and location, configure a newDeveloper Connect connection.
- Link Git repos in the connection.
- Get links' resource names, pick branch pattern to index for each link,and put it to one or multiple repository groups.
Note: You can use regular expression inRE2 syntax to specify branchnames.resource"google_gemini_repository_group""example"{location="REGION"code_repository_index="INDEX_NAME"repository_group_id="REPOSITORY_GROUP"repositories{resource="REPOSITORY_RESOURCE_NAME"branch_pattern="BRANCH_NAMES"}}Replace the following:
REPOSITORY_GROUP: name of the repository group,such asdefault.REPOSITORY_RESOURCE_NAME: name of the repositoryinside the Developer Connect connection. To find the nameof the repository, go to theGit repositories pagein the Google Cloud console, and in theRepositories tab, lookfor the Connection ID under theConnection column in the table. Tocopy the resource name, click themore_vert menu for more options, andselectCopy resource path.BRANCH_NAMES: name of the branches you want toindex, such asmain|dev.
You also can create a repository group with repositories defined in a JSON(or YAML) file, formatted as follows:
JSON
[{"resource":"REPOSITORY_RESOURCE_NAME","branchPattern":"main|dev"},{"resource":"REPOSITORY_RESOURCE_NAME","branchPattern":"dev"}]YAML
-resource:REPOSITORY_RESOURCE_NAMEbranchPattern:main|dev-resource:REPOSITORY_RESOURCE_NAMEbranchPattern:devTo create a repository group based on a JSON or YAML file, in a shellenvironment, use the
gemini code-repository-indexes repository-groups createcommand:JSON
gcloudgeminicode-repository-indexesrepository-groupscreateREPOSITORY_GROUP\--project=PROJECT_ID\--location=REGION\--code-repository-index=INDEX_NAME\--repositories=FILEPATH.jsonYAML
gcloudgeminicode-repository-indexesrepository-groupscreateREPOSITORY_GROUP\--project=PROJECT_ID\--location=REGION\--code-repository-index=INDEX_NAME\--repositories=FILEPATH.yamlIf preferred, you can encrypt and control your data with acustomer-managed encryption key (CMEK) throughCloud Key Management Service. To learn more about using aCMEK, seeEncrypt data with customer-managed encryption keys.
Grant IAM roles to the repository group on a project.
You only receive suggestions from repositories in the index. Eachrepository belongs to one or multiple repository groups. To accesssuggestions, you must grant the Cloud AI Companion Repository Groups UserIAM role(
roles/cloudaicompanion.repositoryGroupsUser)—which contains therequiredcloudaicompanion.repositoryGroups.userIAMpermission—to the repository group by one of the following ways:- Grant principals permission to access the entire index.
Grant principals access to a subset of the index.
Entire index
To bind an IAM policy for a project, in a shellenvironment, use the
projects add-iam-policy-bindingcommand:gcloudprojectsadd-iam-policy-bindingPROJECT_ID\--member='PRINCIPAL'\--role='roles/cloudaicompanion.repositoryGroupsUser'Replace the following:
PRINCIPAL: the email address of theprincipal that needs access—for example,user:test-user@gmail.comfor an individual, orgroup:admins@example.comfor a group.For more information, see
gcloud projects set-iam-policy.
When prompted to specify a condition, enter
None.
Subset of the index
You can create multiple repository groups and assignIAM roles to different IAM principals.
data"google_iam_policy""foo"{binding{role="roles/cloudaicompanion.repositoryGroupsUser"members=["test-user@example.com"]}}resource"google_gemini_repository_group_iam_policy""foo"{project="PROJECT_ID"location="REGION"code_repository_index_id="INDEX_NAME"repository_group_id="GROUP_NAME"policy_data=data.google_iam_policy.foo.policy_data}data"google_gemini_repository_group_iam_policy""foo"{project="PROJECT_ID"location="REGION"code_repository_index_id="INDEX_NAME"repository_group_id="GROUP_NAME"depends_on=[google_gemini_repository_group_iam_policy.foo]}You can also create a binding:
resource"google_gemini_repository_group_iam_binding""foo"{project="PROJECT_ID"location="REGION"code_repository_index_id="INDEX_NAME"repository_group_id="GROUP_NAME"role="roles/cloudaicompanion.repositoryGroupsUser"members=["test-user@example.com"]}Replace the following:
GROUP_NAME: the repository group nameyou created in a preceding step to control access to your indexusing repository groups.
Check indexing status
Depending on the number of repositories you want to index and theirsize, indexing content can take up to 24 hours. For large repositories, indexingcan take longer. Indexing occurs once every 24 hours, picking up any changesthat were made in the repository.
Search for the
indexinglogs. For more information, seeLogging query language.Console
In the Google Cloud console, go to theLogs Explorer.
Use the log names filter to view
indexinglogs.
CLI
To search for the indexing logs, in a shell environment, use the
logging readcommand:gcloud logging read "logName="projects/PROJECT_ID/logs/indexing""Replace
PROJECT_IDwith the project ID wherethe repository group is located.For example, to view errors in the
indexinglogs, run the followingcommand:gcloud logging read "logName="projects/PROJECT_ID/logs/indexing" AND severity>=ERROR"Review the associated indexing statuses, such as the following:
- Start of repository indexing-for example,
Indexing repositoryREPOSITORY_NAME. Total number of repositories: 10, succeeded: 6, failed: 0. - End of individual repository indexing-for example:
- Success:
Successfully finished indexing repositoryREPOSITORY_NAME. Total number of repositories: 10, succeeded: 7, failed: 0. - Failure:
Failed to index repositoryREPOSITORY_NAME. Error: [<error message>]. Total number of repositories: 10, succeeded: 7, failed: 1.
- Success:
- End of repository indexing-for example:
- Success:
Finished indexing process. Repositories attempted: 10. Repositories successfully indexed: 9. Repositories unsuccessfully fetched: 0. - Failure:
Finished indexing process. Repositories attempted: 10. Repositories successfully indexed: 9. Repositories unsuccessfully fetched: 1. Repositories that were not successfully fetched will be retried in the next run.
- Success:
In the index statuses,
REPOSITORY_NAMEis the repositoryyou want to review.- Start of repository indexing-for example,
Review the associated indexing errors, such as the following:
- Failed to fetch repository.
- Failed to list repository files.
- Failed to retrieve repository information from the index.
- Failed to retrieve files from the index.
- Internal error.
Use code customization
Once you have set up code customization, you'll begin to see code completionand code generation suggestions which may be based on private code you haveindexed in addition to results from full codebase awareness.
Developers added to the repository group where at least one resource is indexedwill receive a notice in their IDE that code customization was enabled. To seethe code customization status, developers can click thesparkGemini symbol inthe bottom right corner and look for one of the following code customizationstatuses in the search bar:
- All set. Code customization is enabled and configured.
- Unavailable. The developer is missing repository group access or therepository group to which the user has access is empty.
- Unset. Code customization either isn't enabled or isn't configured by theadministrator.
To learn more about using code customization and best practices, seeUse code customization.
Turn off code customization
Select one of the following options:
Console
In the Google Cloud console, go to theGemini Products page.
TheGemini Products page loads.
In the navigation menu, clickCode customization.
TheCode customization page loads.
To delete the index, clickDelete.
A warning message is displayed. If you want to proceed and delete theindex, enter the index name, and then clickDelete.
CLI
To list all repository groups for the current index, in a shellenvironment, use the
gemini code-repository-indexes repository-groups listcommand:gcloud gemini code-repository-indexes repository-groups list --location=REGION \ --project=PROJECT_ID \ --code-repository-index=INDEX_NAME --uriReplace the following:
REGION: the region that is configured inDeveloper Connect in your Cloud project.For commands to succeed, you must specify asupported region.PROJECT_ID: your Google Cloud project ID.INDEX_NAME: name of the index you created in apreceding step to create an index.
To delete a repository group from the current index, use the
gemini code-repository-indexes repository-groups deletecommand:gcloud gemini code-repository-indexes repository-groups deleteREPOSITORY_GROUP \ --location=REGION \ --project=PROJECT_ID \ --code-repository-index=INDEX_NAMERepeat the preceding steps for each repository group until you delete allrepository groups from the index.
Optional: To delete the index, in a shell environment, use the
gemini code-repository-indexes deletecommand:gcloud gemini code-repository-indexes deleteINDEX_NAME \ --location=REGION \ --project=PROJECT_ID
What's next
- Start using Gemini Code Assist:
- VS Code, IntelliJ, and other supported JetBrains IDEs:Code with Gemini Code Assist
- Cloud Shell:Code with Gemini Code Assist
- Cloud Workstations:Code with Gemini Code Assist
- Learn how touse code customizationand best practices.
- Learn how toencrypt data with customer-managed encryption keys (CMEK).
- Learn more aboutDeveloper Connect.
- Learnhow and when Gemini for Google Cloud uses your data.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-10 UTC.