read_many_files - Read Multiple Files
Overview
The read_many_files tool reads content from multiple files specified by paths or glob patterns within a configured target directory. For text files, it concatenates their content into a single string. It is primarily designed for text-based files but can also process image (e.g., .png, .jpg) and PDF (.pdf) files if their file names or extensions are explicitly included in the 'paths' argument.
Tool Name
- Internal Name:
read_many_files - Display Name: ReadManyFiles
- Icon: FileStack
Parameters
Required Parameters
| Parameter | Type | Description |
|---|---|---|
paths | string[] | An array of glob patterns or paths relative to the tool's target directory. Examples: ['src/**/*.ts'], ['README.md', 'docs/']. At least one path is required. |
Optional Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
exclude | string[] | [] | Glob patterns for files/directories to exclude. Added to default excludes if useDefaultExcludes is true. Example: ["**/*.log", "temp/"] |
include | string[] | [] | Additional glob patterns to include. These are merged with paths. Example: ["*.test.ts"] to specifically add test files |
recursive | boolean | true | Whether to search recursively (primarily controlled by ** in glob patterns) |
useDefaultExcludes | boolean | true | Whether to apply a list of default exclusion patterns (e.g., node_modules, .git, binary files) |
per_file_max_lines | number | 200 | Maximum number of lines to read from each text file |
per_file_max_chars | number | 20000 | Maximum characters to read from each text file |
max_total_files | number | 20 | Maximum number of files to read before truncating the result |
max_total_chars | number | 200000 | Maximum total characters to return across all files |
prefer_full_read | boolean | false | Set to true to disable per-file truncation guards. Total limits (max_total_files, max_total_chars) remain in effect |
file_filtering_options | object | - | File filtering options |
file_filtering_options.respect_git_ignore | boolean | true | Whether to respect .gitignore patterns (only available in git repositories) |
file_filtering_options.respect_sii_ignore | boolean | true | Whether to respect .siiignore patterns |
Features
Batch Reading:
- Read multiple files at once
- Support glob pattern matching
- Automatically merge file contents
File Type Support:
- Primarily for text files
- Can process explicitly specified image files (PNG, JPG, etc.)
- Can process explicitly specified PDF files
Content Formatting:
- Uses
--- {filePath} ---separator - Default UTF-8 encoding
- Clear file boundary markers
- Uses
Smart Filtering:
- Respects .gitignore rules
- Respects .siiignore rules
- Default excludes common large directories
- Automatically skips binary files (unless explicitly requested)
Safety Limits:
- File count limits
- Per-file size limits
- Total character limits
- Prevents reading excessive content
Use Cases
This tool is useful when you need to:
- Get an overview of a codebase or parts of it (e.g., all TypeScript files in the 'src' directory)
- Find where specific functionality is implemented
- Review documentation files (e.g., all Markdown files in the 'docs' directory)
- Gather context from multiple configuration files
- When the user asks to "read all files in X directory" or "show me the content of all Y files"
Usage Examples
Read All TypeScript Files
{
"paths": ["src/**/*.ts"]
}Read Specific Files and Directories
{
"paths": ["README.md", "package.json", "src/"]
}Read with Exclusions
{
"paths": ["src/**/*.js"],
"exclude": ["**/*.test.js", "**/*.spec.js"]
}Read Test Files
{
"paths": ["src/**/*.ts"],
"include": ["**/*.test.ts", "**/*.spec.ts"]
}Full Read for Small Files
{
"paths": ["config/**/*.json"],
"prefer_full_read": true,
"max_total_files": 50
}Without Default Excludes
{
"paths": ["node_modules/my-package/**/*.js"],
"useDefaultExcludes": false,
"file_filtering_options": {
"respect_git_ignore": false
}
}Return Value
The tool returns an object containing:
llmContent: Merged file content stringreturnDisplay: User-friendly display informationsummary: Operation summary (including number of files read, etc.)
Content Format
--- /path/to/file1.ts ---
[file1 content]
--- /path/to/file2.ts ---
[file2 content]
...Error Handling
Possible error scenarios:
Path Errors:
- Empty paths parameter
- Invalid glob pattern
- Path outside allowed directory scope
File Access Errors:
- No read permission
- File excluded by ignore rules
Limit Errors:
- Exceeded file count limit
- Exceeded total character limit
- Individual file too large
Best Practices
Use Specific Glob Patterns:
- ✅
src/**/*.ts- Specific file type - ❌
**/*- Too broad
- ✅
Set Reasonable Limits:
- Adjust
max_total_filesbased on needs - Use more specific paths for large projects
- Adjust
Utilize Exclusions:
- Exclude test files:
exclude: ["**/*.test.ts"] - Exclude build artifacts:
exclude: ["dist/", "build/"]
- Exclude test files:
Process in Batches:
- For large codebases, read in multiple passes
- Read core files first, then others
Check Return Summary:
- Confirm expected number of files read
- Check if any files were truncated
Performance Considerations
File Count:
- Default maximum of 20 files
- Adjustable based on needs
File Size:
- Per-file default: 200 lines or 20000 characters
- Total default: 200000 characters
Read Speed:
- Text files read quickly
- Images and PDFs process slower
Memory Usage:
- All content loaded into memory
- Be mindful of total character limits
Comparison with Other Tools
| Tool | Purpose | Use Case |
|---|---|---|
read_file | Read single file | Need complete content of specific file |
read_many_files | Batch read files | Need content from multiple files |
glob | Find file paths | Only need file list, not content |
search_file_content | Search file content | Find files containing specific patterns |
Notes
- Path Relativity: Paths are relative to the tool's target directory
- Binary Files: Skipped by default unless explicitly specified
- Large Files: Automatically truncated, use
prefer_full_readwith caution - Encoding: Defaults to UTF-8, other encodings may display incorrectly
Related Tools
read_file: Read single fileglob: Find matching file pathssearch_file_content: Search within file contentlist_directory: List directory contents
