Skip to content

Conversation

@Thomas-Shephard
Copy link

@Thomas-Shephard Thomas-Shephard commented Jan 8, 2026

This comes from #16089, I accidentally deleted the forked branch so the pr was automatically closed :/

Summary

Fixes an issue where the agent would attempt to use Linux-specific shell commands (like grep and &&) when running on Windows. Since Gemini CLI's shell tool implementation forces the use of PowerShell on Windows, these Unix-style commands were failing. This PR makes the system prompt platform-aware, ensuring the agent uses compatible syntax and utilities.

Details

The core problem was a mismatch between the agent's instructions (which assumed a POSIX-like shell) and the CLI's actual execution environment on Windows (PowerShell).

Related Issues

Fixes #16151

How to Validate

  1. Unit Tests: Run the core prompt tests to verify cross-platform logic:
    npx vitest packages/core/src/core/prompts.test.ts
  2. Manual Verification (Windows):
  • Start Gemini CLI on a Windows machine.
  • Ask the agent to "check git status and show recent logs".
  • Expected Result: The agent should call run_shell_command with commands chained by ; instead of &&.
  • Ask the agent to search for a string in a file using a shell command.
  • Expected Result: The agent should use Select-String instead of grep.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@Thomas-Shephard Thomas-Shephard requested a review from a team as a code owner January 8, 2026 09:07
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Thomas-Shephard, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the cross-platform compatibility of the Gemini CLI agent by making its system prompt aware of the underlying operating system. Previously, the agent would instruct users with Linux-centric shell commands, leading to execution failures on Windows machines running PowerShell. The changes introduce logic to adapt command syntax and utility suggestions, ensuring the agent provides relevant and executable instructions regardless of whether it's running on Windows or a Unix-like system. This enhances the agent's reliability and user experience across diverse development environments.

Highlights

  • Platform-Specific Shell Commands: The system prompt now dynamically generates shell commands based on the operating system, resolving an issue where Linux-specific commands (like grep and &&) would fail on Windows PowerShell environments.
  • Windows Compatibility: On Windows, the agent will now suggest PowerShell-compatible commands such as Select-String instead of grep, Get-Content -Tail 10 instead of tail, and uses ; for command chaining instead of &&.
  • Enhanced Test Coverage: New unit tests have been added to prompts.test.ts to explicitly verify that the system prompt correctly generates both Windows-specific and Linux-specific shell commands.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of using platform-specific shell commands in the system prompt, particularly for Windows environments. The changes are logical and the accompanying tests provide good coverage for both Windows and Linux platforms. I have one suggestion to enhance the flexibility of the tail and head command equivalents on Windows by not hardcoding the line count, which would allow the agent to specify it as needed.

Comment on lines +136 to +137
const tailCommand = isWindows ? 'Get-Content -Tail 10' : 'tail';
const headCommand = isWindows ? 'Get-Content -TotalCount 10' : 'head';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Hardcoding the line count to 10 for tail and head equivalents on Windows limits the agent's flexibility. The agent might need to inspect more or fewer lines depending on the context. A better approach would be to provide the command and parameter, allowing the agent to specify the number of lines itself. This would be more consistent with how the tail and head commands are used on Linux, where the agent can add flags like -n 20.

Suggested change
const tailCommand = isWindows ? 'Get-Content -Tail 10' : 'tail';
const headCommand = isWindows ? 'Get-Content -TotalCount 10' : 'head';
const tailCommand = isWindows ? 'Get-Content -Tail' : 'tail';
const headCommand = isWindows ? 'Get-Content -TotalCount' : 'head';

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 is the default for tail and head so I think this is fine

Comment on lines +93 to +94
expect(prompt).toContain("'Get-Content -Tail 10'");
expect(prompt).toContain("'Get-Content -TotalCount 10'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To align with the suggested change in prompts.ts, this test should check for the command and parameter without the hardcoded line count.

Suggested change
expect(prompt).toContain("'Get-Content -Tail 10'");
expect(prompt).toContain("'Get-Content -TotalCount 10'");
expect(prompt).toContain("'Get-Content -Tail'");
expect(prompt).toContain("'Get-Content -TotalCount'");

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@Thomas-Shephard
Copy link
Author

Comment from: jacob314

it would be better to mock the platform rather than using define property. Please do that instead if feasible.

Done :)

@Thomas-Shephard
Copy link
Author

Comment from: jacob314

why are the windows versions specifying a number of responses to request?

This is for token efficiency tail and head both default to 10 so that's why I went with it

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System prompt suggests Linux-specific commands on Windows platforms

2 participants