File System Tools
Qwen Code provides a comprehensive suite of tools for interacting with the local file system. All file system tools operate within the workspace directory for security.read_file
Tool Name:read_file
Display Name: ReadFile
Kind: Read
Description: Reads and returns the content of a specified file. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files.
Parameters
Usage
Behavior
- Text Files: Returns content as string with line numbers
- Images: Returns base64-encoded data with MIME type
- PDFs: Returns base64-encoded data
- Binary Files: Returns error message
- Large Files: Automatically truncates with indication
- Missing Files: Returns error
Confirmation
No confirmation required (read-only operation).Implementation
Location:packages/core/src/tools/read-file.ts
write_file
Tool Name:write_file
Display Name: WriteFile
Kind: Edit
Description: Writes content to a specified file. Creates the file and parent directories if they don’t exist. Overwrites existing files.
Parameters
Usage
Behavior
- New Files: Creates file and parent directories
- Existing Files: Overwrites completely
- Encoding: Preserves existing BOM if present
- Permissions: Respects file system permissions
- User Modification: User can modify content before write
Confirmation
Yes. Shows a diff of changes and asks for user approval.Implementation
Location:packages/core/src/tools/write-file.ts
edit
Tool Name:edit
Display Name: Edit
Kind: Edit
Description: Replaces text within a file. By default requires unique match. Set replace_all for multiple replacements.
Parameters
Usage
Behavior
- Unique Match Required: By default,
old_stringmust match exactly once - Replace All: Set
replace_all: truefor multiple matches - Context Required: Include sufficient context (3+ lines before/after)
- Whitespace Sensitive: Preserves exact indentation and spacing
- Line Ending Normalization: Handles CRLF/LF automatically
- Self-Correction: May attempt to fix ambiguous matches
Confirmation
Yes. Shows a diff of the proposed changes.Common Errors
Implementation
Location:packages/core/src/tools/edit.ts
glob
Tool Name:glob
Display Name: Glob
Kind: Read
Description: Finds files matching glob patterns, returning paths sorted by modification time (newest first).
Parameters
Usage
Patterns
*- Match any characters except/**- Match any characters including/?- Match single character[abc]- Match any character in set{js,ts}- Match any pattern in set!pattern- Exclude pattern
Behavior
- Sorting: Most recently modified first
- Limit: Returns max 100 files
- Respects Ignores: Follows
.gitignoreand.qwenignore - Absolute Paths: Always returns absolute paths
Confirmation
No confirmation required.Implementation
Location:packages/core/src/tools/glob.ts
grep_search
Tool Name:grep_search
Display Name: Grep
Kind: Read
Description: Searches for regex patterns within file contents. Returns matching lines with file paths and line numbers.
Parameters
Usage
Behavior
- Engine: Uses ripgrep if available, falls back to JS implementation
- Case Insensitive: By default
- Respects Ignores: Follows
.gitignoreand.qwenignore - Line Context: Returns full matching lines
- Performance: Very fast with ripgrep
Confirmation
No confirmation required.Implementation
Location:packages/core/src/tools/grep.ts and ripGrep.ts
list_directory
Tool Name:list_directory
Display Name: ListFiles
Kind: Read
Description: Lists files and subdirectories in a specified directory.
Parameters
Usage
Behavior
- Sorting: Directories first, then alphabetically
- Type Indication: Shows
[DIR]for directories - Respects Ignores: Follows ignore patterns by default
Confirmation
No confirmation required.Implementation
Location:packages/core/src/tools/ls.ts
Security
All file system tools enforce security measures:Path Validation
- Absolute Paths Required: All paths must be absolute
- Workspace Boundary: Paths must be within workspace
- Ignore Patterns: Respects
.qwenignoreand.gitignore - Temp Directory Access: Limited temp directory access
Example Validation
Best Practices
- Read Before Edit: Always read files before editing
- Sufficient Context: Include 3+ lines of context in
old_string - Use Glob First: Use glob to find files before reading
- Limit Results: Use limits to prevent overwhelming context
- Validate Paths: Always use absolute paths
- Handle Errors: Check for error results
Next Steps
- Shell Tool - Execute shell commands
- Task Tool - Delegate to subagents
- Memory Tool - Save long-term memories
- Tools System - Understanding the tools architecture
