这是用户在 2025-6-26 18:36 为 https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/commands.md 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Skip to content
Open in github.dev Open in a new github.dev tab Open in codespace

Latest commit

Jun 25, 2025
7421bf6 · Jun 25, 2025

History

History
150 lines (103 loc) · 8.58 KB

commands.md  命令.md

File metadata and controls

150 lines (103 loc) · 8.58 KB

CLI Commands  CLI 指令

Gemini CLI supports several built-in commands to help you manage your session, customize the interface, and control its behavior. These commands are prefixed with a forward slash (/), an at symbol (@), or an exclamation mark (!).
Gemini CLI 支持多个内置命令,可以帮助您管理会话、自定义界面以及控制其行为。这些命令以正斜杠 ( / )、 @ @ 或感叹号 ( ! ) 为前缀。

Slash commands (/)
斜杠命令 ( / )

Slash commands provide meta-level control over the CLI itself.
Slash 命令提供了对 CLI 本身的元级控制。

  • /bug

    • Description: File an issue about Gemini CLI. By default, the issue is filed within the GitHub repository for Gemini CLI. The string you enter after /bug will become the headline for the bug being filed. The default /bug behavior can be modified using the bugCommand setting in your .gemini/settings.json files.
      Description: 向 Gemini CLI 提交问题。默认情况下,问题将提交到 Gemini CLI 的 GitHub 代码仓库中。您在 /bug 后输入的字符串将成为提交的错误标题。默认 /bug 行为可以通过 bugCommand 设置在您的 .gemini/settings.json 文件中进行修改。
  • /chat

    • Description: Save and resume conversation history for branching conversation state interactively, or resuming a previous state from a later session.
      Description: 保存并恢复对话历史记录,以便在交互式分支对话状态中使用,或从之前的会话恢复先前的状态。
    • Sub-commands:  子命令:
      • save
        • Description: Saves the current conversation history. You must add a <tag> for identifying the conversation state.
          描述:保存当前对话历史记录。您必须添加一个 <tag> 以标识对话状态。
        • Usage: /chat save <tag>  Usage: /chat save <tag> auto→简体中文
      • resume
        • Description: Resumes a conversation from a previous save.
          描述: 从之前的保存恢复会话。
        • Usage: /chat resume <tag>  Usage: /chat resume <tag> 自动→简体中文
      • list
        • Description: Lists available tags for chat state resumption.
          描述: 列出可用于会话状态恢复的可用标签。
  • /clear

    • Description: Clear the terminal screen, including the visible session history and scrollback within the CLI. The underlying session data (for history recall) might be preserved depending on the exact implementation, but the visual display is cleared.
      Description: 清除终端屏幕,包括 CLI 中的可见会话历史和滚动缓冲区。底层会话数据(用于历史回溯)可能会根据具体实现保留,但视觉显示会被清除。
    • Keyboard shortcut: Press Ctrl+L at any time to perform a clear action.
      键盘快捷键: 在任何时间按下 Ctrl+L 执行清除操作。
  • /compress

    • Description: Replace the entire chat context with a summary. This saves on tokens used for future tasks while retaining a high level summary of what has happened.
      Description: 用摘要替换整个聊天上下文。这样可以节省用于未来任务的令牌数量,同时保留所发生事件的高层次概述。
  • /editor

    • Description: Open a dialog for selecting supported editors.
      Description: 打开一个对话框用于选择支持的编辑器。
  • /help (or /?)   /help (或 /?

    • Description: Display help information about the Gemini CLI, including available commands and their usage.
      Description: 显示关于 Gemini CLI 的帮助信息,包括可用命令及其用法。
  • /mcp

    • Description: List configured Model Context Protocol (MCP) servers, their connection status, server details, and available tools.
      描述: 列出已配置的 Model Context Protocol (MCP) 服务器,包括它们的连接状态、服务器详细信息以及可用工具。
    • Sub-commands:  子命令:
      • desc or descriptions:
        descdescriptions :
        • Description: Show detailed descriptions for MCP servers and tools.
          Description: 显示 MCP 服务器和工具的详细描述。
      • nodesc or nodescriptions:
        nodescnodescriptions :
        • Description: Hide tool descriptions, showing only the tool names.
          Description: 隐藏工具描述,仅显示工具名称。
      • schema:
        • Description: Show the full JSON schema for the tool's configured parameters.
          Description: 显示工具配置参数的完整 JSON 模式。
    • Keyboard Shortcut: Press Ctrl+T at any time to toggle between showing and hiding tool descriptions.
      键盘快捷键:随时按下 Ctrl+T 切换显示和隐藏工具描述。
  • /memory

    • Description: Manage the AI's instructional context (hierarchical memory loaded from GEMINI.md files).
      Description: 管理 AI 的指导性上下文(从 GEMINI.md 文件加载的分层记忆)。
    • Sub-commands:  子命令:
      • add:
        • Description: Adds the following text to the AI's memory. Usage: /memory add <text to remember>
          描述: 将以下文本添加到 AI 的记忆中。用法: /memory add <text to remember>
      • show:
        • Description: Display the full, concatenated content of the current hierarchical memory that has been loaded from all GEMINI.md files. This lets you inspect the instructional context being provided to the Gemini model.
          Description: 显示当前从所有 GEMINI.md 文件加载的层次化记忆的完整连接内容。这可以让您检查传递给 Gemini 模型的指令性上下文。
      • refresh:
        • Description: Reload the hierarchical instructional memory from all GEMINI.md files found in the configured locations (global, project/ancestors, and sub-directories). This command updates the model with the latest GEMINI.md content.
          Description: 从配置的位置(全局、项目/祖先和子目录)中重新加载分层指令记忆,从找到的所有 GEMINI.md 文件中加载。此命令会使用最新的 GEMINI.md 内容更新模型。
      • Note: For more details on how GEMINI.md files contribute to hierarchical memory, see the CLI Configuration documentation.
        音符: 有关 GEMINI.md 文件如何贡献于分层内存的详细信息,请参阅 CLI 配置文档。
  • /restore

    • Description: Restores the project files to the state they were in just before a tool was executed. This is particularly useful for undoing file edits made by a tool. If run without a tool call ID, it will list available checkpoints to restore from.
      Description: 将项目文件恢复到执行工具之前的状态。这对于撤销工具所做的文件编辑特别有用。如果不指定工具调用 ID,则会列出可用于恢复的检查点。
    • Usage: /restore [tool_call_id]  Usage: /restore [tool_call_id] 自动→简体中文
    • Note: Only available if the CLI is invoked with the --checkpointing option or configured via settings. See Checkpointing documentation for more details.
      Note: 仅在 CLI 通过 --checkpointing 选项被调用或通过设置进行配置时可用。有关详细信息,请参阅检查点文档。
  • /stats

    • Description: Display detailed statistics for the current Gemini CLI session, including token usage, cached token savings (when available), and session duration.
      Description: 显示当前 Gemini CLI 会话的详细统计信息,包括令牌使用情况、缓存令牌节省(如有)以及会话时长。

      Note: Cached token information is only displayed when cached tokens are being used, which occurs with API key authentication but not with OAuth authentication at this time.
      注意:缓存的令牌信息仅在使用缓存的令牌时显示,这目前仅发生在使用 API 密钥认证时,而不发生在 OAuth 认证时。
  • /theme

    • Description: Open a dialog that lets you change the visual theme of Gemini CLI.
      Description: 打开一个对话框,让你可以更改 Gemini CLI 的视觉主题。
  • /auth

    • Description: Open a dialog that lets you change the authentication method.
      Description: 打开一个对话框,让你更改认证方法。
  • /about

    • Description: Show version info. Please share this information when filing issues.
      Description: 显示版本信息。请在提交问题时分享此信息。
  • /tools

    • Description: Display a list of tools that are currently available within Gemini CLI.
      Description: 显示当前可用的 Gemini CLI 工具列表。
    • Sub-commands:  子命令:
      • desc or descriptions:
        descdescriptions :
        • Description: Show detailed descriptions of each tool, including each tool's name with its full description as provided to the model.
          Description: 显示每个工具的详细描述,包括每个工具的名称及其提供的完整描述。
      • nodesc or nodescriptions:
        nodescnodescriptions :
        • Description: Hide tool descriptions, showing only the tool names.
          Description: 隐藏工具描述,仅显示工具名称。
  • /quit (or /exit)   /quit (或 /exit

    • Description: Exit Gemini CLI.
      Description: 退出 Gemini CLI。

At commands (@)
在命令 ( @ )

At commands are used to include the content of files or directories as part of your prompt to Gemini. These commands include git-aware filtering.
在命令中可以包含文件或目录的内容,将其作为提示的一部分发送给 Gemini。这些命令包括 git 感知过滤。

  • @<path_to_file_or_directory>

    • Description: Inject the content of the specified file or files into your current prompt. This is useful for asking questions about specific code, text, or collections of files.
      Description: 将指定文件或文件的内容注入到当前提示中。这在询问特定代码、文本或文件集合的问题时非常有用。
    • Examples:  示例:
      • @path/to/your/file.txt Explain this text.
      • @src/my_project/ Summarize the code in this directory.
      • What is this file about? @README.md
    • Details:  详情:
      • If a path to a single file is provided, the content of that file is read.
        如果提供了单个文件的路径,将会读取该文件的内容。
      • If a path to a directory is provided, the command attempts to read the content of files within that directory and any subdirectories.
        如果提供了目录路径,该命令将尝试读取该目录及其子目录中文件的内容。
      • Spaces in paths should be escaped with a backslash (e.g., @My\ Documents/file.txt).
        路径中的空格应使用反斜杠转义(例如, @My\ Documents/file.txt )。
      • The command uses the read_many_files tool internally. The content is fetched and then inserted into your query before being sent to the Gemini model.
        该命令内部使用了 read_many_files 工具。内容会被获取并插入到您的查询中,然后发送给 Gemini 模型。
      • Git-aware filtering: By default, git-ignored files (like node_modules/, dist/, .env, .git/) are excluded. This behavior can be changed via the fileFiltering settings.
        Git 感知过滤:默认情况下,会被 git 忽略的文件(如 node_modules/dist/.env.git/ )会被排除。此行为可以通过 fileFiltering 设置进行更改。
      • File types: The command is intended for text-based files. While it might attempt to read any file, binary files or very large files might be skipped or truncated by the underlying read_many_files tool to ensure performance and relevance. The tool indicates if files were skipped.
        文件类型:该命令适用于文本文件。虽然它可能会尝试读取任何文件,但二进制文件或非常大的文件可能会被底层 read_many_files 工具跳过或截断以确保性能和相关性。工具会指示哪些文件被跳过了。
    • Output: The CLI will show a tool call message indicating that read_many_files was used, along with a message detailing the status and the path(s) that were processed.
      输出:命令行界面将显示一条工具调用消息,表明使用了 read_many_files ,并附带一条详细说明状态和处理路径的消息。
  • @ (Lone at symbol)   @ (单独的 @ 符号)

    • Description: If you type a lone @ symbol without a path, the query is passed as-is to the Gemini model. This might be useful if you are specifically talking about the @ symbol in your prompt.
      Description: 如果你在路径后面只输入了单独的 @ 符号,查询将原封不动地传递给 Gemini 模型。这可能在你的提示中特别提到 @ 符号时是有用的。

Error handling for @ commands
错误处理 for @ 命令

  • If the path specified after @ is not found or is invalid, an error message will be displayed, and the query might not be sent to the Gemini model, or it will be sent without the file content.
    如果在 @ 后面指定的路径未找到或无效,将显示错误消息,并且查询可能不会发送到 Gemini 模型,或者将不包含文件内容地发送。
  • If the read_many_files tool encounters an error (e.g., permission issues), this will also be reported.
    如果 read_many_files 工具遇到错误(例如权限问题),也会报告该错误。

Shell mode & passthrough commands (!)
Shell 模式及透传命令 ( ! )

The ! prefix lets you interact with your system's shell directly from within Gemini CLI.
! 前缀可以让您直接从 Gemini CLI 中与系统的 Shell 交互。

  • !<shell_command>

    • Description: Execute the given <shell_command> in your system's default shell. Any output or errors from the command are displayed in the terminal.
      Description: 在您的系统默认 Shell 中执行给定的 <shell_command> 。命令的任何输出或错误将在终端中显示。
    • Examples:  示例:
      • !ls -la (executes ls -la and returns to Gemini CLI)
        !ls -la (执行 ls -la 并返回到 Gemini CLI)
      • !git status (executes git status and returns to Gemini CLI)
        !git status (执行 git status 并返回到 Gemini CLI)
  • ! (Toggle shell mode)   ! (切换 Shell 模式)

    • Description: Typing ! on its own toggles shell mode.
      Description: 输入 ! 本身可以切换到 Shell 模式。
      • Entering shell mode:  进入 Shell 模式:
        • When active, shell mode uses a different coloring and a "Shell Mode Indicator".
          当启用时,Shell 模式会使用不同的颜色,并显示一个“Shell 模式指示器”。
        • While in shell mode, text you type is interpreted directly as a shell command.
          在 Shell 模式下,您输入的文本会被直接解释为 Shell 命令。
      • Exiting shell mode:  退出 Shell 模式:
        • When exited, the UI reverts to its standard appearance and normal Gemini CLI behavior resumes.
          当退出时,UI 将恢复其标准外观,并且正常的 Gemini CLI 行为将恢复。
  • Caution for all ! usage: Commands you execute in shell mode have the same permissions and impact as if you ran them directly in your terminal.
    警告:所有 ! 的用法需谨慎:在 Shell 模式下执行的命令与直接在终端中运行时具有相同的权限和影响。

set 限制解除