gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Commands Should work in Non-Interactive Mode

Open jerop opened this issue 1 year ago • 19 comments

What happened?

Description

When running the Gemini CLI in a non-interactive environment, custom commands defined in .toml files are not being recognized or executed. The CLI either treats the command as a literal string or reports it as an invalid command.

Instead of expanding the command from the corresponding .toml file, the CLI either treats the custom command itself (e.g., /pr-review) as the literal prompt text or fails with an "invalid command" error. This prevents the use of reusable prompts in automated workflows, which is a primary use case for this feature.

Steps to Reproduce

  1. Create a custom command file
  2. Run the command interactively. This works as expected.
  3. Run the same command non-interactively. This fails.

cc @abhipatel12

What did you expect to happen?

When gemini --prompt "/hello" is executed, the CLI should find the .gemini/commands/hello.toml file, expand the prompt, and execute that prompt with Gemini CLI non-interactively.

Open to other syntax suggestions to make this work in headless mode, doesn't have to be slash commands.

Client information

N/A

Login information

N/A

Anything else we need to know?

The primary impact of this bug is on automation. The current workaround is to embed the entire multi-line prompt directly into the script. This defeats the purpose of having reusable custom commands, making workflows verbose and difficult to maintain. Enabling slash commands in non-interactive mode is critical for clean, modular, and maintainable automated workflows.

In addition, this makes it impossible to use extensions in non-interactive mode.

jerop avatar Aug 02 '25 22:08 jerop

I don't think this is strictly a custom slash commands, no slash commands work in non-interactive mode.

Would also be useful to be able use built-in slash commands like gemini -p /about as well. See #5390

This is definitely something we should look at supporting 😄

jackwotherspoon avatar Aug 03 '25 14:08 jackwotherspoon

I don't think this is strictly a custom slash commands, no slash commands work in non-interactive mode.我不认为这严格来说是自定义斜杠命令,没有斜杠命令在非交互模式下工作。

Would also be useful to be able use built-in slash commands like gemini -p /about as well. See #5390能够使用内置的斜杠命令(如 gemini -p /about)也很有用。看 #5390

This is definitely something we should look at supporting 😄这绝对是我们应该考虑支持😄的东西

Really want custom commands! (✧∀✧)

xxxIxxxx avatar Aug 04 '25 02:08 xxxIxxxx

I know this is two weeks old, but I am facing the exact problem - version 0.1.21 This works gemini --prompt "/plan"

This does not /plan

CodingMadePlain avatar Aug 17 '25 19:08 CodingMadePlain

looks like this has been fixed on main branch 🙂

> gemini --prompt "/plan"

Data collection is disabled.
Loaded cached credentials.
I see you're asking for a `/plan`. I'll start by examining the `.gemini/commands/plan.toml` file to understand what that 
command does.Okay, I understand. The `/plan` command requires me to create a comprehensive travel plan from ...

dumbbellcode avatar Aug 19 '25 18:08 dumbbellcode

looks like this has been fixed on main branch

it's not really been fixed, this looks like gemini figuring it out by itself, which is cool but not working as requested in this issue

jerop avatar Aug 27 '25 21:08 jerop

I'm curious which option people would like to see:

  1. The option where you call gemini --prompt "/command command args"

or

  1. An option where you call gemini --command="comand args"

I'm looking at implementing one of these two strategies and I'd love to get some feedback from the community on which one they prefer. Assume that we will take care of dynamically creating a flag for your custom slash commands in the second case.

allenhutchison avatar Aug 27 '25 21:08 allenhutchison

I'm curious which option people would like to see:

  1. The option where you call gemini --prompt "/command command args"

or

  1. An option where you call gemini --command="comand args"

I'm looking at implementing one of these two strategies and I'd love to get some feedback from the community on which one they prefer. Assume that we will take care of dynamically creating a flag for your custom slash commands in the second case.

I vote 1, I hope it same as claude code, really don't like every cli has own difference instruction

cowbear6598 avatar Aug 31 '25 13:08 cowbear6598

First option

On Sun, Aug 31, 2025, 14:05 CodeMeteor @.***> wrote:

cowbear6598 left a comment (google-gemini/gemini-cli#5435) https://github.com/google-gemini/gemini-cli/issues/5435#issuecomment-3240133697

I'm curious which option people would like to see:

  1. The option where you call gemini --prompt "/command command args"

or

  1. An option where you call gemini --command="comand args"

I'm looking at implementing one of these two strategies and I'd love to get some feedback from the community on which one they prefer. Assume that we will take care of dynamically creating a flag for your custom slash commands in the second case.

I vote 1, I hope it same as claude code, really don't like every cli has own difference instruction

— Reply to this email directly, view it on GitHub https://github.com/google-gemini/gemini-cli/issues/5435#issuecomment-3240133697, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZGJZ5QLHZANZWBH5UWUHR33QLXJVAVCNFSM6AAAAACC7GOZ42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTENBQGEZTGNRZG4 . You are receiving this because you commented.Message ID: @.***>

CodingMadePlain avatar Aug 31 '25 15:08 CodingMadePlain

If /copy would save all of the output /copy /dev/stdout

would allow gemini-cli to be used in the middle of a UNIX pipe

gbrbc avatar Sep 06 '25 16:09 gbrbc

@gbrbc Gemini CLI can already be used in a unix pipe cat foo.txt | gemini -p "summarize this text" | more should work today

allenhutchison avatar Sep 09 '25 19:09 allenhutchison

@allenhutchison Hello, is this feature currently in development?

TomorJM avatar Sep 11 '25 08:09 TomorJM

@TomorJM could you please share more about your use case? Also, do you have any inputs to @allenhutchison's question above about which syntax to go with?

jerop avatar Sep 12 '25 15:09 jerop

I can share my use cases:

  1. Simple reuse of slash commands. Say I've already defined a custom slash command (or installed an extension). Why can't I also use it in non-interactive mode? (I know I can pipe over the command definition but I'd first need to know where to find the toml file)
  2. From a Gemini CLI session, I want to spawn other Gemini CLI sessions as subagents with isolated context windows. These days I find myself defining a custom slash command with instructions like When [certain condition met], you can run: 'gemini -p "Do this other thing but only return me the result"' to get [certain additional context]. But because slash commands don't work in non-interactive mode, I can not reuse them as subagents easily. (I'm not sure if there is a better way to spawn sessions as subagents)

yolocs avatar Sep 12 '25 16:09 yolocs

  1. The option where you call gemini --prompt "/command command args"

or

  1. An option where you call gemini --command="comand args"

@allenhutchison my quick thoughts

Big fan of Option 1. Seems the most intuitive.

It is how i tested to see if custom commands were supported in non-interactive mode. I think with option 1 it gives the beauty of developers finding it naturally by trying what they are used to in interactive mode. "Hey I wonder if this works", followed by the magic of "Wow it works!" ✨

This is a powerful feeling as a dev.

Versus Option 2 where i need to learn a new syntax or go look at docs etc.

jackwotherspoon avatar Sep 12 '25 16:09 jackwotherspoon

I will attempt to summarize the discussions so far:

gemini --prompt "/command command args"

  • Consistency with other tools e.g. Claude
  • Intuitive and discoverable
    • Users are extremely likely to try this first and may not know the command is not actually executed

An command line option where you call gemini --command="command args"

  • Consistency with general command-line interface design principles. Please see Allen's comment in the draft PR
    • 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?
  • Clearly expresses intent to run a command e.g. in the other option, what should we do when the command doesn't exist, should it proceed silently with /unknownprompt

capachino avatar Sep 12 '25 20:09 capachino

I echo that Option 1 seems far more consistent with other tools and is more discoverable....

sniemczyk-google avatar Sep 12 '25 22:09 sniemczyk-google

@TomorJM could you please share more about your use case? Also, do you have any inputs to @allenhutchison's question above about which syntax to go with?

@jerop I am more inclined towards option 1. My use case is that I expose custom commands to the cli via mcp prompt. Some of these commands are parameterless, while others have parameters. I tried adding this feature myself and passed the test (although the implementation is not that elegant).

gemini -p "/no-param-test"

gemini -p "/multi-param-test name=\"John Doe\" age=30 city=\"New York\""

TomorJM avatar Sep 15 '25 07:09 TomorJM

+1 to option 1; seems reasonable that one could expect the same prompt to be interpreted consistently whether they're in interactive or non-interactive mode

(maybe option 2 is addressing a slightly different use case? nice to have tight control over invoking just one command?)

bobcatfish avatar Sep 15 '25 16:09 bobcatfish

ok, thanks everyone for the discussion. It looks like we are going with option 1.

allenhutchison avatar Sep 15 '25 22:09 allenhutchison