Building Desktop Automation Agents
File and Folder Operations
5 min read
Computer Use excels at file management tasks. Claude can navigate file managers, create folders, rename files, and organize your documents.
The Text Editor Tool
For direct file manipulation, use the text_editor tool:
tools = [
{
"type": "text_editor_20250124",
"name": "str_replace_editor"
}
]
Available Commands
| Command | Description |
|---|---|
view |
Read file contents |
create |
Create new file |
str_replace |
Replace text in file |
insert |
Insert text at line |
Example: Organize Downloads
task = """
Organize my Downloads folder:
1. Create subfolders: Documents, Images, Code
2. Move .pdf files to Documents
3. Move .png and .jpg files to Images
4. Move .py and .js files to Code
5. Report what was moved
"""
result = run_agent(task)
Claude will:
- Open the file manager
- Navigate to Downloads
- Create the folders
- Select and move files by extension
- Return a summary
Using Bash for File Operations
The bash tool is more efficient for bulk operations:
tools = [
{
"type": "bash_20250124",
"name": "bash"
}
]
Example task:
task = """
Use the terminal to:
1. Find all .log files older than 7 days in /var/log
2. Create a backup directory with today's date
3. Move those files to the backup
4. Compress the backup folder
"""
Combining Visual and CLI
The most effective agents combine both approaches:
task = """
1. Open the file manager and find the project folder
2. Use terminal to run 'npm install'
3. Check the file manager for new node_modules folder
4. Report the size of node_modules
"""
Best Practices
| Practice | Reason |
|---|---|
| Use bash for bulk operations | Faster, more reliable |
| Use visual for unknown layouts | When you don't know paths |
| Confirm before deletion | Safety check |
| Log all operations | Audit trail |
Warning: Always test file operations in a sandbox first. Never run on production data without verification.
Next, we'll explore terminal automation patterns. :::