Skip to content

feat(cli) Custom Commands work in Non-Interactive/Headless Mode#8305

Merged
jerop merged 3 commits into
google-gemini:mainfrom
capachino:non-interactive-custom-commands
Sep 19, 2025
Merged

feat(cli) Custom Commands work in Non-Interactive/Headless Mode#8305
jerop merged 3 commits into
google-gemini:mainfrom
capachino:non-interactive-custom-commands

Conversation

@capachino

@capachino capachino commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

TLDR

Adds the ability to run custom commands in non-interactive mode #5435

Dive Deeper

  • Does not support MCP prompts yet (though I can add this soon as a follow up)
  • Does not support built-in commands. I think this requires some discussion as many of them do not make sense in non-interactive mode.
  • Expects the command invocation will result in a prompt. Confirmations and any other processing result will fail.
  • If the "slash command" is not registered or unknown, proceeds as a regular prompt. I'm open to failing in this case if you think that's better.

Reviewer Test Plan

Try a custom command in non-interactive mode e.g.

node /gemini-cli/packages/cli -p "/security:analyze"

  • Expected failure if the command requires confirmation
  • Expected success if a shell command confirmation is needed AND yolo mode
  • Expected success with command args
  • Expected success if it's not a registered command (i.e. proceed with the raw prompt)
  • No regressions with a command-less prompt

Testing Matrix

🍏 🪟 🐧
npm run X
npx
Docker
Podman - -
Seatbelt X - -

Linked issues / bugs

Makes progress on #5435

@gemini-cli gemini-cli Bot added kind/enhancement priority/p1 Important and should be addressed in the near term. labels Sep 11, 2025
@jerop jerop linked an issue Sep 12, 2025 that may be closed by this pull request

@jerop jerop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think of splitting this into two parts:

  1. Refactor existing functionality to create a reusable packages/cli/src/utils/commands.ts
  2. Implement custom command support in non-interactive mode?

cc @abhipatel12 @allenhutchison

@allenhutchison

Copy link
Copy Markdown
Contributor

We haven't really had a discussion yet on how we want to structure the CLI interface for custom commands (i.e. whether we include them in the positional arg gemini "/command args for command" or if we do the alternative gemini --command="args for command"

I continue to argue for the latter because it doesn't carry over the TUI ux affordance "/" which is unnecessary in the CLI command environment because we have flags. In other words, why invent a new way to do a flag on the command line when we have a perfect good way to do flags on the command line that is used by every other CLI application out there?

Second, I would like this PR to focus on custom commands. Take the @ file processing out for a different PR. Again gemini cli has the ability to take context on STDIN and files can be passed to gemini CLI that way, which is much more consistent with standard command line ux than including the TUI ux affordance "@" to indicate that on the command line. Either way, let's keep this PR focused on one thing.

Finally let's make sure we are including the issue for this #5435 in the PR description and please update the PR description to be more descriptive overall.

@capachino

Copy link
Copy Markdown
Contributor Author

What do you think of splitting this into two parts:

  1. Refactor existing functionality to create a reusable packages/cli/src/utils/commands.ts
  2. Implement custom command support in non-interactive mode?

cc @abhipatel12 @allenhutchison

Good idea. Created PR #8381

@capachino

Copy link
Copy Markdown
Contributor Author

We haven't really had a discussion yet on how we want to structure the CLI interface for custom commands (i.e. whether we include them in the positional arg gemini "/command args for command" or if we do the alternative gemini --command="args for command"

I continue to argue for the latter because it doesn't carry over the TUI ux affordance "/" which is unnecessary in the CLI command environment because we have flags. In other words, why invent a new way to do a flag on the command line when we have a perfect good way to do flags on the command line that is used by every other CLI application out there?

From an engineering perspective I like the separate command flag as it better separates concerns too.

However, the feedback seems clearly in favor of specifying it in the prompt (at least 6 votes for that). I totally understand, because I tried that myself and I think the intuition will become stronger over time as similar tools are going with that approach.

Second, I would like this PR to focus on custom commands. Take the @ file processing out for a different PR. Again gemini cli has the ability to take context on STDIN and files can be passed to gemini CLI that way, which is much more consistent with standard command line ux than including the TUI ux affordance "@" to indicate that on the command line. Either way, let's keep this PR focused on one thing.

Sorry for the confusing diff, that is actually existing functionality.

Finally let's make sure we are including the issue for this #5435 in the PR description and please update the PR description to be more descriptive overall.

Done.

FYI I split the refactoring for the command parsing to PR #8381

I'm not sure if I rebased this PR correctly (apologies I'm still learning Git), but I do see separate commits in this PR at least.

@gemini-cli gemini-cli Bot added kind/bug area/core Issues related to User Interface, OS Support, Core Functionality and removed kind/enhancement labels Sep 13, 2025
Comment thread packages/cli/src/ui/commands/noOpUi.ts Outdated
Comment thread packages/cli/src/nonInteractiveCli.ts Outdated
Comment thread packages/cli/src/nonInteractiveCli.ts Outdated
Comment thread packages/cli/src/nonInteractiveCli.ts Outdated
@allenhutchison

Copy link
Copy Markdown
Contributor

Good progress. A few comments to think about here. Ping me when you are ready for another review.

@allenhutchison

Copy link
Copy Markdown
Contributor

I took another pass this afternoon. This looks great, works well in my testing, and you've addressed all of my comments. I think we can bring this in.

@jerop jerop marked this pull request as ready for review September 19, 2025 13:20
@jerop jerop requested a review from a team as a code owner September 19, 2025 13:20
@jerop

jerop commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

trying to kick off the tests again

@jerop jerop closed this Sep 19, 2025
@jerop jerop reopened this Sep 19, 2025
@jerop jerop added this pull request to the merge queue Sep 19, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 19, 2025
@jerop jerop added this pull request to the merge queue Sep 19, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 19, 2025
@jerop jerop added this pull request to the merge queue Sep 19, 2025
Merged via the queue into google-gemini:main with commit 2c4f61e Sep 19, 2025
67 of 69 checks passed
nagendrareddy10 pushed a commit to nagendrareddy10/gemini-cli that referenced this pull request Sep 22, 2025
yashv6655 added a commit to yashv6655/gemini-cli that referenced this pull request Sep 22, 2025
thacio added a commit to thacio/auditaria that referenced this pull request Oct 3, 2025
giraffe-tree pushed a commit to giraffe-tree/gemini-cli that referenced this pull request Oct 10, 2025
@sripasg sripasg added the size/l A large sized PR label Jun 2, 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 priority/p1 Important and should be addressed in the near term. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commands Should work in Non-Interactive Mode

4 participants