Skip to content

Add recursive directory listing to list_files tool#14

Merged
BillJr99 merged 1 commit into
mainfrom
claude/upbeat-pasteur-LsyDk
May 25, 2026
Merged

Add recursive directory listing to list_files tool#14
BillJr99 merged 1 commit into
mainfrom
claude/upbeat-pasteur-LsyDk

Conversation

@BillJr99
Copy link
Copy Markdown
Owner

Summary

Enhanced the list_files tool to support recursive directory traversal with optional depth limiting, and improved the entry structure to include relative paths.

Key Changes

  • Added recursive listing: New recursive parameter (default True) controls whether subdirectories are traversed
  • Added depth limiting: New max_depth parameter allows limiting recursion depth (e.g., max_depth=1 for immediate children only)
  • Enhanced entry structure: Each entry now includes a path field with the relative path from the listed directory (using / as separator), in addition to the existing name field
  • Symlink safety: Directory symlinks are not followed during recursion to prevent infinite loops
  • Improved documentation: Updated docstring to clarify the new parameters and behavior

Implementation Details

  • Refactored the listing logic to use a recursive _walk() helper function that respects depth limits
  • Directory detection now explicitly excludes symlinks (entry.is_dir() and not entry.is_symlink()) to prevent following circular symlink references
  • Entries are still emitted in sorted order and directories appear as their own entries before their children
  • The response now includes the recursive parameter value for clarity
  • Tool schema in server.py updated with proper parameter definitions and descriptions

https://claude.ai/code/session_012AkYGvzYkJzN7f2VEN3wUn

Default recursive=true so callers see the full tree under the base
directory in a single call. Directories are still emitted as entries
with type='directory', and each entry now carries a 'path' field
relative to the listed root. Adds max_depth and skips directory
symlinks to avoid cycles.
@BillJr99 BillJr99 merged commit 534c8da into main May 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants