Skip to content

fix(anthropic): exclude sibling directories from grep search scope - #39681

Merged
ccurme (ccurme) merged 2 commits into
langchain-ai:masterfrom
Haaaarry:Haaaarry/anthropic/grep-sibling-scope
Aug 18, 2026
Merged

fix(anthropic): exclude sibling directories from grep search scope#39681
ccurme (ccurme) merged 2 commits into
langchain-ai:masterfrom
Haaaarry:Haaaarry/anthropic/grep-sibling-scope

Conversation

@Haaaarry

Copy link
Copy Markdown
Contributor

Fixes #39679


StateFileSearchMiddleware._handle_grep_search scoped a search with a raw startswith check, so a file under a sibling directory that shares the scope prefix (for example /app-secret/creds.txt when scoped to /app) was included in the results. This disagreed with _handle_glob_search, which already enforces a segment boundary.

The grep lookup now uses the same segment-aware boundary: a file is in scope when the base path is /, when it is the base path itself, or when it lives directly under base_path/. Sibling directories that merely share the prefix are excluded, matching _handle_glob_search.

Added a unit test covering a sibling directory that shares the scope prefix.

Release note

grep_search in the Anthropic file-search middleware now respects the directory boundary of its path argument and no longer returns files from sibling directories that merely share the path prefix.


This contribution was prepared with AI assistance.

@github-actions github-actions Bot added anthropic `langchain-anthropic` package issues & PRs fix For PRs that implement a fix integration PR made that is related to a provider partner package integration size: XS < 50 LOC labels Aug 17, 2026
@github-actions

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic `langchain-anthropic` package issues & PRs external fix For PRs that implement a fix integration PR made that is related to a provider partner package integration new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StateFileSearchMiddleware: grep_search matches sibling directories that share a path prefix (inconsistent with glob_search)

2 participants