Skip to content

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

ParameterTypeDescription
pathsstring[]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

ParameterTypeDefaultDescription
excludestring[][]Glob patterns for files/directories to exclude. Added to default excludes if useDefaultExcludes is true. Example: ["**/*.log", "temp/"]
includestring[][]Additional glob patterns to include. These are merged with paths. Example: ["*.test.ts"] to specifically add test files
recursivebooleantrueWhether to search recursively (primarily controlled by ** in glob patterns)
useDefaultExcludesbooleantrueWhether to apply a list of default exclusion patterns (e.g., node_modules, .git, binary files)
per_file_max_linesnumber200Maximum number of lines to read from each text file
per_file_max_charsnumber20000Maximum characters to read from each text file
max_total_filesnumber20Maximum number of files to read before truncating the result
max_total_charsnumber200000Maximum total characters to return across all files
prefer_full_readbooleanfalseSet to true to disable per-file truncation guards. Total limits (max_total_files, max_total_chars) remain in effect
file_filtering_optionsobject-File filtering options
file_filtering_options.respect_git_ignorebooleantrueWhether to respect .gitignore patterns (only available in git repositories)
file_filtering_options.respect_sii_ignorebooleantrueWhether to respect .siiignore patterns

Features

  1. Batch Reading:

    • Read multiple files at once
    • Support glob pattern matching
    • Automatically merge file contents
  2. File Type Support:

    • Primarily for text files
    • Can process explicitly specified image files (PNG, JPG, etc.)
    • Can process explicitly specified PDF files
  3. Content Formatting:

    • Uses --- {filePath} --- separator
    • Default UTF-8 encoding
    • Clear file boundary markers
  4. Smart Filtering:

    • Respects .gitignore rules
    • Respects .siiignore rules
    • Default excludes common large directories
    • Automatically skips binary files (unless explicitly requested)
  5. 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

json
{
  "paths": ["src/**/*.ts"]
}

Read Specific Files and Directories

json
{
  "paths": ["README.md", "package.json", "src/"]
}

Read with Exclusions

json
{
  "paths": ["src/**/*.js"],
  "exclude": ["**/*.test.js", "**/*.spec.js"]
}

Read Test Files

json
{
  "paths": ["src/**/*.ts"],
  "include": ["**/*.test.ts", "**/*.spec.ts"]
}

Full Read for Small Files

json
{
  "paths": ["config/**/*.json"],
  "prefer_full_read": true,
  "max_total_files": 50
}

Without Default Excludes

json
{
  "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 string
  • returnDisplay: User-friendly display information
  • summary: 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:

  1. Path Errors:

    • Empty paths parameter
    • Invalid glob pattern
    • Path outside allowed directory scope
  2. File Access Errors:

    • No read permission
    • File excluded by ignore rules
  3. Limit Errors:

    • Exceeded file count limit
    • Exceeded total character limit
    • Individual file too large

Best Practices

  1. Use Specific Glob Patterns:

    • src/**/*.ts - Specific file type
    • **/* - Too broad
  2. Set Reasonable Limits:

    • Adjust max_total_files based on needs
    • Use more specific paths for large projects
  3. Utilize Exclusions:

    • Exclude test files: exclude: ["**/*.test.ts"]
    • Exclude build artifacts: exclude: ["dist/", "build/"]
  4. Process in Batches:

    • For large codebases, read in multiple passes
    • Read core files first, then others
  5. Check Return Summary:

    • Confirm expected number of files read
    • Check if any files were truncated

Performance Considerations

  1. File Count:

    • Default maximum of 20 files
    • Adjustable based on needs
  2. File Size:

    • Per-file default: 200 lines or 20000 characters
    • Total default: 200000 characters
  3. Read Speed:

    • Text files read quickly
    • Images and PDFs process slower
  4. Memory Usage:

    • All content loaded into memory
    • Be mindful of total character limits

Comparison with Other Tools

ToolPurposeUse Case
read_fileRead single fileNeed complete content of specific file
read_many_filesBatch read filesNeed content from multiple files
globFind file pathsOnly need file list, not content
search_file_contentSearch file contentFind files containing specific patterns

Notes

  1. Path Relativity: Paths are relative to the tool's target directory
  2. Binary Files: Skipped by default unless explicitly specified
  3. Large Files: Automatically truncated, use prefer_full_read with caution
  4. Encoding: Defaults to UTF-8, other encodings may display incorrectly
  • read_file: Read single file
  • glob: Find matching file paths
  • search_file_content: Search within file content
  • list_directory: List directory contents

Released under the MIT License.