Skip to content

Gemini CLI 的所有配置都存储在 ~/.gemini/settings.json(全局)或 项目/.gemini/settings.json(项目级)。本页是完整字段速查表,覆盖 General、UI、Output、MCP 服务器配置等所有选项。项目级配置会覆盖全局配置。

Gemini CLI 配置参考(settings.json)

配置文件位置

作用范围文件路径
全局(所有项目)~/.gemini/settings.json
项目级(当前项目)项目根目录/.gemini/settings.json

项目级配置优先级更高,会覆盖全局配置中的同名字段。

修改配置的方式:

  • 直接编辑文件
  • 在 REPL 中使用 /settings 命令(图形化设置面板)

General 通用配置

字段默认值说明
general.vimModefalse启用 Vim 键绑定
general.defaultApprovalMode"default"默认工具审批模式:default / auto_edit / plan
general.enableAutoUpdatetrue启用自动更新
general.enableNotificationsfalse启用终端通知
general.notificationMethod"auto"通知方式
general.plan.enabledtrue启用 Plan Mode
general.plan.directoryundefined计划文件存储目录(未设则用系统临时目录)
general.plan.modelRoutingtrue规划阶段用 Pro 模型,执行阶段用 Flash
general.retryFetchErrorstrue遇到 fetch 报错时自动重试
general.maxAttempts10主聊天模型的最大重试次数(上限 10)
general.sessionRetention.enabledtrue启用自动清理旧会话
general.sessionRetention.maxAge"30d"保留会话时长(如 "7d""24h""1w"
general.topicUpdateNarrationtrue减少啰嗦输出,启用结构化进度报告

UI 界面配置

字段默认值说明
ui.autoThemeSwitchingtrue根据终端背景色自动切换亮/暗主题
ui.hideWindowTitlefalse隐藏窗口标题栏
ui.inlineThinkingMode"off"显示模型思考过程:off / full
ui.dynamicWindowTitletrue在终端标题栏显示状态图标(就绪/工作中/需操作)
ui.showHomeDirectoryWarningtrue在家目录运行时显示警告
ui.hideTipsfalse隐藏界面中的提示信息
ui.compactToolOutputtrue紧凑模式显示工具输出(列目录、读文件等)
ui.hideBannerfalse隐藏启动 Banner
ui.hideContextSummaryfalse隐藏输入框上方的上下文摘要
ui.hideFooterfalse隐藏底部状态栏
ui.showLineNumberstrue在聊天中显示行号
ui.showUserIdentitytrue显示已登录账号(邮箱)信息
ui.useAlternateBufferfalse使用交替屏幕缓冲区(保留 shell 历史)
ui.escapePastedAtSymbolsfalse粘贴时自动转义 @ 符号,防止误触发文件引用

Output 输出配置

字段默认值说明
output.format"text"输出格式:text / json

MCP 服务器配置

settings.json 中添加 mcpServers 块来配置 MCP 服务器:

json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "my-http-service": {
      "url": "http://localhost:3000/mcp",
      "transport": "http"
    }
  }
}

详见MCP 服务器接入

实验性功能

json
{
  "experimental": {
    "autoMemory": true,
    "worktrees": true
  }
}
字段默认值说明
experimental.autoMemoryfalse启用 Auto Memory 自动技能提取
experimental.worktreesfalse启用 git worktree 支持(-w 参数)

完整配置示例

json
{
  "general": {
    "defaultApprovalMode": "auto_edit",
    "plan": {
      "enabled": true,
      "modelRouting": true
    },
    "sessionRetention": {
      "maxAge": "14d"
    }
  },
  "ui": {
    "hideTips": true,
    "hideBanner": true,
    "compactToolOutput": true
  },
  "output": {
    "format": "text"
  },
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    }
  },
  "context": {
    "fileName": ["GEMINI.md", "CLAUDE.md"]
  }
}

常见问题

Q: 修改 settings.json 后需要重启吗?

A: 大部分 UI 和 General 设置通过 /settings 实时生效;MCP 服务器配置需要 /mcp reload 或重启;实验性功能需要完全重启。

Q: auto_editdefault 审批模式有什么差别?

A: default 模式下每次工具调用(包括读文件、写文件、Shell 命令)都询问确认;auto_edit 自动批准文件读写操作,但 Shell 命令和危险操作仍需确认。

Q: 项目级 settings.json 是否应该提交到 git?

A: 建议提交(不含敏感信息的部分)。MCP 服务器配置中用 ${ENV_VAR} 引用环境变量,不会把 token 写入配置文件。团队共享配置有助于统一开发体验。