Skip to content

fix(file_read): skip hidden directories during os.walk traversal#440

Open
dosvk wants to merge 1 commit intostrands-agents:mainfrom
dosvk:fix/file-read-hidden-dirs
Open

fix(file_read): skip hidden directories during os.walk traversal#440
dosvk wants to merge 1 commit intostrands-agents:mainfrom
dosvk:fix/file-read-hidden-dirs

Conversation

@dosvk
Copy link
Copy Markdown

@dosvk dosvk commented Apr 2, 2026

Description using their template:

Filter directories starting with '.' in-place during os.walk to
prevent descending into .venv, .git, .mypy_cache, etc. This matches
the existing hidden file filter and prevents token explosion when
file_read is called on directories containing large hidden trees.

Closes #405

Description

find_files() uses os.walk() and filters hidden files but not hidden
directories. This causes traversal into .venv, .git, .mypy_cache, etc.,
collecting thousands of irrelevant files and exploding the context window.

The fix modifies dirs in-place during os.walk (the standard Python
approach for pruning traversal) to skip directories starting with .,
consistent with the existing hidden file filter on the same line.

Before: 13,769 files (97% from hidden dirs)
After: 1,257 files (hidden dirs skipped)

Related Issues

Closes #405

Type of Change

Bug fix

Testing

  • All 17 existing file_read tests pass

  • Verified manually: hidden directory files no longer returned

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Filter directories starting with '.' in-place during os.walk to
prevent descending into .venv, .git, .mypy_cache, etc. This matches
the existing hidden file filter and prevents token explosion when
file_read is called on directories containing large hidden trees.

Closes strands-agents#405
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.

file_read find_files() traverses hidden directories (.venv, .git, etc.) causing token explosion

1 participant