Skip to content

line/block comments starting with // are incorrectly parsed as slash commands #6953

@lifefloating

Description

@lifefloating

What happened?

When i input JavaScript code that starts with comments using //, the gemini-cli incorrectly interprets these as slash commands and throws an "Unknown command" error.

For example, inputting this JavaScript code:

  // check if variants base info all filled.
                            if(!objDetCtrl.variantInfo.baseInfo.title) {
                                 toastr.error('[Title] cannot be empty.')
                                 return false
                            }
                            if(!objDetCtrl.variantInfo.baseInfo.description) {
                                 toastr.error('[Description] cannot be empty.')
                                 return false
                            }
                            if(!objDetCtrl.variantInfo.options.length) {
                                 toastr.error('[Variants] cannot be empty.')
                                 return false
                            }

Results in the error:

Image

What did you expect to happen?

The CLI should treat this input as regular text/code content to be processed by Gemini, not as a command. JavaScript comments starting with // should not trigger the slash command parser.

Root Cause:

In packages/cli/src/ui/hooks/slashCommandProcessor.ts line 263, the condition trimmed.startsWith('/') catches both legitimate slash commands (like /help) and JavaScript comments (//comment), causing the parser to incorrectly attempt to process code comments as commands.

Expected Behavior:

  • Single / followed by a command name should be parsed as slash commands
  • Double // should be treated as regular text content (JavaScript/C++ style comments)
  • The CLI should only interpret intentional command syntax, not common programming language constructs

Client information

Details
$ gemini /about
 CLI Version              0.1.21                                         │
│ Git Commit               5bba15b0                                       │
│ Model                    gemini-2.5-pro                                 │
│ Sandbox                  no sandbox                                     │
│ OS                       darwin                                         │
│ Auth Method              OAuth                                          │
│ License                  Free Tier (Login with Google)                  │
│ IDE Client               VS Code                                        │

Login information

No response

Anything else we need to know?

// and /* will both affect the judgment of the gemini command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions