@google/gemini-cli-core 0.21.0-nightly.20251219.70696e364 → 0.21.0-nightly.20251220.41a1a3eed

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/docs/CONTRIBUTING.md +546 -0
  2. package/dist/docs/architecture.md +80 -0
  3. package/dist/docs/assets/connected_devtools.png +0 -0
  4. package/dist/docs/assets/gemini-screenshot.png +0 -0
  5. package/dist/docs/assets/release_patch.png +0 -0
  6. package/dist/docs/assets/theme-ansi-light.png +0 -0
  7. package/dist/docs/assets/theme-ansi.png +0 -0
  8. package/dist/docs/assets/theme-atom-one.png +0 -0
  9. package/dist/docs/assets/theme-ayu-light.png +0 -0
  10. package/dist/docs/assets/theme-ayu.png +0 -0
  11. package/dist/docs/assets/theme-custom.png +0 -0
  12. package/dist/docs/assets/theme-default-light.png +0 -0
  13. package/dist/docs/assets/theme-default.png +0 -0
  14. package/dist/docs/assets/theme-dracula.png +0 -0
  15. package/dist/docs/assets/theme-github-light.png +0 -0
  16. package/dist/docs/assets/theme-github.png +0 -0
  17. package/dist/docs/assets/theme-google-light.png +0 -0
  18. package/dist/docs/assets/theme-xcode-light.png +0 -0
  19. package/dist/docs/changelogs/index.md +592 -0
  20. package/dist/docs/changelogs/latest.md +225 -0
  21. package/dist/docs/changelogs/preview.md +129 -0
  22. package/dist/docs/changelogs/releases.md +896 -0
  23. package/dist/docs/cli/authentication.md +3 -0
  24. package/dist/docs/cli/checkpointing.md +94 -0
  25. package/dist/docs/cli/commands.md +354 -0
  26. package/dist/docs/cli/configuration.md +780 -0
  27. package/dist/docs/cli/custom-commands.md +315 -0
  28. package/dist/docs/cli/enterprise.md +565 -0
  29. package/dist/docs/cli/gemini-ignore.md +71 -0
  30. package/dist/docs/cli/gemini-md.md +108 -0
  31. package/dist/docs/cli/generation-settings.md +210 -0
  32. package/dist/docs/cli/headless.md +388 -0
  33. package/dist/docs/cli/index.md +63 -0
  34. package/dist/docs/cli/keyboard-shortcuts.md +143 -0
  35. package/dist/docs/cli/model-routing.md +37 -0
  36. package/dist/docs/cli/model.md +62 -0
  37. package/dist/docs/cli/sandbox.md +171 -0
  38. package/dist/docs/cli/session-management.md +158 -0
  39. package/dist/docs/cli/settings.md +112 -0
  40. package/dist/docs/cli/system-prompt.md +93 -0
  41. package/dist/docs/cli/telemetry.md +791 -0
  42. package/dist/docs/cli/themes.md +237 -0
  43. package/dist/docs/cli/token-caching.md +20 -0
  44. package/dist/docs/cli/trusted-folders.md +95 -0
  45. package/dist/docs/cli/tutorials.md +83 -0
  46. package/dist/docs/cli/uninstall.md +47 -0
  47. package/dist/docs/core/index.md +101 -0
  48. package/dist/docs/core/memport.md +244 -0
  49. package/dist/docs/core/policy-engine.md +267 -0
  50. package/dist/docs/core/tools-api.md +131 -0
  51. package/dist/docs/examples/proxy-script.md +83 -0
  52. package/dist/docs/extensions/extension-releasing.md +183 -0
  53. package/dist/docs/extensions/getting-started-extensions.md +245 -0
  54. package/dist/docs/extensions/index.md +293 -0
  55. package/dist/docs/faq.md +154 -0
  56. package/dist/docs/get-started/authentication.md +321 -0
  57. package/dist/docs/get-started/configuration-v1.md +888 -0
  58. package/dist/docs/get-started/configuration.md +1444 -0
  59. package/dist/docs/get-started/deployment.md +143 -0
  60. package/dist/docs/get-started/examples.md +219 -0
  61. package/dist/docs/get-started/gemini-3.md +116 -0
  62. package/dist/docs/get-started/index.md +71 -0
  63. package/dist/docs/get-started/installation.md +141 -0
  64. package/dist/docs/hooks/best-practices.md +806 -0
  65. package/dist/docs/hooks/index.md +665 -0
  66. package/dist/docs/hooks/reference.md +168 -0
  67. package/dist/docs/hooks/writing-hooks.md +1026 -0
  68. package/dist/docs/ide-integration/ide-companion-spec.md +267 -0
  69. package/dist/docs/ide-integration/index.md +202 -0
  70. package/dist/docs/index.md +147 -0
  71. package/dist/docs/integration-tests.md +211 -0
  72. package/dist/docs/issue-and-pr-automation.md +134 -0
  73. package/dist/docs/local-development.md +128 -0
  74. package/dist/docs/mermaid/context.mmd +103 -0
  75. package/dist/docs/mermaid/render-path.mmd +64 -0
  76. package/dist/docs/npm.md +62 -0
  77. package/dist/docs/quota-and-pricing.md +158 -0
  78. package/dist/docs/release-confidence.md +164 -0
  79. package/dist/docs/releases.md +540 -0
  80. package/dist/docs/sidebar.json +297 -0
  81. package/dist/docs/tools/file-system.md +217 -0
  82. package/dist/docs/tools/index.md +95 -0
  83. package/dist/docs/tools/mcp-server.md +1044 -0
  84. package/dist/docs/tools/memory.md +54 -0
  85. package/dist/docs/tools/shell.md +260 -0
  86. package/dist/docs/tools/todos.md +57 -0
  87. package/dist/docs/tools/web-fetch.md +59 -0
  88. package/dist/docs/tools/web-search.md +42 -0
  89. package/dist/docs/tos-privacy.md +96 -0
  90. package/dist/docs/troubleshooting.md +158 -0
  91. package/dist/google-gemini-cli-core-0.21.0-nightly.20251219.70696e364.tgz +0 -0
  92. package/dist/src/agents/delegate-to-agent-tool.test.js +1 -0
  93. package/dist/src/agents/delegate-to-agent-tool.test.js.map +1 -1
  94. package/dist/src/agents/introspection-agent.d.ts +23 -0
  95. package/dist/src/agents/introspection-agent.js +72 -0
  96. package/dist/src/agents/introspection-agent.js.map +1 -0
  97. package/dist/src/agents/introspection-agent.test.d.ts +6 -0
  98. package/dist/src/agents/introspection-agent.test.js +47 -0
  99. package/dist/src/agents/introspection-agent.test.js.map +1 -0
  100. package/dist/src/agents/local-executor.js +14 -12
  101. package/dist/src/agents/local-executor.js.map +1 -1
  102. package/dist/src/agents/local-executor.test.js +3 -0
  103. package/dist/src/agents/local-executor.test.js.map +1 -1
  104. package/dist/src/agents/registry.js +6 -0
  105. package/dist/src/agents/registry.js.map +1 -1
  106. package/dist/src/agents/registry.test.js +16 -0
  107. package/dist/src/agents/registry.test.js.map +1 -1
  108. package/dist/src/config/config.d.ts +6 -0
  109. package/dist/src/config/config.js +22 -0
  110. package/dist/src/config/config.js.map +1 -1
  111. package/dist/src/config/config.test.js +59 -1
  112. package/dist/src/config/config.test.js.map +1 -1
  113. package/dist/src/core/client.js +8 -4
  114. package/dist/src/core/client.js.map +1 -1
  115. package/dist/src/core/client.test.js +20 -0
  116. package/dist/src/core/client.test.js.map +1 -1
  117. package/dist/src/core/clientHookTriggers.js +2 -2
  118. package/dist/src/core/clientHookTriggers.js.map +1 -1
  119. package/dist/src/core/coreToolHookTriggers.js +3 -3
  120. package/dist/src/core/coreToolHookTriggers.js.map +1 -1
  121. package/dist/src/core/geminiChatHookTriggers.js +3 -3
  122. package/dist/src/core/geminiChatHookTriggers.js.map +1 -1
  123. package/dist/src/core/sessionHookTriggers.js +3 -3
  124. package/dist/src/core/sessionHookTriggers.js.map +1 -1
  125. package/dist/src/generated/git-commit.d.ts +2 -2
  126. package/dist/src/generated/git-commit.js +2 -2
  127. package/dist/src/hooks/hookEventHandler.js +10 -4
  128. package/dist/src/hooks/hookEventHandler.js.map +1 -1
  129. package/dist/src/hooks/hookEventHandler.test.js +40 -0
  130. package/dist/src/hooks/hookEventHandler.test.js.map +1 -1
  131. package/dist/src/hooks/hookRunner.js +12 -8
  132. package/dist/src/hooks/hookRunner.js.map +1 -1
  133. package/dist/src/hooks/hookRunner.test.js +58 -33
  134. package/dist/src/hooks/hookRunner.test.js.map +1 -1
  135. package/dist/src/mcp/oauth-provider.js +6 -2
  136. package/dist/src/mcp/oauth-provider.js.map +1 -1
  137. package/dist/src/mcp/oauth-provider.test.js +4 -1
  138. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  139. package/dist/src/mcp/oauth-utils.d.ts +8 -1
  140. package/dist/src/mcp/oauth-utils.js +30 -1
  141. package/dist/src/mcp/oauth-utils.js.map +1 -1
  142. package/dist/src/mcp/oauth-utils.test.js +42 -0
  143. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  144. package/dist/src/services/contextManager.d.ts +5 -11
  145. package/dist/src/services/contextManager.js +20 -17
  146. package/dist/src/services/contextManager.js.map +1 -1
  147. package/dist/src/services/contextManager.test.js +40 -41
  148. package/dist/src/services/contextManager.test.js.map +1 -1
  149. package/dist/src/tools/get-internal-docs.d.ts +27 -0
  150. package/dist/src/tools/get-internal-docs.js +129 -0
  151. package/dist/src/tools/get-internal-docs.js.map +1 -0
  152. package/dist/src/tools/get-internal-docs.test.d.ts +6 -0
  153. package/dist/src/tools/get-internal-docs.test.js +56 -0
  154. package/dist/src/tools/get-internal-docs.test.js.map +1 -0
  155. package/dist/src/tools/tool-names.d.ts +1 -0
  156. package/dist/src/tools/tool-names.js +1 -0
  157. package/dist/src/tools/tool-names.js.map +1 -1
  158. package/dist/src/utils/environmentContext.js +3 -0
  159. package/dist/src/utils/environmentContext.js.map +1 -1
  160. package/dist/src/utils/environmentContext.test.js +2 -0
  161. package/dist/src/utils/environmentContext.test.js.map +1 -1
  162. package/dist/src/utils/events.d.ts +3 -2
  163. package/dist/src/utils/events.js.map +1 -1
  164. package/dist/src/utils/memoryDiscovery.js +1 -1
  165. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  166. package/dist/src/utils/memoryDiscovery.test.js +3 -1
  167. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  168. package/dist/src/utils/shell-utils.js +25 -4
  169. package/dist/src/utils/shell-utils.js.map +1 -1
  170. package/dist/tsconfig.tsbuildinfo +1 -1
  171. package/package.json +1 -1
  172. package/dist/google-gemini-cli-core-0.21.0-nightly.20251218.739c02bd6.tgz +0 -0
