2026-02-13 14:09:17 -08:00
|
|
|
# File system tools reference
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
The Gemini CLI core provides a suite of tools for interacting with the local
|
|
|
|
|
file system. These tools allow the model to explore and modify your codebase.
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
## Technical reference
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
All file system tools operate within a `rootDirectory` (the current working
|
|
|
|
|
directory or workspace root) for security.
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
### `list_directory` (ReadFolder)
|
|
|
|
|
|
|
|
|
|
Lists the names of files and subdirectories directly within a specified path.
|
2025-06-24 15:31:58 -07:00
|
|
|
|
|
|
|
|
- **Tool name:** `list_directory`
|
2026-02-13 14:09:17 -08:00
|
|
|
- **Arguments:**
|
|
|
|
|
- `dir_path` (string, required): Absolute or relative path to the directory.
|
|
|
|
|
- `ignore` (array, optional): Glob patterns to exclude.
|
|
|
|
|
- `file_filtering_options` (object, optional): Configuration for `.gitignore`
|
|
|
|
|
and `.geminiignore` compliance.
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
### `read_file` (ReadFile)
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
Reads and returns the content of a specific file. Supports text, images, audio,
|
|
|
|
|
and PDF.
|
2025-06-24 15:31:58 -07:00
|
|
|
|
|
|
|
|
- **Tool name:** `read_file`
|
2026-02-13 14:09:17 -08:00
|
|
|
- **Arguments:**
|
|
|
|
|
- `file_path` (string, required): Path to the file.
|
|
|
|
|
- `offset` (number, optional): Start line for text files (0-based).
|
|
|
|
|
- `limit` (number, optional): Maximum lines to read.
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
### `write_file` (WriteFile)
|
2025-06-07 10:47:30 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
Writes content to a specified file, overwriting it if it exists or creating it
|
|
|
|
|
if not.
|
2025-06-24 15:31:58 -07:00
|
|
|
|
|
|
|
|
- **Tool name:** `write_file`
|
2026-02-13 14:09:17 -08:00
|
|
|
- **Arguments:**
|
|
|
|
|
- `file_path` (string, required): Path to the file.
|
|
|
|
|
- `content` (string, required): Data to write.
|
|
|
|
|
- **Confirmation:** Requires manual user approval.
|
2025-06-07 10:47:30 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
### `glob` (FindFiles)
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-13 14:09:17 -08:00
|
|
|
Finds files matching specific glob patterns across the workspace.
|
2025-06-24 15:31:58 -07:00
|
|
|
|
|
|
|
|
- **Tool name:** `glob`
|
|
|
|
|
- **Display name:** FindFiles
|
2025-05-15 20:04:33 -07:00
|
|
|
- **File:** `glob.ts`
|
|
|
|
|
- **Parameters:**
|
2025-10-09 08:17:37 -04:00
|
|
|
- `pattern` (string, required): The glob pattern to match against (e.g.,
|
|
|
|
|
`"*.py"`, `"src/**/*.js"`).
|
|
|
|
|
- `path` (string, optional): The absolute path to the directory to search
|
|
|
|
|
within. If omitted, searches the tool's root directory.
|
|
|
|
|
- `case_sensitive` (boolean, optional): Whether the search should be
|
|
|
|
|
case-sensitive. Defaults to `false`.
|
|
|
|
|
- `respect_git_ignore` (boolean, optional): Whether to respect .gitignore
|
|
|
|
|
patterns when finding files. Defaults to `true`.
|
2025-05-15 20:04:33 -07:00
|
|
|
- **Behavior:**
|
|
|
|
|
- Searches for files matching the glob pattern within the specified directory.
|
2025-10-09 08:17:37 -04:00
|
|
|
- Returns a list of absolute paths, sorted with the most recently modified
|
|
|
|
|
files first.
|
|
|
|
|
- Ignores common nuisance directories like `node_modules` and `.git` by
|
|
|
|
|
default.
|
|
|
|
|
- **Output (`llmContent`):** A message like:
|
|
|
|
|
`Found 5 file(s) matching "*.ts" within src, sorted by modification time (newest first):\nsrc/file1.ts\nsrc/subdir/file2.ts...`
|
2025-05-15 20:04:33 -07:00
|
|
|
- **Confirmation:** No.
|
|
|
|
|
|
2026-03-09 20:03:50 +01:00
|
|
|
### `grep_search` (SearchText)
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-02 20:18:24 -08:00
|
|
|
`grep_search` searches for a regular expression pattern within the content of
|
|
|
|
|
files in a specified directory. Can filter files by a glob pattern. Returns the
|
|
|
|
|
lines containing matches, along with their file paths and line numbers.
|
2025-06-24 15:31:58 -07:00
|
|
|
|
2026-02-02 20:18:24 -08:00
|
|
|
- **Tool name:** `grep_search`
|
2025-06-24 15:31:58 -07:00
|
|
|
- **Display name:** SearchText
|
2025-05-15 20:04:33 -07:00
|
|
|
- **File:** `grep.ts`
|
|
|
|
|
- **Parameters:**
|
2025-10-09 08:17:37 -04:00
|
|
|
- `pattern` (string, required): The regular expression (regex) to search for
|
|
|
|
|
(e.g., `"function\s+myFunction"`).
|
|
|
|
|
- `path` (string, optional): The absolute path to the directory to search
|
|
|
|
|
within. Defaults to the current working directory.
|
|
|
|
|
- `include` (string, optional): A glob pattern to filter which files are
|
|
|
|
|
searched (e.g., `"*.js"`, `"src/**/*.{ts,tsx}"`). If omitted, searches most
|
|
|
|
|
files (respecting common ignores).
|
2025-05-15 20:04:33 -07:00
|
|
|
- **Behavior:**
|
2025-10-09 08:17:37 -04:00
|
|
|
- Uses `git grep` if available in a Git repository for speed; otherwise, falls
|
|
|
|
|
back to system `grep` or a JavaScript-based search.
|
|
|
|
|
- Returns a list of matching lines, each prefixed with its file path (relative
|
|
|
|
|
to the search directory) and line number.
|
2025-05-15 20:04:33 -07:00
|
|
|
- **Output (`llmContent`):** A formatted string of matches, e.g.:
|
|
|
|
|
```
|
2025-06-28 17:41:25 +03:00
|
|
|
Found 3 matches for pattern "myFunction" in path "." (filter: "*.ts"):
|
2025-05-15 20:04:33 -07:00
|
|
|
---
|
|
|
|
|
File: src/utils.ts
|
|
|
|
|
L15: export function myFunction() {
|
|
|
|
|
L22: myFunction.call();
|
|
|
|
|
---
|
|
|
|
|
File: src/index.ts
|
|
|
|
|
L5: import { myFunction } from './utils';
|
|
|
|
|
---
|
|
|
|
|
```
|
|
|
|
|
- **Confirmation:** No.
|
|
|
|
|
|
2026-03-09 20:03:50 +01:00
|
|
|
### `replace` (Edit)
|
2025-05-15 20:04:33 -07:00
|
|
|
|
2026-02-23 11:53:58 -08:00
|
|
|
`replace` replaces text within a file. By default, the tool expects to find and
|
|
|
|
|
replace exactly ONE occurrence of `old_string`. If you want to replace multiple
|
|
|
|
|
occurrences of the exact same string, set `allow_multiple` to `true`. This tool
|
|
|
|
|
is designed for precise, targeted changes and requires significant context
|
|
|
|
|
around the `old_string` to ensure it modifies the correct location.
|
2025-06-24 15:31:58 -07:00
|
|
|
|
|
|
|
|
- **Tool name:** `replace`
|
2026-02-13 14:09:17 -08:00
|
|
|
- **Arguments:**
|
|
|
|
|
- `file_path` (string, required): Path to the file.
|
|
|
|
|
- `instruction` (string, required): Semantic description of the change.
|
|
|
|
|
- `old_string` (string, required): Exact literal text to find.
|
|
|
|
|
- `new_string` (string, required): Exact literal text to replace with.
|
2026-02-23 11:53:58 -08:00
|
|
|
- `allow_multiple` (boolean, optional): If `true`, replaces all occurrences.
|
|
|
|
|
If `false` (default), only succeeds if exactly one occurrence is found.
|
2026-02-13 14:09:17 -08:00
|
|
|
- **Confirmation:** Requires manual user approval.
|
|
|
|
|
|
|
|
|
|
## Next steps
|
|
|
|
|
|
|
|
|
|
- Follow the [File management tutorial](../cli/tutorials/file-management.md) for
|
|
|
|
|
practical examples.
|
|
|
|
|
- Learn about [Trusted folders](../cli/trusted-folders.md) to manage access
|
|
|
|
|
permissions.
|