docs: add Windows PowerShell equivalents for environments and scripting (#20333)

This commit is contained in:
Tommaso Sciortino
2026-02-27 15:41:47 -08:00
committed by GitHub
parent 08ee136132
commit c89d4f9c6c
18 changed files with 434 additions and 34 deletions
+12 -12
View File
@@ -5,18 +5,18 @@ and parameters.
## CLI commands ## CLI commands
| Command | Description | Example | | Command | Description | Example |
| ---------------------------------- | ---------------------------------- | --------------------------------------------------- | | ---------------------------------- | ---------------------------------- | ------------------------------------------------------------ |
| `gemini` | Start interactive REPL | `gemini` | | `gemini` | Start interactive REPL | `gemini` |
| `gemini "query"` | Query non-interactively, then exit | `gemini "explain this project"` | | `gemini "query"` | Query non-interactively, then exit | `gemini "explain this project"` |
| `cat file \| gemini` | Process piped content | `cat logs.txt \| gemini` | | `cat file \| gemini` | Process piped content | `cat logs.txt \| gemini`<br>`Get-Content logs.txt \| gemini` |
| `gemini -i "query"` | Execute and continue interactively | `gemini -i "What is the purpose of this project?"` | | `gemini -i "query"` | Execute and continue interactively | `gemini -i "What is the purpose of this project?"` |
| `gemini -r "latest"` | Continue most recent session | `gemini -r "latest"` | | `gemini -r "latest"` | Continue most recent session | `gemini -r "latest"` |
| `gemini -r "latest" "query"` | Continue session with a new prompt | `gemini -r "latest" "Check for type errors"` | | `gemini -r "latest" "query"` | Continue session with a new prompt | `gemini -r "latest" "Check for type errors"` |
| `gemini -r "<session-id>" "query"` | Resume session by ID | `gemini -r "abc123" "Finish this PR"` | | `gemini -r "<session-id>" "query"` | Resume session by ID | `gemini -r "abc123" "Finish this PR"` |
| `gemini update` | Update to latest version | `gemini update` | | `gemini update` | Update to latest version | `gemini update` |
| `gemini extensions` | Manage extensions | See [Extensions Management](#extensions-management) | | `gemini extensions` | Manage extensions | See [Extensions Management](#extensions-management) |
| `gemini mcp` | Configure MCP servers | See [MCP Server Management](#mcp-server-management) | | `gemini mcp` | Configure MCP servers | See [MCP Server Management](#mcp-server-management) |
### Positional arguments ### Positional arguments
+9
View File
@@ -278,11 +278,20 @@ Let's create a global command that asks the model to refactor a piece of code.
First, ensure the user commands directory exists, then create a `refactor` First, ensure the user commands directory exists, then create a `refactor`
subdirectory for organization and the final TOML file. subdirectory for organization and the final TOML file.
**macOS/Linux**
```bash ```bash
mkdir -p ~/.gemini/commands/refactor mkdir -p ~/.gemini/commands/refactor
touch ~/.gemini/commands/refactor/pure.toml touch ~/.gemini/commands/refactor/pure.toml
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.gemini\commands\refactor"
New-Item -ItemType File -Force -Path "$env:USERPROFILE\.gemini\commands\refactor\pure.toml"
```
**2. Add the content to the file:** **2. Add the content to the file:**
Open `~/.gemini/commands/refactor/pure.toml` in your editor and add the Open `~/.gemini/commands/refactor/pure.toml` in your editor and add the
+19
View File
@@ -203,6 +203,15 @@ with the actual Gemini CLI process, which inherits the environment variable.
This makes it significantly more difficult for a user to bypass the enforced This makes it significantly more difficult for a user to bypass the enforced
settings. settings.
**PowerShell Profile (Windows alternative):**
On Windows, administrators can achieve similar results by adding the environment
variable to the system-wide or user-specific PowerShell profile:
```powershell
Add-Content -Path $PROFILE -Value '$env:GEMINI_CLI_SYSTEM_SETTINGS_PATH="C:\ProgramData\gemini-cli\settings.json"'
```
## User isolation in shared environments ## User isolation in shared environments
In shared compute environments (like ML experiment runners or shared build In shared compute environments (like ML experiment runners or shared build
@@ -214,12 +223,22 @@ use the `GEMINI_CLI_HOME` environment variable to point to a unique directory
for a specific user or job. The CLI will create a `.gemini` folder inside the for a specific user or job. The CLI will create a `.gemini` folder inside the
specified path. specified path.
**macOS/Linux**
```bash ```bash
# Isolate state for a specific job # Isolate state for a specific job
export GEMINI_CLI_HOME="/tmp/gemini-job-123" export GEMINI_CLI_HOME="/tmp/gemini-job-123"
gemini gemini
``` ```
**Windows (PowerShell)**
```powershell
# Isolate state for a specific job
$env:GEMINI_CLI_HOME="C:\temp\gemini-job-123"
gemini
```
## Restricting tool access ## Restricting tool access
You can significantly enhance security by controlling which tools the Gemini You can significantly enhance security by controlling which tools the Gemini
+42 -2
View File
@@ -55,12 +55,27 @@ from your organization's registry.
```bash ```bash
# Enable sandboxing with command flag # Enable sandboxing with command flag
gemini -s -p "analyze the code structure" gemini -s -p "analyze the code structure"
```
# Use environment variable **Use environment variable**
**macOS/Linux**
```bash
export GEMINI_SANDBOX=true export GEMINI_SANDBOX=true
gemini -p "run the test suite" gemini -p "run the test suite"
```
# Configure in settings.json **Windows (PowerShell)**
```powershell
$env:GEMINI_SANDBOX="true"
gemini -p "run the test suite"
```
**Configure in settings.json**
```json
{ {
"tools": { "tools": {
"sandbox": "docker" "sandbox": "docker"
@@ -99,26 +114,51 @@ use cases.
To disable SELinux labeling for volume mounts, you can set the following: To disable SELinux labeling for volume mounts, you can set the following:
**macOS/Linux**
```bash ```bash
export SANDBOX_FLAGS="--security-opt label=disable" export SANDBOX_FLAGS="--security-opt label=disable"
``` ```
**Windows (PowerShell)**
```powershell
$env:SANDBOX_FLAGS="--security-opt label=disable"
```
Multiple flags can be provided as a space-separated string: Multiple flags can be provided as a space-separated string:
**macOS/Linux**
```bash ```bash
export SANDBOX_FLAGS="--flag1 --flag2=value" export SANDBOX_FLAGS="--flag1 --flag2=value"
``` ```
**Windows (PowerShell)**
```powershell
$env:SANDBOX_FLAGS="--flag1 --flag2=value"
```
## Linux UID/GID handling ## Linux UID/GID handling
The sandbox automatically handles user permissions on Linux. Override these The sandbox automatically handles user permissions on Linux. Override these
permissions with: permissions with:
**macOS/Linux**
```bash ```bash
export SANDBOX_SET_UID_GID=true # Force host UID/GID export SANDBOX_SET_UID_GID=true # Force host UID/GID
export SANDBOX_SET_UID_GID=false # Disable UID/GID mapping export SANDBOX_SET_UID_GID=false # Disable UID/GID mapping
``` ```
**Windows (PowerShell)**
```powershell
$env:SANDBOX_SET_UID_GID="true" # Force host UID/GID
$env:SANDBOX_SET_UID_GID="false" # Disable UID/GID mapping
```
## Troubleshooting ## Troubleshooting
### Common issues ### Common issues
+29
View File
@@ -103,23 +103,52 @@ Before using either method below, complete these steps:
1. Set your Google Cloud project ID: 1. Set your Google Cloud project ID:
- For telemetry in a separate project from inference: - For telemetry in a separate project from inference:
**macOS/Linux**
```bash ```bash
export OTLP_GOOGLE_CLOUD_PROJECT="your-telemetry-project-id" export OTLP_GOOGLE_CLOUD_PROJECT="your-telemetry-project-id"
``` ```
**Windows (PowerShell)**
```powershell
$env:OTLP_GOOGLE_CLOUD_PROJECT="your-telemetry-project-id"
```
- For telemetry in the same project as inference: - For telemetry in the same project as inference:
**macOS/Linux**
```bash ```bash
export GOOGLE_CLOUD_PROJECT="your-project-id" export GOOGLE_CLOUD_PROJECT="your-project-id"
``` ```
**Windows (PowerShell)**
```powershell
$env:GOOGLE_CLOUD_PROJECT="your-project-id"
```
2. Authenticate with Google Cloud: 2. Authenticate with Google Cloud:
- If using a user account: - If using a user account:
```bash ```bash
gcloud auth application-default login gcloud auth application-default login
``` ```
- If using a service account: - If using a service account:
**macOS/Linux**
```bash ```bash
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account.json" export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account.json"
``` ```
**Windows (PowerShell)**
```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\your\service-account.json"
```
3. Make sure your account or service account has these IAM roles: 3. Make sure your account or service account has these IAM roles:
- Cloud Trace Agent - Cloud Trace Agent
- Monitoring Metric Writer - Monitoring Metric Writer
+101 -5
View File
@@ -37,10 +37,18 @@ output.
Pipe a file: Pipe a file:
**macOS/Linux**
```bash ```bash
cat error.log | gemini "Explain why this failed" cat error.log | gemini "Explain why this failed"
``` ```
**Windows (PowerShell)**
```powershell
Get-Content error.log | gemini "Explain why this failed"
```
Pipe a command: Pipe a command:
```bash ```bash
@@ -57,7 +65,10 @@ results to a file.
You have a folder of Python scripts and want to generate a `README.md` for each You have a folder of Python scripts and want to generate a `README.md` for each
one. one.
1. Save the following code as `generate_docs.sh`: 1. Save the following code as `generate_docs.sh` (or `generate_docs.ps1` for
Windows):
**macOS/Linux (`generate_docs.sh`)**
```bash ```bash
#!/bin/bash #!/bin/bash
@@ -72,13 +83,34 @@ one.
done done
``` ```
**Windows PowerShell (`generate_docs.ps1`)**
```powershell
# Loop through all Python files
Get-ChildItem -Filter *.py | ForEach-Object {
Write-Host "Generating docs for $($_.Name)..."
$newName = $_.Name -replace '\.py$', '.md'
# Ask Gemini CLI to generate the documentation and print it to stdout
gemini "Generate a Markdown documentation summary for @$($_.Name). Print the result to standard output." | Out-File -FilePath $newName -Encoding utf8
}
```
2. Make the script executable and run it in your directory: 2. Make the script executable and run it in your directory:
**macOS/Linux**
```bash ```bash
chmod +x generate_docs.sh chmod +x generate_docs.sh
./generate_docs.sh ./generate_docs.sh
``` ```
**Windows (PowerShell)**
```powershell
.\generate_docs.ps1
```
This creates a corresponding Markdown file for every Python file in the This creates a corresponding Markdown file for every Python file in the
folder. folder.
@@ -90,7 +122,10 @@ like `jq`. To get pure JSON data from the model, combine the
### Scenario: Extract and return structured data ### Scenario: Extract and return structured data
1. Save the following script as `generate_json.sh`: 1. Save the following script as `generate_json.sh` (or `generate_json.ps1` for
Windows):
**macOS/Linux (`generate_json.sh`)**
```bash ```bash
#!/bin/bash #!/bin/bash
@@ -105,13 +140,35 @@ like `jq`. To get pure JSON data from the model, combine the
gemini --output-format json "Return a raw JSON object with keys 'version' and 'deps' from @package.json" | jq -r '.response' > data.json gemini --output-format json "Return a raw JSON object with keys 'version' and 'deps' from @package.json" | jq -r '.response' > data.json
``` ```
2. Run `generate_json.sh`: **Windows PowerShell (`generate_json.ps1`)**
```powershell
# Ensure we are in a project root
if (-not (Test-Path "package.json")) {
Write-Error "Error: package.json not found."
exit 1
}
# Extract data (requires jq installed, or you can use ConvertFrom-Json)
$output = gemini --output-format json "Return a raw JSON object with keys 'version' and 'deps' from @package.json" | ConvertFrom-Json
$output.response | Out-File -FilePath data.json -Encoding utf8
```
2. Run the script:
**macOS/Linux**
```bash ```bash
chmod +x generate_json.sh chmod +x generate_json.sh
./generate_json.sh ./generate_json.sh
``` ```
**Windows (PowerShell)**
```powershell
.\generate_json.ps1
```
3. Check `data.json`. The file should look like this: 3. Check `data.json`. The file should look like this:
```json ```json
@@ -129,8 +186,10 @@ Use headless mode to perform custom, automated AI tasks.
### Scenario: Create a "Smart Commit" alias ### Scenario: Create a "Smart Commit" alias
You can add a function to your shell configuration (like `.zshrc` or `.bashrc`) You can add a function to your shell configuration to create a `git commit`
to create a `git commit` wrapper that writes the message for you. wrapper that writes the message for you.
**macOS/Linux (Bash/Zsh)**
1. Open your `.zshrc` file (or `.bashrc` if you use Bash) in your preferred 1. Open your `.zshrc` file (or `.bashrc` if you use Bash) in your preferred
text editor. text editor.
@@ -170,6 +229,43 @@ to create a `git commit` wrapper that writes the message for you.
source ~/.zshrc source ~/.zshrc
``` ```
**Windows (PowerShell)**
1. Open your PowerShell profile in your preferred text editor.
```powershell
notepad $PROFILE
```
2. Scroll to the very bottom of the file and paste this code:
```powershell
function gcommit {
# Get the diff of staged changes
$diff = git diff --staged
if (-not $diff) {
Write-Host "No staged changes to commit."
return
}
# Ask Gemini to write the message
Write-Host "Generating commit message..."
$msg = $diff | gemini "Write a concise Conventional Commit message for this diff. Output ONLY the message."
# Commit with the generated message
git commit -m "$msg"
}
```
Save your file and exit.
3. Run this command to make the function available immediately:
```powershell
. $PROFILE
```
4. Use your new command: 4. Use your new command:
```bash ```bash
+8
View File
@@ -20,10 +20,18 @@ Most MCP servers require authentication. For GitHub, you need a PAT.
**Read/Write** access to **Issues** and **Pull Requests**. **Read/Write** access to **Issues** and **Pull Requests**.
3. Store it in your environment: 3. Store it in your environment:
**macOS/Linux**
```bash ```bash
export GITHUB_PERSONAL_ACCESS_TOKEN="github_pat_..." export GITHUB_PERSONAL_ACCESS_TOKEN="github_pat_..."
``` ```
**Windows (PowerShell)**
```powershell
$env:GITHUB_PERSONAL_ACCESS_TOKEN="github_pat_..."
```
## How to configure Gemini CLI ## How to configure Gemini CLI
You tell Gemini about new servers by editing your `settings.json`. You tell Gemini about new servers by editing your `settings.json`.
@@ -14,10 +14,18 @@ responding correctly.
1. Run the following command to create the folders: 1. Run the following command to create the folders:
**macOS/Linux**
```bash ```bash
mkdir -p .gemini/skills/api-auditor/scripts mkdir -p .gemini/skills/api-auditor/scripts
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path ".gemini\skills\api-auditor\scripts"
```
### Create the definition ### Create the definition
1. Create a file at `.gemini/skills/api-auditor/SKILL.md`. This tells the agent 1. Create a file at `.gemini/skills/api-auditor/SKILL.md`. This tells the agent
+16
View File
@@ -189,10 +189,18 @@ Custom commands create shortcuts for complex prompts.
1. Create a `commands` directory and a subdirectory for your command group: 1. Create a `commands` directory and a subdirectory for your command group:
**macOS/Linux**
```bash ```bash
mkdir -p commands/fs mkdir -p commands/fs
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path "commands\fs"
```
2. Create a file named `commands/fs/grep-code.toml`: 2. Create a file named `commands/fs/grep-code.toml`:
```toml ```toml
@@ -252,10 +260,18 @@ Skills are activated only when needed, which saves context tokens.
1. Create a `skills` directory and a subdirectory for your skill: 1. Create a `skills` directory and a subdirectory for your skill:
**macOS/Linux**
```bash ```bash
mkdir -p skills/security-audit mkdir -p skills/security-audit
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path "skills\security-audit"
```
2. Create a `skills/security-audit/SKILL.md` file: 2. Create a `skills/security-audit/SKILL.md` file:
```markdown ```markdown
+86 -5
View File
@@ -78,11 +78,20 @@ To authenticate and use Gemini CLI with a Gemini API key:
2. Set the `GEMINI_API_KEY` environment variable to your key. For example: 2. Set the `GEMINI_API_KEY` environment variable to your key. For example:
**macOS/Linux**
```bash ```bash
# Replace YOUR_GEMINI_API_KEY with the key from AI Studio # Replace YOUR_GEMINI_API_KEY with the key from AI Studio
export GEMINI_API_KEY="YOUR_GEMINI_API_KEY" export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
``` ```
**Windows (PowerShell)**
```powershell
# Replace YOUR_GEMINI_API_KEY with the key from AI Studio
$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
```
To make this setting persistent, see To make this setting persistent, see
[Persisting Environment Variables](#persisting-vars). [Persisting Environment Variables](#persisting-vars).
@@ -114,12 +123,22 @@ or the location where you want to run your jobs.
For example: For example:
**macOS/Linux**
```bash ```bash
# Replace with your project ID and desired location (e.g., us-central1) # Replace with your project ID and desired location (e.g., us-central1)
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID" export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION" export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"
``` ```
**Windows (PowerShell)**
```powershell
# Replace with your project ID and desired location (e.g., us-central1)
$env:GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
$env:GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"
```
To make any Vertex AI environment variable settings persistent, see To make any Vertex AI environment variable settings persistent, see
[Persisting Environment Variables](#persisting-vars). [Persisting Environment Variables](#persisting-vars).
@@ -130,9 +149,17 @@ Consider this authentication method if you have Google Cloud CLI installed.
> **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you > **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you
> must unset them to use ADC: > must unset them to use ADC:
> >
> **macOS/Linux**
>
> ```bash > ```bash
> unset GOOGLE_API_KEY GEMINI_API_KEY > unset GOOGLE_API_KEY GEMINI_API_KEY
> ``` > ```
>
> **Windows (PowerShell)**
>
> ```powershell
> Remove-Item Env:\GOOGLE_API_KEY, Env:\GEMINI_API_KEY -ErrorAction Ignore
> ```
1. Verify you have a Google Cloud project and Vertex AI API is enabled. 1. Verify you have a Google Cloud project and Vertex AI API is enabled.
@@ -160,9 +187,17 @@ pipelines, or if your organization restricts user-based ADC or API key creation.
> **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you > **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you
> must unset them: > must unset them:
> >
> **macOS/Linux**
>
> ```bash > ```bash
> unset GOOGLE_API_KEY GEMINI_API_KEY > unset GOOGLE_API_KEY GEMINI_API_KEY
> ``` > ```
>
> **Windows (PowerShell)**
>
> ```powershell
> Remove-Item Env:\GOOGLE_API_KEY, Env:\GEMINI_API_KEY -ErrorAction Ignore
> ```
1. [Create a service account and key](https://cloud.google.com/iam/docs/keys-create-delete) 1. [Create a service account and key](https://cloud.google.com/iam/docs/keys-create-delete)
and download the provided JSON file. Assign the "Vertex AI User" role to the and download the provided JSON file. Assign the "Vertex AI User" role to the
@@ -171,11 +206,20 @@ pipelines, or if your organization restricts user-based ADC or API key creation.
2. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the JSON 2. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the JSON
file's absolute path. For example: file's absolute path. For example:
**macOS/Linux**
```bash ```bash
# Replace /path/to/your/keyfile.json with the actual path # Replace /path/to/your/keyfile.json with the actual path
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/keyfile.json" export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/keyfile.json"
``` ```
**Windows (PowerShell)**
```powershell
# Replace C:\path\to\your\keyfile.json with the actual path
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\your\keyfile.json"
```
3. [Configure your Google Cloud Project](#set-gcp). 3. [Configure your Google Cloud Project](#set-gcp).
4. Start the CLI: 4. Start the CLI:
@@ -195,11 +239,20 @@ pipelines, or if your organization restricts user-based ADC or API key creation.
2. Set the `GOOGLE_API_KEY` environment variable: 2. Set the `GOOGLE_API_KEY` environment variable:
**macOS/Linux**
```bash ```bash
# Replace YOUR_GOOGLE_API_KEY with your Vertex AI API key # Replace YOUR_GOOGLE_API_KEY with your Vertex AI API key
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY" export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
``` ```
**Windows (PowerShell)**
```powershell
# Replace YOUR_GOOGLE_API_KEY with your Vertex AI API key
$env:GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
```
> **Note:** If you see errors like > **Note:** If you see errors like
> `"API keys are not supported by this API..."`, your organization might > `"API keys are not supported by this API..."`, your organization might
> restrict API key usage for this service. Try the other Vertex AI > restrict API key usage for this service. Try the other Vertex AI
@@ -243,11 +296,20 @@ To configure Gemini CLI to use a Google Cloud project, do the following:
For example, to set the `GOOGLE_CLOUD_PROJECT_ID` variable: For example, to set the `GOOGLE_CLOUD_PROJECT_ID` variable:
**macOS/Linux**
```bash ```bash
# Replace YOUR_PROJECT_ID with your actual Google Cloud project ID # Replace YOUR_PROJECT_ID with your actual Google Cloud project ID
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID" export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
``` ```
**Windows (PowerShell)**
```powershell
# Replace YOUR_PROJECT_ID with your actual Google Cloud project ID
$env:GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
```
To make this setting persistent, see To make this setting persistent, see
[Persisting Environment Variables](#persisting-vars). [Persisting Environment Variables](#persisting-vars).
@@ -257,16 +319,22 @@ To avoid setting environment variables for every terminal session, you can
persist them with the following methods: persist them with the following methods:
1. **Add your environment variables to your shell configuration file:** Append 1. **Add your environment variables to your shell configuration file:** Append
the `export ...` commands to your shell's startup file (e.g., `~/.bashrc`, the environment variable commands to your shell's startup file.
`~/.zshrc`, or `~/.profile`) and reload your shell (e.g.,
`source ~/.bashrc`). **macOS/Linux** (e.g., `~/.bashrc`, `~/.zshrc`, or `~/.profile`):
```bash ```bash
# Example for .bashrc
echo 'export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"' >> ~/.bashrc echo 'export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"' >> ~/.bashrc
source ~/.bashrc source ~/.bashrc
``` ```
**Windows (PowerShell)** (e.g., `$PROFILE`):
```powershell
Add-Content -Path $PROFILE -Value '$env:GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"'
. $PROFILE
```
> **Warning:** Be aware that when you export API keys or service account > **Warning:** Be aware that when you export API keys or service account
> paths in your shell configuration file, any process launched from that > paths in your shell configuration file, any process launched from that
> shell can read them. > shell can read them.
@@ -274,10 +342,13 @@ persist them with the following methods:
2. **Use a `.env` file:** Create a `.gemini/.env` file in your project 2. **Use a `.env` file:** Create a `.gemini/.env` file in your project
directory or home directory. Gemini CLI automatically loads variables from directory or home directory. Gemini CLI automatically loads variables from
the first `.env` file it finds, searching up from the current directory, the first `.env` file it finds, searching up from the current directory,
then in `~/.gemini/.env` or `~/.env`. `.gemini/.env` is recommended. then in your home directory's `.gemini/.env` (e.g., `~/.gemini/.env` or
`%USERPROFILE%\.gemini\.env`).
Example for user-wide settings: Example for user-wide settings:
**macOS/Linux**
```bash ```bash
mkdir -p ~/.gemini mkdir -p ~/.gemini
cat >> ~/.gemini/.env <<'EOF' cat >> ~/.gemini/.env <<'EOF'
@@ -286,6 +357,16 @@ persist them with the following methods:
EOF EOF
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.gemini"
@"
GOOGLE_CLOUD_PROJECT="your-project-id"
# Add other variables like GEMINI_API_KEY as needed
"@ | Out-File -FilePath "$env:USERPROFILE\.gemini\.env" -Encoding utf8 -Append
```
Variables are loaded from the first file found, not merged. Variables are loaded from the first file found, not merged.
## Running in Google Cloud environments <a id="cloud-env"></a> ## Running in Google Cloud environments <a id="cloud-env"></a>
+1 -1
View File
@@ -13,7 +13,7 @@ installation methods, and release types.
- "Casual" usage: 4GB+ RAM (short sessions, common tasks and edits) - "Casual" usage: 4GB+ RAM (short sessions, common tasks and edits)
- "Power" usage: 16GB+ RAM (long sessions, large codebases, deep context) - "Power" usage: 16GB+ RAM (long sessions, large codebases, deep context)
- **Runtime:** Node.js 20.0.0+ - **Runtime:** Node.js 20.0.0+
- **Shell:** Bash or Zsh - **Shell:** Bash, Zsh, or PowerShell
- **Location:** - **Location:**
[Gemini Code Assist supported locations](https://developers.google.com/gemini-code-assist/resources/available-locations#americas) [Gemini Code Assist supported locations](https://developers.google.com/gemini-code-assist/resources/available-locations#americas)
- **Internet connection required** - **Internet connection required**
+33 -1
View File
@@ -167,6 +167,8 @@ try {
Run hook scripts manually with sample JSON input to verify they behave as Run hook scripts manually with sample JSON input to verify they behave as
expected before hooking them up to the CLI. expected before hooking them up to the CLI.
**macOS/Linux**
```bash ```bash
# Create test input # Create test input
cat > test-input.json << 'EOF' cat > test-input.json << 'EOF'
@@ -187,7 +189,30 @@ cat test-input.json | .gemini/hooks/my-hook.sh
# Check exit code # Check exit code
echo "Exit code: $?" echo "Exit code: $?"
```
**Windows (PowerShell)**
```powershell
# Create test input
@"
{
"session_id": "test-123",
"cwd": "C:\\temp\\test",
"hook_event_name": "BeforeTool",
"tool_name": "write_file",
"tool_input": {
"file_path": "test.txt",
"content": "Test content"
}
}
"@ | Out-File -FilePath test-input.json -Encoding utf8
# Test the hook
Get-Content test-input.json | .\.gemini\hooks\my-hook.ps1
# Check exit code
Write-Host "Exit code: $LASTEXITCODE"
``` ```
### Check exit codes ### Check exit codes
@@ -333,7 +358,7 @@ tool_name=$(echo "$input" | jq -r '.tool_name')
### Make scripts executable ### Make scripts executable
Always make hook scripts executable: Always make hook scripts executable on macOS/Linux:
```bash ```bash
chmod +x .gemini/hooks/*.sh chmod +x .gemini/hooks/*.sh
@@ -341,6 +366,10 @@ chmod +x .gemini/hooks/*.js
``` ```
**Windows Note**: On Windows, PowerShell scripts (`.ps1`) don't use `chmod`, but
you may need to ensure your execution policy allows them to run (e.g.,
`Set-ExecutionPolicy RemoteSigned -Scope CurrentUser`).
### Version control ### Version control
Commit hooks to share with your team: Commit hooks to share with your team:
@@ -481,6 +510,9 @@ ls -la .gemini/hooks/my-hook.sh
chmod +x .gemini/hooks/my-hook.sh chmod +x .gemini/hooks/my-hook.sh
``` ```
**Windows Note**: On Windows, ensure your execution policy allows running
scripts (e.g., `Get-ExecutionPolicy`).
**Verify script path:** Ensure the path in `settings.json` resolves correctly. **Verify script path:** Ensure the path in `settings.json` resolves correctly.
```bash ```bash
+24
View File
@@ -28,6 +28,8 @@ Create a directory for hooks and a simple logging script.
> This example uses `jq` to parse JSON. If you don't have it installed, you can > This example uses `jq` to parse JSON. If you don't have it installed, you can
> perform similar logic using Node.js or Python. > perform similar logic using Node.js or Python.
**macOS/Linux**
```bash ```bash
mkdir -p .gemini/hooks mkdir -p .gemini/hooks
cat > .gemini/hooks/log-tools.sh << 'EOF' cat > .gemini/hooks/log-tools.sh << 'EOF'
@@ -52,6 +54,28 @@ EOF
chmod +x .gemini/hooks/log-tools.sh chmod +x .gemini/hooks/log-tools.sh
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path ".gemini\hooks"
@"
# Read hook input from stdin
`$inputJson = `$input | Out-String | ConvertFrom-Json
# Extract tool name
`$toolName = `$inputJson.tool_name
# Log to stderr (visible in terminal if hook fails, or captured in logs)
[Console]::Error.WriteLine("Logging tool: `$toolName")
# Log to file
"[`$(Get-Date -Format 'o')] Tool executed: `$toolName" | Out-File -FilePath ".gemini\tool-log.txt" -Append -Encoding utf8
# Return success with empty JSON
"{}"
"@ | Out-File -FilePath ".gemini\hooks\log-tools.ps1" -Encoding utf8
```
## Exit Code Strategies ## Exit Code Strategies
There are two ways to control or block an action in Gemini CLI: There are two ways to control or block an action in Gemini CLI:
+8
View File
@@ -177,10 +177,18 @@ standalone terminal and want to manually associate it with a specific IDE
instance, you can set the `GEMINI_CLI_IDE_PID` environment variable to the instance, you can set the `GEMINI_CLI_IDE_PID` environment variable to the
process ID (PID) of your IDE. process ID (PID) of your IDE.
**macOS/Linux**
```bash ```bash
export GEMINI_CLI_IDE_PID=12345 export GEMINI_CLI_IDE_PID=12345
``` ```
**Windows (PowerShell)**
```powershell
$env:GEMINI_CLI_IDE_PID=12345
```
When this variable is set, Gemini CLI will skip automatic detection and attempt When this variable is set, Gemini CLI will skip automatic detection and attempt
to connect using the provided PID. to connect using the provided PID.
+16 -7
View File
@@ -1332,7 +1332,8 @@ the `advanced.excludedEnvVars` setting in your `settings.json` file.
- **`GEMINI_MODEL`**: - **`GEMINI_MODEL`**:
- Specifies the default Gemini model to use. - Specifies the default Gemini model to use.
- Overrides the hardcoded default - Overrides the hardcoded default
- Example: `export GEMINI_MODEL="gemini-3-flash-preview"` - Example: `export GEMINI_MODEL="gemini-3-flash-preview"` (Windows PowerShell:
`$env:GEMINI_MODEL="gemini-3-flash-preview"`)
- **`GEMINI_CLI_IDE_PID`**: - **`GEMINI_CLI_IDE_PID`**:
- Manually specifies the PID of the IDE process to use for integration. This - Manually specifies the PID of the IDE process to use for integration. This
is useful when running Gemini CLI in a standalone terminal while still is useful when running Gemini CLI in a standalone terminal while still
@@ -1344,12 +1345,14 @@ the `advanced.excludedEnvVars` setting in your `settings.json` file.
- By default, this is the user's system home directory. The CLI will create a - By default, this is the user's system home directory. The CLI will create a
`.gemini` folder inside this directory. `.gemini` folder inside this directory.
- Useful for shared compute environments or keeping CLI state isolated. - Useful for shared compute environments or keeping CLI state isolated.
- Example: `export GEMINI_CLI_HOME="/path/to/user/config"` - Example: `export GEMINI_CLI_HOME="/path/to/user/config"` (Windows
PowerShell: `$env:GEMINI_CLI_HOME="C:\path\to\user\config"`)
- **`GOOGLE_API_KEY`**: - **`GOOGLE_API_KEY`**:
- Your Google Cloud API key. - Your Google Cloud API key.
- Required for using Vertex AI in express mode. - Required for using Vertex AI in express mode.
- Ensure you have the necessary permissions. - Ensure you have the necessary permissions.
- Example: `export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"`. - Example: `export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"` (Windows PowerShell:
`$env:GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"`).
- **`GOOGLE_CLOUD_PROJECT`**: - **`GOOGLE_CLOUD_PROJECT`**:
- Your Google Cloud Project ID. - Your Google Cloud Project ID.
- Required for using Code Assist or Vertex AI. - Required for using Code Assist or Vertex AI.
@@ -1360,18 +1363,23 @@ the `advanced.excludedEnvVars` setting in your `settings.json` file.
you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud
Shell, it will be overridden by this default. To use a different project in Shell, it will be overridden by this default. To use a different project in
Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file.
- Example: `export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - Example: `export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"` (Windows
PowerShell: `$env:GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`).
- **`GOOGLE_APPLICATION_CREDENTIALS`** (string): - **`GOOGLE_APPLICATION_CREDENTIALS`** (string):
- **Description:** The path to your Google Application Credentials JSON file. - **Description:** The path to your Google Application Credentials JSON file.
- **Example:** - **Example:**
`export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"` `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"`
(Windows PowerShell:
`$env:GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\your\credentials.json"`)
- **`GOOGLE_GENAI_API_VERSION`**: - **`GOOGLE_GENAI_API_VERSION`**:
- Specifies the API version to use for Gemini API requests. - Specifies the API version to use for Gemini API requests.
- When set, overrides the default API version used by the SDK. - When set, overrides the default API version used by the SDK.
- Example: `export GOOGLE_GENAI_API_VERSION="v1"` - Example: `export GOOGLE_GENAI_API_VERSION="v1"` (Windows PowerShell:
`$env:GOOGLE_GENAI_API_VERSION="v1"`)
- **`OTLP_GOOGLE_CLOUD_PROJECT`**: - **`OTLP_GOOGLE_CLOUD_PROJECT`**:
- Your Google Cloud Project ID for Telemetry in Google Cloud - Your Google Cloud Project ID for Telemetry in Google Cloud
- Example: `export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - Example: `export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"` (Windows
PowerShell: `$env:OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`).
- **`GEMINI_TELEMETRY_ENABLED`**: - **`GEMINI_TELEMETRY_ENABLED`**:
- Set to `true` or `1` to enable telemetry. Any other value is treated as - Set to `true` or `1` to enable telemetry. Any other value is treated as
disabling it. disabling it.
@@ -1399,7 +1407,8 @@ the `advanced.excludedEnvVars` setting in your `settings.json` file.
- **`GOOGLE_CLOUD_LOCATION`**: - **`GOOGLE_CLOUD_LOCATION`**:
- Your Google Cloud Project Location (e.g., us-central1). - Your Google Cloud Project Location (e.g., us-central1).
- Required for using Vertex AI in non-express mode. - Required for using Vertex AI in non-express mode.
- Example: `export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"`. - Example: `export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"` (Windows
PowerShell: `$env:GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"`).
- **`GEMINI_SANDBOX`**: - **`GEMINI_SANDBOX`**:
- Alternative to the `sandbox` setting in `settings.json`. - Alternative to the `sandbox` setting in `settings.json`.
- Accepts `true`, `false`, `docker`, `podman`, or a custom command string. - Accepts `true`, `false`, `docker`, `podman`, or a custom command string.
+10
View File
@@ -10,9 +10,19 @@ confirmation.
To create your first policy: To create your first policy:
1. **Create the policy directory** if it doesn't exist: 1. **Create the policy directory** if it doesn't exist:
**macOS/Linux**
```bash ```bash
mkdir -p ~/.gemini/policies mkdir -p ~/.gemini/policies
``` ```
**Windows (PowerShell)**
```powershell
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.gemini\policies"
```
2. **Create a new policy file** (e.g., `~/.gemini/policies/my-rules.toml`). You 2. **Create a new policy file** (e.g., `~/.gemini/policies/my-rules.toml`). You
can use any filename ending in `.toml`; all such files in this directory can use any filename ending in `.toml`; all such files in this directory
will be loaded and combined: will be loaded and combined:
+8
View File
@@ -88,10 +88,18 @@ You can configure your Google Cloud Project ID using an environment variable.
Set the `GOOGLE_CLOUD_PROJECT` environment variable in your shell: Set the `GOOGLE_CLOUD_PROJECT` environment variable in your shell:
**macOS/Linux**
```bash ```bash
export GOOGLE_CLOUD_PROJECT="your-project-id" export GOOGLE_CLOUD_PROJECT="your-project-id"
``` ```
**Windows (PowerShell)**
```powershell
$env:GOOGLE_CLOUD_PROJECT="your-project-id"
```
To make this setting permanent, add this line to your shell's startup file To make this setting permanent, add this line to your shell's startup file
(e.g., `~/.bashrc`, `~/.zshrc`). (e.g., `~/.bashrc`, `~/.zshrc`).
+4 -1
View File
@@ -55,10 +55,13 @@ topics on:
- Set the `NODE_USE_SYSTEM_CA=1` environment variable to tell Node.js to use - Set the `NODE_USE_SYSTEM_CA=1` environment variable to tell Node.js to use
the operating system's native certificate store (where corporate the operating system's native certificate store (where corporate
certificates are typically already installed). certificates are typically already installed).
- Example: `export NODE_USE_SYSTEM_CA=1` - Example: `export NODE_USE_SYSTEM_CA=1` (Windows PowerShell:
`$env:NODE_USE_SYSTEM_CA=1`)
- Set the `NODE_EXTRA_CA_CERTS` environment variable to the absolute path of - Set the `NODE_EXTRA_CA_CERTS` environment variable to the absolute path of
your corporate root CA certificate file. your corporate root CA certificate file.
- Example: `export NODE_EXTRA_CA_CERTS=/path/to/your/corporate-ca.crt` - Example: `export NODE_EXTRA_CA_CERTS=/path/to/your/corporate-ca.crt`
(Windows PowerShell:
`$env:NODE_EXTRA_CA_CERTS="C:\path\to\your\corporate-ca.crt"`)
## Common error messages and solutions ## Common error messages and solutions