@@ -0,0 +1,108 @@
1
+ # Provide context with GEMINI.md files
2
+
3
+ Context files, which use the default name `GEMINI.md`, are a powerful feature
4
+ for providing instructional context to the Gemini model. You can use these files
5
+ to give project-specific instructions, define a persona, or provide coding style
6
+ guides to make the AI's responses more accurate and tailored to your needs.
7
+
8
+ Instead of repeating instructions in every prompt, you can define them once in a
9
+ context file.
10
+
11
+ ## Understand the context hierarchy
12
+
13
+ The CLI uses a hierarchical system to source context. It loads various context
14
+ files from several locations, concatenates the contents of all found files, and
15
+ sends them to the model with every prompt. The CLI loads files in the following
16
+ order:
17
+
18
+ 1. **Global context file:**
19
+ - **Location:** `~/.gemini/GEMINI.md` (in your user home directory).
20
+ - **Scope:** Provides default instructions for all your projects.
21
+
22
+ 2. **Project root and ancestor context files:**
23
+ - **Location:** The CLI searches for a `GEMINI.md` file in your current
24
+ working directory and then in each parent directory up to the project root
25
+ (identified by a `.git` folder).
26
+ - **Scope:** Provides context relevant to the entire project.
27
+
28
+ 3. **Sub-directory context files:**
29
+ - **Location:** The CLI also scans for `GEMINI.md` files in subdirectories
30
+ below your current working directory. It respects rules in `.gitignore`
31
+ and `.geminiignore`.
32
+ - **Scope:** Lets you write highly specific instructions for a particular
33
+ component or module.
34
+
35
+ The CLI footer displays the number of loaded context files, which gives you a
36
+ quick visual cue of the active instructional context.
37
+
38
+ ### Example `GEMINI.md` file
39
+
40
+ Here is an example of what you can include in a `GEMINI.md` file at the root of
41
+ a TypeScript project:
42
+
43
+ ```markdown
44
+ # Project: My TypeScript Library
45
+
46
+ ## General Instructions
47
+
48
+ - When you generate new TypeScript code, follow the existing coding style.
49
+ - Ensure all new functions and classes have JSDoc comments.
50
+ - Prefer functional programming paradigms where appropriate.
51
+
52
+ ## Coding Style
53
+
54
+ - Use 2 spaces for indentation.
55
+ - Prefix interface names with `I` (for example, `IUserService`).
56
+ - Always use strict equality (`===` and `!==`).
57
+ ```
58
+
59
+ ## Manage context with the `/memory` command
60
+
61
+ You can interact with the loaded context files by using the `/memory` command.
62
+
63
+ - **`/memory show`**: Displays the full, concatenated content of the current
64
+ hierarchical memory. This lets you inspect the exact instructional context
65
+ being provided to the model.
66
+ - **`/memory refresh`**: Forces a re-scan and reload of all `GEMINI.md` files
67
+ from all configured locations.
68
+ - **`/memory add <text>`**: Appends your text to your global
69
+ `~/.gemini/GEMINI.md` file. This lets you add persistent memories on the fly.
70
+
71
+ ## Modularize context with imports
72
+
73
+ You can break down large `GEMINI.md` files into smaller, more manageable
74
+ components by importing content from other files using the `@file.md` syntax.
75
+ This feature supports both relative and absolute paths.
76
+
77
+ **Example `GEMINI.md` with imports:**
78
+
79
+ ```markdown
80
+ # Main GEMINI.md file
81
+
82
+ This is the main content.
83
+
84
+ @./components/instructions.md
85
+
86
+ More content here.
87
+
88
+ @../shared/style-guide.md
89
+ ```
90
+
91
+ For more details, see the [Memory Import Processor](../core/memport.md)
92
+ documentation.
93
+
94
+ ## Customize the context file name
95
+
96
+ While `GEMINI.md` is the default filename, you can configure this in your
97
+ `settings.json` file. To specify a different name or a list of names, use the
98
+ `context.fileName` property.
99
+
100
+ **Example `settings.json`:**
101
+
102
+ ```json
103
+ {
104
+ "context": {
105
+ "fileName": ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]
106
+ }
107
+ }
108
+ ```
@@ -0,0 +1,210 @@
1
+ # Advanced Model Configuration
2
+
3
+ This guide details the Model Configuration system within the Gemini CLI.
4
+ Designed for researchers, AI quality engineers, and advanced users, this system
5
+ provides a rigorous framework for managing generative model hyperparameters and
6
+ behaviors.
7
+
8
+ > **Warning**: This is a power-user feature. Configuration values are passed
9
+ > directly to the model provider with minimal validation. Incorrect settings
10
+ > (e.g., incompatible parameter combinations) may result in runtime errors from
11
+ > the API.
12
+
13
+ ## 1. System Overview
14
+
15
+ The Model Configuration system (`ModelConfigService`) enables deterministic
16
+ control over model generation. It decouples the requested model identifier
17
+ (e.g., a CLI flag or agent request) from the underlying API configuration. This
18
+ allows for:
19
+
20
+ - **Precise Hyperparameter Tuning**: Direct control over `temperature`, `topP`,
21
+ `thinkingBudget`, and other SDK-level parameters.
22
+ - **Environment-Specific Behavior**: Distinct configurations for different
23
+ operating contexts (e.g., testing vs. production).
24
+ - **Agent-Scoped Customization**: Applying specific settings only when a
25
+ particular agent is active.
26
+
27
+ The system operates on two core primitives: **Aliases** and **Overrides**.
28
+
29
+ ## 2. Configuration Primitives
30
+
31
+ These settings are located under the `modelConfigs` key in your configuration
32
+ file.
33
+
34
+ ### Aliases (`customAliases`)
35
+
36
+ Aliases are named, reusable configuration presets. Users should define their own
37
+ aliases (or override system defaults) in the `customAliases` map.
38
+
39
+ - **Inheritance**: An alias can `extends` another alias (including system
40
+ defaults like `chat-base`), inheriting its `modelConfig`. Child aliases can
41
+ overwrite or augment inherited settings.
42
+ - **Abstract Aliases**: An alias is not required to specify a concrete `model`
43
+ if it serves purely as a base for other aliases.
44
+
45
+ **Example Hierarchy**:
46
+
47
+ ```json
48
+ "modelConfigs": {
49
+ "customAliases": {
50
+ "base": {
51
+ "modelConfig": {
52
+ "generateContentConfig": { "temperature": 0.0 }
53
+ }
54
+ },
55
+ "chat-base": {
56
+ "extends": "base",
57
+ "modelConfig": {
58
+ "generateContentConfig": { "temperature": 0.7 }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ ```
64
+
65
+ ### Overrides (`overrides`)
66
+
67
+ Overrides are conditional rules that inject configuration based on the runtime
68
+ context. They are evaluated dynamically for each model request.
69
+
70
+ - **Match Criteria**: Overrides apply when the request context matches the
71
+ specified `match` properties.
72
+ - `model`: Matches the requested model name or alias.
73
+ - `overrideScope`: Matches the distinct scope of the request (typically the
74
+ agent name, e.g., `codebaseInvestigator`).
75
+
76
+ **Example Override**:
77
+
78
+ ```json
79
+ "modelConfigs": {
80
+ "overrides": [
81
+ {
82
+ "match": {
83
+ "overrideScope": "codebaseInvestigator"
84
+ },
85
+ "modelConfig": {
86
+ "generateContentConfig": { "temperature": 0.1 }
87
+ }
88
+ }
89
+ ]
90
+ }
91
+ ```
92
+
93
+ ## 3. Resolution Strategy
94
+
95
+ The `ModelConfigService` resolves the final configuration through a two-step
96
+ process:
97
+
98
+ ### Step 1: Alias Resolution
99
+
100
+ The requested model string is looked up in the merged map of system `aliases`
101
+ and user `customAliases`.
102
+
103
+ 1. If found, the system recursively resolves the `extends` chain.
104
+ 2. Settings are merged from parent to child (child wins).
105
+ 3. This results in a base `ResolvedModelConfig`.
106
+ 4. If not found, the requested string is treated as the raw model name.
107
+
108
+ ### Step 2: Override Application
109
+
110
+ The system evaluates the `overrides` list against the request context (`model`
111
+ and `overrideScope`).
112
+
113
+ 1. **Filtering**: All matching overrides are identified.
114
+ 2. **Sorting**: Matches are prioritized by **specificity** (the number of
115
+ matched keys in the `match` object).
116
+ - Specific matches (e.g., `model` + `overrideScope`) override broad matches
117
+ (e.g., `model` only).
118
+ - Tie-breaking: If specificity is equal, the order of definition in the
119
+ `overrides` array is preserved (last one wins).
120
+ 3. **Merging**: The configurations from the sorted overrides are merged
121
+ sequentially onto the base configuration.
122
+
123
+ ## 4. Configuration Reference
124
+
125
+ The configuration follows the `ModelConfigServiceConfig` interface.
126
+
127
+ ### `ModelConfig` Object
128
+
129
+ Defines the actual parameters for the model.
130
+
131
+ | Property | Type | Description |
132
+ | :---------------------- | :------- | :----------------------------------------------------------------- |
133
+ | `model` | `string` | The identifier of the model to be called (e.g., `gemini-2.5-pro`). |
134
+ | `generateContentConfig` | `object` | The configuration object passed to the `@google/genai` SDK. |
135
+
136
+ ### `GenerateContentConfig` (Common Parameters)
137
+
138
+ Directly maps to the SDK's `GenerateContentConfig`. Common parameters include:
139
+
140
+ - **`temperature`**: (`number`) Controls output randomness. Lower values (0.0)
141
+ are deterministic; higher values (>0.7) are creative.
142
+ - **`topP`**: (`number`) Nucleus sampling probability.
143
+ - **`maxOutputTokens`**: (`number`) Limit on generated response length.
144
+ - **`thinkingConfig`**: (`object`) Configuration for models with reasoning
145
+ capabilities (e.g., `thinkingBudget`, `includeThoughts`).
146
+
147
+ ## 5. Practical Examples
148
+
149
+ ### Defining a Deterministic Baseline
150
+
151
+ Create an alias for tasks requiring high precision, extending the standard chat
152
+ configuration but enforcing zero temperature.
153
+
154
+ ```json
155
+ "modelConfigs": {
156
+ "customAliases": {
157
+ "precise-mode": {
158
+ "extends": "chat-base",
159
+ "modelConfig": {
160
+ "generateContentConfig": {
161
+ "temperature": 0.0,
162
+ "topP": 1.0
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ ### Agent-Specific Parameter Injection
171
+
172
+ Enforce extended thinking budgets for a specific agent without altering the
173
+ global default, e.g. for the `codebaseInvestigator`.
174
+
175
+ ```json
176
+ "modelConfigs": {
177
+ "overrides": [
178
+ {
179
+ "match": {
180
+ "overrideScope": "codebaseInvestigator"
181
+ },
182
+ "modelConfig": {
183
+ "generateContentConfig": {
184
+ "thinkingConfig": { "thinkingBudget": 4096 }
185
+ }
186
+ }
187
+ }
188
+ ]
189
+ }
190
+ ```
191
+
192
+ ### Experimental Model Evaluation
193
+
194
+ Route traffic for a specific alias to a preview model for A/B testing, without
195
+ changing client code.
196
+
197
+ ```json
198
+ "modelConfigs": {
199
+ "overrides": [
200
+ {
201
+ "match": {
202
+ "model": "gemini-2.5-pro"
203
+ },
204
+ "modelConfig": {
205
+ "model": "gemini-2.5-pro-experimental-001"
206
+ }
207
+ }
208
+ ]
209
+ }
210
+ ```
@@ -0,0 +1,388 @@
1
+ # Headless mode
2
+
3
+ Headless mode allows you to run Gemini CLI programmatically from command line
4
+ scripts and automation tools without any interactive UI. This is ideal for
5
+ scripting, automation, CI/CD pipelines, and building AI-powered tools.
6
+
7
+ - [Headless Mode](#headless-mode)
8
+ - [Overview](#overview)
9
+ - [Basic Usage](#basic-usage)
10
+ - [Direct Prompts](#direct-prompts)
11
+ - [Stdin Input](#stdin-input)
12
+ - [Combining with File Input](#combining-with-file-input)
13
+ - [Output Formats](#output-formats)
14
+ - [Text Output (Default)](#text-output-default)
15
+ - [JSON Output](#json-output)
16
+ - [Response Schema](#response-schema)
17
+ - [Example Usage](#example-usage)
18
+ - [Streaming JSON Output](#streaming-json-output)
19
+ - [When to Use Streaming JSON](#when-to-use-streaming-json)
20
+ - [Event Types](#event-types)
21
+ - [Basic Usage](#basic-usage)
22
+ - [Example Output](#example-output)
23
+ - [Processing Stream Events](#processing-stream-events)
24
+ - [Real-World Examples](#real-world-examples)
25
+ - [File Redirection](#file-redirection)
26
+ - [Configuration Options](#configuration-options)
27
+ - [Examples](#examples)
28
+ - [Code review](#code-review)
29
+ - [Generate commit messages](#generate-commit-messages)
30
+ - [API documentation](#api-documentation)
31
+ - [Batch code analysis](#batch-code-analysis)
32
+ - [Code review](#code-review-1)
33
+ - [Log analysis](#log-analysis)
34
+ - [Release notes generation](#release-notes-generation)
35
+ - [Model and tool usage tracking](#model-and-tool-usage-tracking)
36
+ - [Resources](#resources)
37
+
38
+ ## Overview
39
+
40
+ The headless mode provides a headless interface to Gemini CLI that:
41
+
42
+ - Accepts prompts via command line arguments or stdin
43
+ - Returns structured output (text or JSON)
44
+ - Supports file redirection and piping
45
+ - Enables automation and scripting workflows
46
+ - Provides consistent exit codes for error handling
47
+
48
+ ## Basic usage
49
+
50
+ ### Direct prompts
51
+
52
+ Use the `--prompt` (or `-p`) flag to run in headless mode:
53
+
54
+ ```bash
55
+ gemini --prompt "What is machine learning?"
56
+ ```
57
+
58
+ ### Stdin input
59
+
60
+ Pipe input to Gemini CLI from your terminal:
61
+
62
+ ```bash
63
+ echo "Explain this code" | gemini
64
+ ```
65
+
66
+ ### Combining with file input
67
+
68
+ Read from files and process with Gemini:
69
+
70
+ ```bash
71
+ cat README.md | gemini --prompt "Summarize this documentation"
72
+ ```
73
+
74
+ ## Output formats
75
+
76
+ ### Text output (default)
77
+
78
+ Standard human-readable output:
79
+
80
+ ```bash
81
+ gemini -p "What is the capital of France?"
82
+ ```
83
+
84
+ Response format:
85
+
86
+ ```
87
+ The capital of France is Paris.
88
+ ```
89
+
90
+ ### JSON output
91
+
92
+ Returns structured data including response, statistics, and metadata. This
93
+ format is ideal for programmatic processing and automation scripts.
94
+
95
+ #### Response schema
96
+
97
+ The JSON output follows this high-level structure:
98
+
99
+ ```json
100
+ {
101
+ "response": "string", // The main AI-generated content answering your prompt
102
+ "stats": {
103
+ // Usage metrics and performance data
104
+ "models": {
105
+ // Per-model API and token usage statistics
106
+ "[model-name]": {
107
+ "api": {
108
+ /* request counts, errors, latency */
109
+ },
110
+ "tokens": {
111
+ /* prompt, response, cached, total counts */
112
+ }
113
+ }
114
+ },
115
+ "tools": {
116
+ // Tool execution statistics
117
+ "totalCalls": "number",
118
+ "totalSuccess": "number",
119
+ "totalFail": "number",
120
+ "totalDurationMs": "number",
121
+ "totalDecisions": {
122
+ /* accept, reject, modify, auto_accept counts */
123
+ },
124
+ "byName": {
125
+ /* per-tool detailed stats */
126
+ }
127
+ },
128
+ "files": {
129
+ // File modification statistics
130
+ "totalLinesAdded": "number",
131
+ "totalLinesRemoved": "number"
132
+ }
133
+ },
134
+ "error": {
135
+ // Present only when an error occurred
136
+ "type": "string", // Error type (e.g., "ApiError", "AuthError")
137
+ "message": "string", // Human-readable error description
138
+ "code": "number" // Optional error code
139
+ }
140
+ }
141
+ ```
142
+
143
+ #### Example usage
144
+
145
+ ```bash
146
+ gemini -p "What is the capital of France?" --output-format json
147
+ ```
148
+
149
+ Response:
150
+
151
+ ```json
152
+ {
153
+ "response": "The capital of France is Paris.",
154
+ "stats": {
155
+ "models": {
156
+ "gemini-2.5-pro": {
157
+ "api": {
158
+ "totalRequests": 2,
159
+ "totalErrors": 0,
160
+ "totalLatencyMs": 5053
161
+ },
162
+ "tokens": {
163
+ "prompt": 24939,
164
+ "candidates": 20,
165
+ "total": 25113,
166
+ "cached": 21263,
167
+ "thoughts": 154,
168
+ "tool": 0
169
+ }
170
+ },
171
+ "gemini-2.5-flash": {
172
+ "api": {
173
+ "totalRequests": 1,
174
+ "totalErrors": 0,
175
+ "totalLatencyMs": 1879
176
+ },
177
+ "tokens": {
178
+ "prompt": 8965,
179
+ "candidates": 10,
180
+ "total": 9033,
181
+ "cached": 0,
182
+ "thoughts": 30,
183
+ "tool": 28
184
+ }
185
+ }
186
+ },
187
+ "tools": {
188
+ "totalCalls": 1,
189
+ "totalSuccess": 1,
190
+ "totalFail": 0,
191
+ "totalDurationMs": 1881,
192
+ "totalDecisions": {
193
+ "accept": 0,
194
+ "reject": 0,
195
+ "modify": 0,
196
+ "auto_accept": 1
197
+ },
198
+ "byName": {
199
+ "google_web_search": {
200
+ "count": 1,
201
+ "success": 1,
202
+ "fail": 0,
203
+ "durationMs": 1881,
204
+ "decisions": {
205
+ "accept": 0,
206
+ "reject": 0,
207
+ "modify": 0,
208
+ "auto_accept": 1
209
+ }
210
+ }
211
+ }
212
+ },
213
+ "files": {
214
+ "totalLinesAdded": 0,
215
+ "totalLinesRemoved": 0
216
+ }
217
+ }
218
+ }
219
+ ```
220
+
221
+ ### Streaming JSON output
222
+
223
+ Returns real-time events as newline-delimited JSON (JSONL). Each significant
224
+ action (initialization, messages, tool calls, results) emits immediately as it
225
+ occurs. This format is ideal for monitoring long-running operations, building
226
+ UIs with live progress, and creating automation pipelines that react to events.
227
+
228
+ #### When to use streaming JSON
229
+
230
+ Use `--output-format stream-json` when you need:
231
+
232
+ - **Real-time progress monitoring** - See tool calls and responses as they
233
+ happen
234
+ - **Event-driven automation** - React to specific events (e.g., tool failures)
235
+ - **Live UI updates** - Build interfaces showing AI agent activity in real-time
236
+ - **Detailed execution logs** - Capture complete interaction history with
237
+ timestamps
238
+ - **Pipeline integration** - Stream events to logging/monitoring systems
239
+
240
+ #### Event types
241
+
242
+ The streaming format emits 6 event types:
243
+
244
+ 1. **`init`** - Session starts (includes session_id, model)
245
+ 2. **`message`** - User prompts and assistant responses
246
+ 3. **`tool_use`** - Tool call requests with parameters
247
+ 4. **`tool_result`** - Tool execution results (success/error)
248
+ 5. **`error`** - Non-fatal errors and warnings
249
+ 6. **`result`** - Final session outcome with aggregated stats
250
+
251
+ #### Basic usage
252
+
253
+ ```bash
254
+ # Stream events to console
255
+ gemini --output-format stream-json --prompt "What is 2+2?"
256
+
257
+ # Save event stream to file
258
+ gemini --output-format stream-json --prompt "Analyze this code" > events.jsonl
259
+
260
+ # Parse with jq
261
+ gemini --output-format stream-json --prompt "List files" | jq -r '.type'
262
+ ```
263
+
264
+ #### Example output
265
+
266
+ Each line is a complete JSON event:
267
+
268
+ ```jsonl
269
+ {"type":"init","timestamp":"2025-10-10T12:00:00.000Z","session_id":"abc123","model":"gemini-2.0-flash-exp"}
270
+ {"type":"message","role":"user","content":"List files in current directory","timestamp":"2025-10-10T12:00:01.000Z"}
271
+ {"type":"tool_use","tool_name":"Bash","tool_id":"bash-123","parameters":{"command":"ls -la"},"timestamp":"2025-10-10T12:00:02.000Z"}
272
+ {"type":"tool_result","tool_id":"bash-123","status":"success","output":"file1.txt\nfile2.txt","timestamp":"2025-10-10T12:00:03.000Z"}
273
+ {"type":"message","role":"assistant","content":"Here are the files...","delta":true,"timestamp":"2025-10-10T12:00:04.000Z"}
274
+ {"type":"result","status":"success","stats":{"total_tokens":250,"input_tokens":50,"output_tokens":200,"duration_ms":3000,"tool_calls":1},"timestamp":"2025-10-10T12:00:05.000Z"}
275
+ ```
276
+
277
+ ### File redirection
278
+
279
+ Save output to files or pipe to other commands:
280
+
281
+ ```bash
282
+ # Save to file
283
+ gemini -p "Explain Docker" > docker-explanation.txt
284
+ gemini -p "Explain Docker" --output-format json > docker-explanation.json
285
+
286
+ # Append to file
287
+ gemini -p "Add more details" >> docker-explanation.txt
288
+
289
+ # Pipe to other tools
290
+ gemini -p "What is Kubernetes?" --output-format json | jq '.response'
291
+ gemini -p "Explain microservices" | wc -w
292
+ gemini -p "List programming languages" | grep -i "python"
293
+ ```
294
+
295
+ ## Configuration options
296
+
297
+ Key command-line options for headless usage:
298
+
299
+ | Option | Description | Example |
300
+ | ----------------------- | ---------------------------------- | -------------------------------------------------- |
301
+ | `--prompt`, `-p` | Run in headless mode | `gemini -p "query"` |
302
+ | `--output-format` | Specify output format (text, json) | `gemini -p "query" --output-format json` |
303
+ | `--model`, `-m` | Specify the Gemini model | `gemini -p "query" -m gemini-2.5-flash` |
304
+ | `--debug`, `-d` | Enable debug mode | `gemini -p "query" --debug` |
305
+ | `--include-directories` | Include additional directories | `gemini -p "query" --include-directories src,docs` |
306
+ | `--yolo`, `-y` | Auto-approve all actions | `gemini -p "query" --yolo` |
307
+ | `--approval-mode` | Set approval mode | `gemini -p "query" --approval-mode auto_edit` |
308
+
309
+ For complete details on all available configuration options, settings files, and
310
+ environment variables, see the
311
+ [Configuration Guide](../get-started/configuration.md).
312
+
313
+ ## Examples
314
+
315
+ #### Code review
316
+
317
+ ```bash
318
+ cat src/auth.py | gemini -p "Review this authentication code for security issues" > security-review.txt
319
+ ```
320
+
321
+ #### Generate commit messages
322
+
323
+ ```bash
324
+ result=$(git diff --cached | gemini -p "Write a concise commit message for these changes" --output-format json)
325
+ echo "$result" | jq -r '.response'
326
+ ```
327
+
328
+ #### API documentation
329
+
330
+ ```bash
331
+ result=$(cat api/routes.js | gemini -p "Generate OpenAPI spec for these routes" --output-format json)
332
+ echo "$result" | jq -r '.response' > openapi.json
333
+ ```
334
+
335
+ #### Batch code analysis
336
+
337
+ ```bash
338
+ for file in src/*.py; do
339
+ echo "Analyzing $file..."
340
+ result=$(cat "$file" | gemini -p "Find potential bugs and suggest improvements" --output-format json)
341
+ echo "$result" | jq -r '.response' > "reports/$(basename "$file").analysis"
342
+ echo "Completed analysis for $(basename "$file")" >> reports/progress.log
343
+ done
344
+ ```
345
+
346
+ #### Code review
347
+
348
+ ```bash
349
+ result=$(git diff origin/main...HEAD | gemini -p "Review these changes for bugs, security issues, and code quality" --output-format json)
350
+ echo "$result" | jq -r '.response' > pr-review.json
351
+ ```
352
+
353
+ #### Log analysis
354
+
355
+ ```bash
356
+ grep "ERROR" /var/log/app.log | tail -20 | gemini -p "Analyze these errors and suggest root cause and fixes" > error-analysis.txt
357
+ ```
358
+
359
+ #### Release notes generation
360
+
361
+ ```bash
362
+ result=$(git log --oneline v1.0.0..HEAD | gemini -p "Generate release notes from these commits" --output-format json)
363
+ response=$(echo "$result" | jq -r '.response')
364
+ echo "$response"
365
+ echo "$response" >> CHANGELOG.md
366
+ ```
367
+
368
+ #### Model and tool usage tracking
369
+
370
+ ```bash
371
+ result=$(gemini -p "Explain this database schema" --include-directories db --output-format json)
372
+ total_tokens=$(echo "$result" | jq -r '.stats.models // {} | to_entries | map(.value.tokens.total) | add // 0')
373
+ models_used=$(echo "$result" | jq -r '.stats.models // {} | keys | join(", ") | if . == "" then "none" else . end')
374
+ tool_calls=$(echo "$result" | jq -r '.stats.tools.totalCalls // 0')
375
+ tools_used=$(echo "$result" | jq -r '.stats.tools.byName // {} | keys | join(", ") | if . == "" then "none" else . end')
376
+ echo "$(date): $total_tokens tokens, $tool_calls tool calls ($tools_used) used with models: $models_used" >> usage.log
377
+ echo "$result" | jq -r '.response' > schema-docs.md
378
+ echo "Recent usage trends:"
379
+ tail -5 usage.log
380
+ ```
381
+
382
+ ## Resources
383
+
384
+ - [CLI Configuration](../get-started/configuration.md) - Complete configuration
385
+ guide
386
+ - [Authentication](../get-started/authentication.md) - Setup authentication
387
+ - [Commands](./commands.md) - Interactive commands reference
388
+ - [Tutorials](./tutorials.md) - Step-by-step automation guides