Using .saarthiignore to Control File Access
The .saarthiignore file is a key feature for managing Saarthi's interaction with your project files. It allows you to specify files and directories that Saarthi should not access or modify, similar to how .gitignore works for Git.
What is .saarthiignore?
- Purpose: To protect sensitive information, prevent accidental changes to build artifacts or large assets, and generally define Saarthi's operational scope within your workspace.
- How to Use: Create a file named
.saarthiignorein the root directory of your VS Code workspace. List patterns in this file to tell Saarthi which files and directories to ignore. - Scope:
.saarthiignoreaffects both Saarthi's tools and context mentions (like@directoryattachments).
Saarthi actively monitors the .saarthiignore file. Any changes you make are reloaded automatically, ensuring Saarthi always uses the most current rules. The .saarthiignore file itself is always implicitly ignored, so Saarthi cannot change its own access rules.
Pattern Syntax
The syntax for .saarthiignore is identical to .gitignore. Here are common examples:
node_modules/: Ignores the entirenode_modulesdirectory.*.log: Ignores all files ending in.log.config/secrets.json: Ignores a specific file.!important.log: An exception; Saarthi will not ignore this specific file, even if a broader pattern like*.logexists.build/: Ignores thebuilddirectory.docs/**/*.md: Ignores all Markdown files in thedocsdirectory and its subdirectories.
For a comprehensive guide on syntax, refer to the official Git documentation on .gitignore.
How Saarthi Tools Interact with .saarthiignore
.saarthiignore rules are enforced across various Saarthi tools:
Strict Enforcement (Reads & Writes)
These tools directly check .saarthiignore before any file operation. If a file is ignored, the operation is blocked:
read_file: Will not read ignored files.write_to_file: Will not write to or create new ignored files.apply_diff: Will not apply diffs to ignored files.insert_content: Will not write to ignored files.search_and_replace: Will not search and replace within ignored files.list_code_definition_names: Will not parse ignored files for code symbols.
File Discovery and Listing
list_filesTool &@directoryAttachments: When Saarthi lists files or when you use@directoryattachments, ignored files are omitted or marked with a 🔒 symbol (see "User Experience" below). Both use identical filtering logic.- Environment Details: Information about your workspace (like open tabs and project structure) provided to Saarthi is filtered to exclude or mark ignored items.
Context Mentions
@directoryAttachments: Directory contents respect.saarthiignorepatterns. Ignored files are filtered out or marked with[🔒]prefix depending on theshowRooIgnoredFilessetting.- Single File Mentions: Ignored files return "(File is ignored by .saarthiignore)" instead of content.
Command Execution
execute_commandTool: This tool checks if a command (from a predefined list likecatorgrep) targets an ignored file. If so, execution is blocked.
Key Limitations and Scope
- Workspace-Centric:
.saarthiignorerules apply only to files and directories within the current VS Code workspace root. Files outside this scope are not affected. execute_commandSpecificity: Protection forexecute_commandis limited to a predefined list of file-reading commands. Custom scripts or uncommon utilities might not be caught.- Not a Full Sandbox:
.saarthiignoreis a powerful tool for controlling Saarthi's file access via its tools, but it does not create a system-level sandbox.
User Experience and Notifications
- Visual Cue (🔒): In file listings and
@directoryattachments, files ignored by.saarthiignoremay be marked with a lock symbol (🔒), depending on theshowRooIgnoredFilessetting (defaults totrue). - Ignore Messages: Single file mentions return "(File is ignored by .saarthiignore)" instead of content.
- Error Messages: If a tool operation is blocked, Saarthi receives an error:
"Access to [file_path] is blocked by the .saarthiignore file settings. You must try to continue in the task without using this file, or ask the user to update the .saarthiignore file." - Chat Notifications: You will typically see a notification in the Saarthi chat interface when an action is blocked due to
.saarthiignore.
This guide helps you understand the .saarthiignore feature, its capabilities, and its current limitations, so you can effectively manage Saarthi's interaction with your codebase.