Skip to content

fix: filter hidden files and directories from glob results in file_read#492

Open
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix/file-read-skip-hidden-dirs-in-glob
Open

fix: filter hidden files and directories from glob results in file_read#492
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix/file-read-skip-hidden-dirs-in-glob

Conversation

@xlyoung

@xlyoung xlyoung commented Jun 4, 2026

Copy link
Copy Markdown

Problem

The search_file() function has two code paths:

  1. os.walk path (for direct directory traversal) — correctly prunes hidden directories and skips hidden files
  2. glob.glob path (for pattern matching) — no filtering, so files under .git/, .venv/, etc. appear in results

Fix

Add the same hidden file/directory filtering to glob results:

matching_files = [
    f for f in matching_files
    if not any(part.startswith(".") for part in f.split(os.sep) if part)
]

This checks every path component (not just the filename) to catch files nested under hidden directories.

Testing

All 18 file_read tests pass.

Fixes #289

The search_file() function's os.walk path correctly prunes hidden
directories and skips hidden files. However, the glob.glob() path
(code line ~400) had no such filtering, causing files under hidden
directories like .git/ to appear in search results.

Add the same hidden file/directory filtering to glob results:
skip any path where a component starts with '.'.

Fixes strands-agents#289
@xlyoung xlyoung requested a deployment to manual-approval June 4, 2026 06:29 — with GitHub Actions Waiting
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.

[BUG] file_read tool lists files under hidden folder

1 participant