diff --git a/aider/commands.py b/aider/commands.py index 01374dbe1..4644a3b57 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1170,12 +1170,20 @@ class Commands: # First collect all expanded paths for pattern in filenames: expanded_pattern = expanduser(pattern) - expanded_paths = Path(self.coder.root).rglob(expanded_pattern) - - if not expanded_paths: - self.io.tool_error(f"No matches found for: {pattern}") + if os.path.isabs(expanded_pattern): + # For absolute paths, check if file exists directly + path = Path(expanded_pattern) + if path.exists(): + all_paths.append(path) + else: + self.io.tool_error(f"No matches found for: {pattern}") else: - all_paths.extend(expanded_paths) + # For relative paths and globs, use glob from the root directory + matches = list(Path(self.coder.root).glob("**/" + expanded_pattern)) + if not matches: + self.io.tool_error(f"No matches found for: {pattern}") + else: + all_paths.extend(matches) # Then process them in sorted order for path in sorted(all_paths):