<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 0xiPickL0x on Medium]]></title>
        <description><![CDATA[Stories by 0xiPickL0x on Medium]]></description>
        <link>https://medium.com/@Wile.E.Peyote?source=rss-77fb1a959e0f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Sivjo7hwP7jljGFcX_sR8g.jpeg</url>
            <title>Stories by 0xiPickL0x on Medium</title>
            <link>https://medium.com/@Wile.E.Peyote?source=rss-77fb1a959e0f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:26:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Wile.E.Peyote/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Run Multiple Gemini-CLI Accounts on Windows, A PowerShell Scripting Guide (Full Code)]]></title>
            <link>https://medium.com/@Wile.E.Peyote/run-multiple-gemini-cli-accounts-on-windows-guide-b197ef29e991?source=rss-77fb1a959e0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b197ef29e991</guid>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[google-gemini-cli]]></category>
            <category><![CDATA[gemini-cli]]></category>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[vibe-coding-tools]]></category>
            <dc:creator><![CDATA[0xiPickL0x]]></dc:creator>
            <pubDate>Sun, 29 Jun 2025 06:06:52 GMT</pubDate>
            <atom:updated>2025-07-01T22:35:42.999Z</atom:updated>
            <content:encoded><![CDATA[<p>By default, Gemini-CLI reads a single API key from environment variables, requiring manual updates to switch accounts. I will show how to build a PowerShell-based key management system that allows quick switching between multiple Gemini accounts and running concurrent authenticated sessions in different terminals.</p><p>Gemini-CLI <a href="https://github.com/google-gemini/gemini-cli/blob/19a9b50aab48394c579d885390438547a93044d2/docs/index.md">official documentation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkoD8ZhZY71y3aT6vpBURg.png" /><figcaption>Extract from official docs</figcaption></figure><h3>Prerequisites:</h3><ul><li>Windows 10/11 with PowerShell 5.1 or later</li><li>Latest Gemini-CLI installed (Follow instructions at <a href="https://github.com/google-gemini/gemini-cli/blob/main/docs/deployment.md#1-standard-installation-recommended-for-typical-users">https://github.com/google-gemini/gemini-cli/blob/main/docs/deployment.md#1-standard-installation-recommended-for-typical-users</a> )</li><li>At least one Google account with access to Google AI Studio</li><li>Administrator access to modify PATH variables (optional, for system-wide access)</li></ul><h3>Step 1. Setting up your API key store:</h3><ol><li>Go to <a href="https://aistudio.google.com/">https://aistudio.google.com/</a> and log in with the account you want to use with Gemini-cli</li><li>Click on the “Get Api Key” button</li><li>Click on the “+ Create API Key” button</li><li>Select your Google cloud project or follow the link to create a new one and wait a short time for it to be registered.</li><li>Copy your API key when it is generated.</li><li>Create a folder somewhere handy for your keystore (~\_GEMINI_KEYS for example)</li><li>Create a subfolder for the account you have created the API key for. Name it after the account as it will be displayed in your CLI menu when you run the script below.</li><li>Create a new text document in the subfolder for that account, insert your api key in the format: GEMINI_API_KEY=”APIKEYABCD1234” on the first line.</li><li>Save the text file as “.env”, NOT as “.env.txt”. On windows select “all files” when you are saving to avoid it appending the .txt extention.</li><li>Repeat for all accounts you want to run concurrently.</li></ol><h3>Step 2. Create and add `~\Tools\` to PATH in Windows 11 .</h3><ul><li>Press `Win + R`, type `sysdm.cpl`, press Enter.</li><li>Go to the <strong>Advanced</strong> tab. Click <strong>Environment Variables</strong>.<br><em>- In the Environment Variables window:</em></li><li><strong>User variables</strong> (top): Select `Path`, click <strong>Edit </strong>(modifies PATH for current user).</li><li><strong>System variables </strong>(bottom): Select `Path`, click <strong>Edit</strong> (modifies PATH for all users). <em>Only add the path here if you intend on using Gemini-cli in administrator shells.</em></li><li>- In the edit window, click <strong>New </strong>and enter:</li></ul><pre>C:\Users\&lt;YourUsername&gt;\Tools</pre><p>- Click **OK** on all dialogs to apply.</p><p><strong>Note:</strong><br>- Replace `&lt;YourUsername&gt;` with your Windows username. <br>- Restart applications to recognize the new PATH value.</p><h4>Creating the script:</h4><p>Create a new file called <strong>gemini-key-manager.ps1</strong> in the Tools folder you have just created in your User folder</p><p>Paste the following and save.</p><pre># Gemini API Key Manager<br># Manages GEMINI_API_KEY environment variable from account-specific .env files<br><br>param(<br>    [string]$KeysDirectory = &quot;~\_GEMINI_KEYS&quot;<br>)<br><br>function Show-Menu {<br>    param(<br>        [array]$AccountFolders,<br>        [string]$CurrentKey<br>    )<br>    <br>    Clear-Host<br>    Write-Host &quot;=== Gemini API Key Manager ===&quot; -ForegroundColor Cyan<br>    Write-Host &quot;&quot;<br>    <br>    # Show current key status<br>    if ($CurrentKey) {<br>        Write-Host &quot;Current GEMINI_API_KEY: &quot; -NoNewline -ForegroundColor Yellow<br>        Write-Host $CurrentKey.Substring(0, [Math]::Min(20, $CurrentKey.Length)) -NoNewline -ForegroundColor Green<br>        if ($CurrentKey.Length -gt 20) {<br>            Write-Host &quot;...&quot; -ForegroundColor Green<br>        } else {<br>            Write-Host &quot;&quot;<br>        }<br>        <br>        # Try to match current key to an account<br>        $matchedAccount = Get-AccountForKey -KeysDirectory $KeysDirectory -TargetKey $CurrentKey<br>        if ($matchedAccount) {<br>            Write-Host &quot;Matched Account: &quot; -NoNewline -ForegroundColor Yellow<br>            Write-Host $matchedAccount -ForegroundColor Green<br>        } else {<br>            Write-Host &quot;Account: &quot; -NoNewline -ForegroundColor Yellow<br>            Write-Host &quot;Unknown/Not from managed accounts&quot; -ForegroundColor Red<br>        }<br>    } else {<br>        Write-Host &quot;Current GEMINI_API_KEY: &quot; -NoNewline -ForegroundColor Yellow<br>        Write-Host &quot;Not set&quot; -ForegroundColor Red<br>    }<br>    <br>    Write-Host &quot;&quot;<br>    Write-Host &quot;Available Options:&quot; -ForegroundColor White<br>    Write-Host &quot;&quot;<br>    <br>    # Option 0: Show current key details<br>    Write-Host &quot;0. &quot; -NoNewline -ForegroundColor Cyan<br>    Write-Host &quot;Show current key details&quot;<br>    <br>    # List account folders<br>    for ($i = 0; $i -lt $AccountFolders.Count; $i++) {<br>        $optionNumber = $i + 1<br>        Write-Host &quot;$optionNumber. &quot; -NoNewline -ForegroundColor Cyan<br>        Write-Host $AccountFolders[$i].Name<br>    }<br>    <br>    Write-Host &quot;&quot;<br>    Write-Host &quot;q. &quot; -NoNewline -ForegroundColor Red<br>    Write-Host &quot;Quit&quot;<br>    Write-Host &quot;&quot;<br>}<br><br>function Get-AccountFolders {<br>    param([string]$KeysDirectory)<br>    <br>    if (-not (Test-Path $KeysDirectory)) {<br>        Write-Error &quot;Keys directory not found: $KeysDirectory&quot;<br>        return @()<br>    }<br>    <br>    $folders = Get-ChildItem -Path $KeysDirectory -Directory | Where-Object {<br>        Test-Path (Join-Path $_.FullName &quot;.env&quot;)<br>    }<br>    <br>    return $folders<br>}<br><br>function Get-ApiKeyFromEnvFile {<br>    param([string]$EnvFilePath)<br>    <br>    if (-not (Test-Path $EnvFilePath)) {<br>        Write-Error &quot;Environment file not found: $EnvFilePath&quot;<br>        return $null<br>    }<br>    <br>    try {<br>        $content = Get-Content $EnvFilePath -Raw<br>        <br>        # Match the pattern GEMINI_API_KEY=&quot;value&quot; or GEMINI_API_KEY=value<br>        if ($content -match &#39;GEMINI_API_KEY\s*=\s*&quot;?([^&quot;\r\n]+)&quot;?&#39;) {<br>            return $matches[1].Trim(&#39;&quot;&#39;)<br>        } else {<br>            Write-Warning &quot;GEMINI_API_KEY not found in $EnvFilePath&quot;<br>            return $null<br>        }<br>    } catch {<br>        Write-Error &quot;Error reading environment file: $_&quot;<br>        return $null<br>    }<br>}<br><br>function Set-GeminiApiKey {<br>    param(<br>        [string]$ApiKey,<br>        [string]$AccountName<br>    )<br>    <br>    try {<br>        # Set environment variable for current session<br>        $env:GEMINI_API_KEY = $ApiKey<br>        <br>        # Also set it for the current process<br>        [Environment]::SetEnvironmentVariable(&quot;GEMINI_API_KEY&quot;, $ApiKey, &quot;Process&quot;)<br>        <br>        Write-Host &quot;&quot;<br>        Write-Host &quot;✓ Successfully set GEMINI_API_KEY for account: &quot; -NoNewline -ForegroundColor Green<br>        Write-Host $AccountName -ForegroundColor Cyan<br>        Write-Host &quot;✓ Key preview: &quot; -NoNewline -ForegroundColor Green<br>        Write-Host $ApiKey.Substring(0, [Math]::Min(20, $ApiKey.Length)) -NoNewline -ForegroundColor Yellow<br>        if ($ApiKey.Length -gt 20) {<br>            Write-Host &quot;...&quot; -ForegroundColor Yellow<br>        } else {<br>            Write-Host &quot;&quot;<br>        }<br>        Write-Host &quot;&quot;<br>        <br>        return $true<br>    } catch {<br>        Write-Error &quot;Failed to set environment variable: $_&quot;<br>        return $false<br>    }<br>}<br><br>function Get-AccountForKey {<br>    param(<br>        [string]$KeysDirectory,<br>        [string]$TargetKey<br>    )<br>    <br>    if (-not $TargetKey) {<br>        return $null<br>    }<br>    <br>    $folders = Get-AccountFolders -KeysDirectory $KeysDirectory<br>    <br>    foreach ($folder in $folders) {<br>        $envFile = Join-Path $folder.FullName &quot;.env&quot;<br>        $key = Get-ApiKeyFromEnvFile -EnvFilePath $envFile<br>        <br>        if ($key -and $key -eq $TargetKey) {<br>            return $folder.Name<br>        }<br>    }<br>    <br>    return $null<br>}<br><br>function Show-CurrentKeyDetails {<br>    param([string]$KeysDirectory)<br>    <br>    $currentKey = $env:GEMINI_API_KEY<br>    <br>    Write-Host &quot;&quot;<br>    Write-Host &quot;=== Current Key Details ===&quot; -ForegroundColor Cyan<br>    Write-Host &quot;&quot;<br>    <br>    if ($currentKey) {<br>        Write-Host &quot;Full Key: &quot; -NoNewline -ForegroundColor Yellow<br>        Write-Host $currentKey -ForegroundColor Green<br>        Write-Host &quot;Length: &quot; -NoNewline -ForegroundColor Yellow<br>        Write-Host $currentKey.Length -ForegroundColor Green<br>        <br>        $matchedAccount = Get-AccountForKey -KeysDirectory $KeysDirectory -TargetKey $currentKey<br>        if ($matchedAccount) {<br>            Write-Host &quot;Matched Account: &quot; -NoNewline -ForegroundColor Yellow<br>            Write-Host $matchedAccount -ForegroundColor Green<br>        } else {<br>            Write-Host &quot;Matched Account: &quot; -NoNewline -ForegroundColor Yellow<br>            Write-Host &quot;None (key not found in managed accounts)&quot; -ForegroundColor Red<br>        }<br>    } else {<br>        Write-Host &quot;No GEMINI_API_KEY is currently set.&quot; -ForegroundColor Red<br>    }<br>    <br>    Write-Host &quot;&quot;<br>    Write-Host &quot;Press any key to continue...&quot; -ForegroundColor Gray<br>    $null = $Host.UI.RawUI.ReadKey(&quot;NoEcho,IncludeKeyDown&quot;)<br>}<br><br># Main script execution<br>function Main {<br>    Write-Host &quot;Initializing Gemini API Key Manager...&quot; -ForegroundColor Green<br>    <br>    # Check if keys directory exists<br>    if (-not (Test-Path $KeysDirectory)) {<br>        Write-Error &quot;Keys directory not found: $KeysDirectory&quot;<br>        Write-Host &quot;Please ensure the directory exists and contains account folders with .env files.&quot;<br>        exit 1<br>    }<br>    <br>    # Get available account folders<br>    $accountFolders = Get-AccountFolders -KeysDirectory $KeysDirectory<br>    <br>    if ($accountFolders.Count -eq 0) {<br>        Write-Warning &quot;No account folders with .env files found in $KeysDirectory&quot;<br>        Write-Host &quot;Please ensure each account folder contains a .env file with GEMINI_API_KEY.&quot;<br>        exit 1  <br>    }<br>    <br>    Write-Host &quot;Found $($accountFolders.Count) account folder(s) with .env files.&quot; -ForegroundColor Green<br>    <br>    # Main menu loop<br>    do {<br>        $currentKey = $env:GEMINI_API_KEY<br>        Show-Menu -AccountFolders $accountFolders -CurrentKey $currentKey<br>        <br>        $choice = Read-Host &quot;Select an option&quot;<br>        <br>        switch ($choice.ToLower()) {<br>            &quot;0&quot; {<br>                Show-CurrentKeyDetails -KeysDirectory $KeysDirectory<br>            }<br>            &quot;q&quot; {<br>                Write-Host &quot;Goodbye!&quot; -ForegroundColor Green<br>                break<br>            }<br>            default {<br>                $choiceNum = $null<br>                if ([int]::TryParse($choice, [ref]$choiceNum) -and $choiceNum -ge 1 -and $choiceNum -le $accountFolders.Count) {<br>                    $selectedFolder = $accountFolders[$choiceNum - 1]<br>                    $envFile = Join-Path $selectedFolder.FullName &quot;.env&quot;<br>                    <br>                    Write-Host &quot;&quot;<br>                    Write-Host &quot;Loading key from: &quot; -NoNewline -ForegroundColor Yellow<br>                    Write-Host $selectedFolder.Name -ForegroundColor Cyan<br>                    <br>                    $apiKey = Get-ApiKeyFromEnvFile -EnvFilePath $envFile<br>                    <br>                    if ($apiKey) {<br>                        $success = Set-GeminiApiKey -ApiKey $apiKey -AccountName $selectedFolder.Name<br>                        if ($success) {<br>                            Write-Host &quot;Press any key to continue...&quot; -ForegroundColor Gray<br>                            $null = $Host.UI.RawUI.ReadKey(&quot;NoEcho,IncludeKeyDown&quot;)<br>                        }<br>                    } else {<br>                        Write-Host &quot;Failed to load API key from $envFile&quot; -ForegroundColor Red<br>                        Write-Host &quot;Press any key to continue...&quot; -ForegroundColor Gray<br>                        $null = $Host.UI.RawUI.ReadKey(&quot;NoEcho,IncludeKeyDown&quot;)<br>                    }<br>                } else {<br>                    Write-Host &quot;Invalid choice. Please try again.&quot; -ForegroundColor Red<br>                    Start-Sleep -Seconds 1<br>                }<br>            }<br>        }<br>    } while ($choice.ToLower() -ne &quot;q&quot;)<br>}<br><br># Run the main function<br>Main</pre><h3>Using the script.</h3><p><strong>Note: You must restart your PowerShell terminal for the path addition to take effect.</strong></p><ol><li>In a new PowerShell instance, navigate to the folder you want to work in with Gemini-cli.</li><li>Type <strong>gemini-key-manager.ps1 </strong>and press return. Alternatively you should be able to cycle through the autocomplete with tab after typing ‘gemi’ to save you some finger strokes.</li><li>The CLI will load.</li><li>Select the account you wish Gemini-api to use.</li><li>The key will be exported into the GEMINI_API_KEY environment variable in that shell only.</li><li>Run Gemini-cli with the <strong>gemini </strong>command.</li><li>Type /auth, hit enter, select auth with API key.</li><li>Done. Next account.</li><li>Open another shell or split your current terminal window.</li><li>Repeat steps 2–6. <br>And so on.</li></ol><figure><img alt="CLI with the account names redacted" src="https://cdn-images-1.medium.com/max/342/1*zwCxg3I8k3jMZT_l2RcqFQ.png" /><figcaption>CLI with account names redacted</figcaption></figure><h4>Now you are Done.</h4><h4>Now you can do this with your other accounts in other working directories and not suffer too harshly with rate limiting as you vibe code your brain off.</h4><h4>Remember to keep your API keys secure and never commit them to version control! A handy way of doing this is to prompt Gemini: Scan my codebase for hardcoded API keys and then initialise the .gitignore securely.</h4><h3>Have fun!</h3><h3>Troubleshooting Common Issues</h3><h3>Script Execution Policy Error</h3><p>If you see “cannot be loaded because running scripts is disabled on this system” run the following command: Set-ExecutionPolicy =ExecutionPolicy RemoteSigned -Scope CurrentUser</p><h3>API Key Not Recognized</h3><p>If Gemini-CLI doesn’t recognize your API key after selection:</p><ul><li>Ensure your .env file uses straight quotes (“) not curly quotes (“”)</li><li>Verify there are no extra spaces in your API key</li><li>Run echo $env:GEMINI_API_KEY to confirm the key is set</li></ul><h3>PATH Variable Not Updating</h3><p>If PowerShell can’t find gemini-key-manager.ps1:</p><ul><li>Restart your computer</li><li>Run $env:Path -split &#39;;&#39; to verify your Tools folder is listed</li><li>Try using the full path: ~\Tools\gemini-key-manager.ps1</li></ul><h3>Multiple Instances Not Working</h3><p>If you can’t run concurrent sessions:</p><ul><li>Ensure each terminal window runs the key manager separately</li><li>Verify each instance shows a different API key when running option “0”</li><li>Check that you’re not using global environment variables that might conflict</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b197ef29e991" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>