@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,665 @@
1
+ # Gemini CLI hooks
2
+
3
+ Hooks are scripts or programs that Gemini CLI executes at specific points in the
4
+ agentic loop, allowing you to intercept and customize behavior without modifying
5
+ the CLI's source code.
6
+
7
+ See [writing hooks guide](writing-hooks.md) for a tutorial on creating your
8
+ first hook and a comprehensive example.
9
+
10
+ See [hooks reference](reference.md) for the technical specification of the I/O
11
+ schemas.
12
+
13
+ See [best practices](best-practices.md) for guidelines on security, performance,
14
+ and debugging.
15
+
16
+ ## What are hooks?
17
+
18
+ With hooks, you can:
19
+
20
+ - **Add context:** Inject relevant information before the model processes a
21
+ request
22
+ - **Validate actions:** Review and block potentially dangerous operations
23
+ - **Enforce policies:** Implement security and compliance requirements
24
+ - **Log interactions:** Track tool usage and model responses
25
+ - **Optimize behavior:** Dynamically adjust tool selection or model parameters
26
+
27
+ Hooks run synchronously as part of the agent loop—when a hook event fires,
28
+ Gemini CLI waits for all matching hooks to complete before continuing.
29
+
30
+ ## Core concepts
31
+
32
+ ### Hook events
33
+
34
+ Hooks are triggered by specific events in Gemini CLI's lifecycle. The following
35
+ table lists all available hook events:
36
+
37
+ | Event | When It Fires | Common Use Cases |
38
+ | --------------------- | --------------------------------------------- | ------------------------------------------ |
39
+ | `SessionStart` | When a session begins | Initialize resources, load context |
40
+ | `SessionEnd` | When a session ends | Clean up, save state |
41
+ | `BeforeAgent` | After user submits prompt, before planning | Add context, validate prompts |
42
+ | `AfterAgent` | When agent loop ends | Review output, force continuation |
43
+ | `BeforeModel` | Before sending request to LLM | Modify prompts, add instructions |
44
+ | `AfterModel` | After receiving LLM response | Filter responses, log interactions |
45
+ | `BeforeToolSelection` | Before LLM selects tools (after BeforeModel) | Filter available tools, optimize selection |
46
+ | `BeforeTool` | Before a tool executes | Validate arguments, block dangerous ops |
47
+ | `AfterTool` | After a tool executes | Process results, run tests |
48
+ | `PreCompress` | Before context compression | Save state, notify user |
49
+ | `Notification` | When a notification occurs (e.g., permission) | Auto-approve, log decisions |
50
+
51
+ ### Hook types
52
+
53
+ Gemini CLI currently supports **command hooks** that run shell commands or
54
+ scripts:
55
+
56
+ ```json
57
+ {
58
+ "type": "command",
59
+ "command": "$GEMINI_PROJECT_DIR/.gemini/hooks/my-hook.sh",
60
+ "timeout": 30000
61
+ }
62
+ ```
63
+
64
+ **Note:** Plugin hooks (npm packages) are planned for a future release.
65
+
66
+ ### Matchers
67
+
68
+ For tool-related events (`BeforeTool`, `AfterTool`), you can filter which tools
69
+ trigger the hook:
70
+
71
+ ```json
72
+ {
73
+ "hooks": {
74
+ "BeforeTool": [
75
+ {
76
+ "matcher": "write_file|replace",
77
+ "hooks": [
78
+ /* hooks for write operations */
79
+ ]
80
+ }
81
+ ]
82
+ }
83
+ }
84
+ ```
85
+
86
+ **Matcher patterns:**
87
+
88
+ - **Exact match:** `"read_file"` matches only `read_file`
89
+ - **Regex:** `"write_.*|replace"` matches `write_file`, `replace`
90
+ - **Wildcard:** `"*"` or `""` matches all tools
91
+
92
+ **Session event matchers:**
93
+
94
+ - **SessionStart:** `startup`, `resume`, `clear`
95
+ - **SessionEnd:** `exit`, `clear`, `logout`, `prompt_input_exit`
96
+ - **PreCompress:** `manual`, `auto`
97
+ - **Notification:** `ToolPermission`
98
+
99
+ ## Hook input/output contract
100
+
101
+ ### Command hook communication
102
+
103
+ Hooks communicate via:
104
+
105
+ - **Input:** JSON on stdin
106
+ - **Output:** Exit code + stdout/stderr
107
+
108
+ ### Exit codes
109
+
110
+ - **0:** Success - stdout shown to user (or injected as context for some events)
111
+ - **2:** Blocking error - stderr shown to agent/user, operation may be blocked
112
+ - **Other:** Non-blocking warning - logged but execution continues
113
+
114
+ ### Common input fields
115
+
116
+ Every hook receives these base fields:
117
+
118
+ ```json
119
+ {
120
+ "session_id": "abc123",
121
+ "transcript_path": "/path/to/transcript.jsonl",
122
+ "cwd": "/path/to/project",
123
+ "hook_event_name": "BeforeTool",
124
+ "timestamp": "2025-12-01T10:30:00Z"
125
+ // ... event-specific fields
126
+ }
127
+ ```
128
+
129
+ ### Event-specific fields
130
+
131
+ #### BeforeTool
132
+
133
+ **Input:**
134
+
135
+ ```json
136
+ {
137
+ "tool_name": "write_file",
138
+ "tool_input": {
139
+ "file_path": "/path/to/file.ts",
140
+ "content": "..."
141
+ }
142
+ }
143
+ ```
144
+
145
+ **Output (JSON on stdout):**
146
+
147
+ ```json
148
+ {
149
+ "decision": "allow|deny|ask|block",
150
+ "reason": "Explanation shown to agent",
151
+ "systemMessage": "Message shown to user"
152
+ }
153
+ ```
154
+
155
+ Or simple exit codes:
156
+
157
+ - Exit 0 = allow (stdout shown to user)
158
+ - Exit 2 = deny (stderr shown to agent)
159
+
160
+ #### AfterTool
161
+
162
+ **Input:**
163
+
164
+ ```json
165
+ {
166
+ "tool_name": "read_file",
167
+ "tool_input": { "file_path": "..." },
168
+ "tool_response": "file contents..."
169
+ }
170
+ ```
171
+
172
+ **Output:**
173
+
174
+ ```json
175
+ {
176
+ "decision": "allow|deny",
177
+ "hookSpecificOutput": {
178
+ "hookEventName": "AfterTool",
179
+ "additionalContext": "Extra context for agent"
180
+ }
181
+ }
182
+ ```
183
+
184
+ #### BeforeAgent
185
+
186
+ **Input:**
187
+
188
+ ```json
189
+ {
190
+ "prompt": "Fix the authentication bug"
191
+ }
192
+ ```
193
+
194
+ **Output:**
195
+
196
+ ```json
197
+ {
198
+ "decision": "allow|deny",
199
+ "hookSpecificOutput": {
200
+ "hookEventName": "BeforeAgent",
201
+ "additionalContext": "Recent project decisions: ..."
202
+ }
203
+ }
204
+ ```
205
+
206
+ #### BeforeModel
207
+
208
+ **Input:**
209
+
210
+ ```json
211
+ {
212
+ "llm_request": {
213
+ "model": "gemini-2.0-flash-exp",
214
+ "messages": [{ "role": "user", "content": "Hello" }],
215
+ "config": { "temperature": 0.7 },
216
+ "toolConfig": {
217
+ "functionCallingConfig": {
218
+ "mode": "AUTO",
219
+ "allowedFunctionNames": ["read_file", "write_file"]
220
+ }
221
+ }
222
+ }
223
+ }
224
+ ```
225
+
226
+ **Output:**
227
+
228
+ ```json
229
+ {
230
+ "decision": "allow",
231
+ "hookSpecificOutput": {
232
+ "hookEventName": "BeforeModel",
233
+ "llm_request": {
234
+ "messages": [
235
+ { "role": "system", "content": "Additional instructions..." },
236
+ { "role": "user", "content": "Hello" }
237
+ ]
238
+ }
239
+ }
240
+ }
241
+ ```
242
+
243
+ #### AfterModel
244
+
245
+ **Input:**
246
+
247
+ ```json
248
+ {
249
+ "llm_request": {
250
+ "model": "gemini-2.0-flash-exp",
251
+ "messages": [
252
+ /* ... */
253
+ ],
254
+ "config": {
255
+ /* ... */
256
+ },
257
+ "toolConfig": {
258
+ /* ... */
259
+ }
260
+ },
261
+ "llm_response": {
262
+ "text": "string",
263
+ "candidates": [
264
+ {
265
+ "content": {
266
+ "role": "model",
267
+ "parts": ["array of content parts"]
268
+ },
269
+ "finishReason": "STOP"
270
+ }
271
+ ]
272
+ }
273
+ }
274
+ ```
275
+
276
+ **Output:**
277
+
278
+ ```json
279
+ {
280
+ "hookSpecificOutput": {
281
+ "hookEventName": "AfterModel",
282
+ "llm_response": {
283
+ "candidate": {
284
+ /* modified response */
285
+ }
286
+ }
287
+ }
288
+ }
289
+ ```
290
+
291
+ #### BeforeToolSelection
292
+
293
+ **Input:**
294
+
295
+ ```json
296
+ {
297
+ "llm_request": {
298
+ "model": "gemini-2.0-flash-exp",
299
+ "messages": [
300
+ /* ... */
301
+ ],
302
+ "toolConfig": {
303
+ "functionCallingConfig": {
304
+ "mode": "AUTO",
305
+ "allowedFunctionNames": [
306
+ /* 100+ tools */
307
+ ]
308
+ }
309
+ }
310
+ }
311
+ }
312
+ ```
313
+
314
+ **Output:**
315
+
316
+ ```json
317
+ {
318
+ "hookSpecificOutput": {
319
+ "hookEventName": "BeforeToolSelection",
320
+ "toolConfig": {
321
+ "functionCallingConfig": {
322
+ "mode": "ANY",
323
+ "allowedFunctionNames": ["read_file", "write_file", "replace"]
324
+ }
325
+ }
326
+ }
327
+ }
328
+ ```
329
+
330
+ Or simple output (comma-separated tool names sets mode to ANY):
331
+
332
+ ```bash
333
+ echo "read_file,write_file,replace"
334
+ ```
335
+
336
+ #### SessionStart
337
+
338
+ **Input:**
339
+
340
+ ```json
341
+ {
342
+ "source": "startup|resume|clear"
343
+ }
344
+ ```
345
+
346
+ **Output:**
347
+
348
+ ```json
349
+ {
350
+ "hookSpecificOutput": {
351
+ "hookEventName": "SessionStart",
352
+ "additionalContext": "Loaded 5 project memories"
353
+ }
354
+ }
355
+ ```
356
+
357
+ #### SessionEnd
358
+
359
+ **Input:**
360
+
361
+ ```json
362
+ {
363
+ "reason": "exit|clear|logout|prompt_input_exit|other"
364
+ }
365
+ ```
366
+
367
+ No structured output expected (but stdout/stderr logged).
368
+
369
+ #### PreCompress
370
+
371
+ **Input:**
372
+
373
+ ```json
374
+ {
375
+ "trigger": "manual|auto"
376
+ }
377
+ ```
378
+
379
+ **Output:**
380
+
381
+ ```json
382
+ {
383
+ "systemMessage": "Compression starting..."
384
+ }
385
+ ```
386
+
387
+ #### Notification
388
+
389
+ **Input:**
390
+
391
+ ```json
392
+ {
393
+ "notification_type": "ToolPermission",
394
+ "message": "string",
395
+ "details": {
396
+ /* notification details */
397
+ }
398
+ }
399
+ ```
400
+
401
+ **Output:**
402
+
403
+ ```json
404
+ {
405
+ "systemMessage": "Notification logged"
406
+ }
407
+ ```
408
+
409
+ ## Configuration
410
+
411
+ Hook definitions are configured in `settings.json` files using the `hooks`
412
+ object. Configuration can be specified at multiple levels with defined
413
+ precedence rules.
414
+
415
+ ### Configuration layers
416
+
417
+ Hook configurations are applied in the following order of execution (lower
418
+ numbers run first):
419
+
420
+ 1. **Project settings:** `.gemini/settings.json` in your project directory
421
+ (highest priority)
422
+ 2. **User settings:** `~/.gemini/settings.json`
423
+ 3. **System settings:** `/etc/gemini-cli/settings.json`
424
+ 4. **Extensions:** Internal hooks defined by installed extensions (lowest
425
+ priority)
426
+
427
+ #### Deduplication and shadowing
428
+
429
+ If multiple hooks with the identical **name** and **command** are discovered
430
+ across different configuration layers, Gemini CLI deduplicates them. The hook
431
+ from the higher-priority layer (e.g., Project) will be kept, and others will be
432
+ ignored.
433
+
434
+ Within each level, hooks run in the order they are declared in the
435
+ configuration.
436
+
437
+ ### Configuration schema
438
+
439
+ ```json
440
+ {
441
+ "hooks": {
442
+ "EventName": [
443
+ {
444
+ "matcher": "pattern",
445
+ "hooks": [
446
+ {
447
+ "name": "hook-identifier",
448
+ "type": "command",
449
+ "command": "./path/to/script.sh",
450
+ "description": "What this hook does",
451
+ "timeout": 30000
452
+ }
453
+ ]
454
+ }
455
+ ]
456
+ }
457
+ }
458
+ ```
459
+
460
+ **Configuration properties:**
461
+
462
+ - **`name`** (string, recommended): Unique identifier for the hook used in
463
+ `/hooks enable/disable` commands. If omitted, the `command` path is used as
464
+ the identifier.
465
+ - **`type`** (string, required): Hook type - currently only `"command"` is
466
+ supported
467
+ - **`command`** (string, required): Path to the script or command to execute
468
+ - **`description`** (string, optional): Human-readable description shown in
469
+ `/hooks panel`
470
+ - **`timeout`** (number, optional): Timeout in milliseconds (default: 60000)
471
+ - **`matcher`** (string, optional): Pattern to filter when hook runs (event
472
+ matchers only)
473
+
474
+ ### Environment variables
475
+
476
+ Hooks have access to:
477
+
478
+ - `GEMINI_PROJECT_DIR`: Project root directory
479
+ - `GEMINI_SESSION_ID`: Current session ID
480
+ - `GEMINI_API_KEY`: Gemini API key (if configured)
481
+ - All other environment variables from the parent process
482
+
483
+ ## Managing hooks
484
+
485
+ ### View registered hooks
486
+
487
+ Use the `/hooks panel` command to view all registered hooks:
488
+
489
+ ```bash
490
+ /hooks panel
491
+ ```
492
+
493
+ This command displays:
494
+
495
+ - All active hooks organized by event
496
+ - Hook source (user, project, system)
497
+ - Hook type (command or plugin)
498
+ - Execution status and recent output
499
+
500
+ ### Enable and disable hooks
501
+
502
+ You can temporarily enable or disable individual hooks using commands:
503
+
504
+ ```bash
505
+ /hooks enable hook-name
506
+ /hooks disable hook-name
507
+ ```
508
+
509
+ These commands allow you to control hook execution without editing configuration
510
+ files. The hook name should match the `name` field in your hook configuration.
511
+ Changes made via these commands are persisted to your global User settings
512
+ (`~/.gemini/settings.json`).
513
+
514
+ ### Disabled hooks configuration
515
+
516
+ To permanently disable hooks, add them to the `hooks.disabled` array in your
517
+ `settings.json`:
518
+
519
+ ```json
520
+ {
521
+ "hooks": {
522
+ "disabled": ["secret-scanner", "auto-test"]
523
+ }
524
+ }
525
+ ```
526
+
527
+ **Note:** The `hooks.disabled` array uses a UNION merge strategy. Disabled hooks
528
+ from all configuration levels (user, project, system) are combined and
529
+ deduplicated, meaning a hook disabled at any level remains disabled.
530
+
531
+ ## Migration from Claude Code
532
+
533
+ If you have hooks configured for Claude Code, you can migrate them:
534
+
535
+ ```bash
536
+ gemini hooks migrate --from-claude
537
+ ```
538
+
539
+ This command:
540
+
541
+ - Reads `.claude/settings.json`
542
+ - Converts event names (`PreToolUse` → `BeforeTool`, etc.)
543
+ - Translates tool names (`Bash` → `run_shell_command`, `replace` → `replace`)
544
+ - Updates matcher patterns
545
+ - Writes to `.gemini/settings.json`
546
+
547
+ ### Event name mapping
548
+
549
+ | Claude Code | Gemini CLI |
550
+ | ------------------ | -------------- |
551
+ | `PreToolUse` | `BeforeTool` |
552
+ | `PostToolUse` | `AfterTool` |
553
+ | `UserPromptSubmit` | `BeforeAgent` |
554
+ | `Stop` | `AfterAgent` |
555
+ | `Notification` | `Notification` |
556
+ | `SessionStart` | `SessionStart` |
557
+ | `SessionEnd` | `SessionEnd` |
558
+ | `PreCompact` | `PreCompress` |
559
+
560
+ ### Tool name mapping
561
+
562
+ | Claude Code | Gemini CLI |
563
+ | ----------- | --------------------- |
564
+ | `Bash` | `run_shell_command` |
565
+ | `Edit` | `replace` |
566
+ | `Read` | `read_file` |
567
+ | `Write` | `write_file` |
568
+ | `Glob` | `glob` |
569
+ | `Grep` | `search_file_content` |
570
+ | `LS` | `list_directory` |
571
+
572
+ ## Tool and Event Matchers Reference
573
+
574
+ ### Available tool names for matchers
575
+
576
+ The following built-in tools can be used in `BeforeTool` and `AfterTool` hook
577
+ matchers:
578
+
579
+ #### File operations
580
+
581
+ - `read_file` - Read a single file
582
+ - `read_many_files` - Read multiple files at once
583
+ - `write_file` - Create or overwrite a file
584
+ - `replace` - Edit file content with find/replace
585
+
586
+ #### File system
587
+
588
+ - `list_directory` - List directory contents
589
+ - `glob` - Find files matching a pattern
590
+ - `search_file_content` - Search within file contents
591
+
592
+ #### Execution
593
+
594
+ - `run_shell_command` - Execute shell commands
595
+
596
+ #### Web and external
597
+
598
+ - `google_web_search` - Google Search with grounding
599
+ - `web_fetch` - Fetch web page content
600
+
601
+ #### Agent features
602
+
603
+ - `write_todos` - Manage TODO items
604
+ - `save_memory` - Save information to memory
605
+ - `delegate_to_agent` - Delegate tasks to sub-agents
606
+
607
+ #### Example matchers
608
+
609
+ ```json
610
+ {
611
+ "matcher": "write_file|replace" // File editing tools
612
+ }
613
+ ```
614
+
615
+ ```json
616
+ {
617
+ "matcher": "read_.*" // All read operations
618
+ }
619
+ ```
620
+
621
+ ```json
622
+ {
623
+ "matcher": "run_shell_command" // Only shell commands
624
+ }
625
+ ```
626
+
627
+ ```json
628
+ {
629
+ "matcher": "*" // All tools
630
+ }
631
+ ```
632
+
633
+ ### Event-specific matchers
634
+
635
+ #### SessionStart event matchers
636
+
637
+ - `startup` - Fresh session start
638
+ - `resume` - Resuming a previous session
639
+ - `clear` - Session cleared
640
+
641
+ #### SessionEnd event matchers
642
+
643
+ - `exit` - Normal exit
644
+ - `clear` - Session cleared
645
+ - `logout` - User logged out
646
+ - `prompt_input_exit` - Exit from prompt input
647
+ - `other` - Other reasons
648
+
649
+ #### PreCompress event matchers
650
+
651
+ - `manual` - Manually triggered compression
652
+ - `auto` - Automatically triggered compression
653
+
654
+ #### Notification event matchers
655
+
656
+ - `ToolPermission` - Tool permission notifications
657
+
658
+ ## Learn more
659
+
660
+ - [Writing Hooks](writing-hooks.md) - Tutorial and comprehensive example
661
+ - [Best Practices](best-practices.md) - Security, performance, and debugging
662
+ - [Custom Commands](../cli/custom-commands.md) - Create reusable prompt
663
+ shortcuts
664
+ - [Configuration](../cli/configuration.md) - Gemini CLI configuration options
665
+ - [Hooks Design Document](../hooks-design.md) - Technical architecture details