Skip to content

WEB-4871: forward Grep/Glob/LS reads from the claude-code hook#160

Closed
MohamedAklamaash wants to merge 4 commits into
stagingfrom
web-4871
Closed

WEB-4871: forward Grep/Glob/LS reads from the claude-code hook#160
MohamedAklamaash wants to merge 4 commits into
stagingfrom
web-4871

Conversation

@MohamedAklamaash

@MohamedAklamaash MohamedAklamaash commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

WEB-4871 — forward Grep/Glob/LS reads from the claude-code hook

Linear: https://linear.app/unboundsec/issue/WEB-4871/classifier-output-uses-inconsistent-field-names-for-the-same-concept

What

Grep / Glob / LS are read-equivalent (they expose file contents or enumerate paths), but the hook never sent them, so they bypassed policy. The hook now forwards them with their target path so read / secret policies evaluate them like a native Read.

Notes

  • Based on web-4850 (well ahead of main) for a clean diff — retarget if preferred.

🤖 Generated with Claude Code

Greptile Summary

Review completed and submitted via the mcp__greptile-review__submit_review tool.

Confidence Score: 4/5

Safe to merge with attention to the approval-retry path for Grep/Glob.

The new forwarding logic for Grep/Glob/LS is backward-compatible and the file_path derivation is correct for the common cases. The approval_key for Grep and Glob is built from the search pattern alone, not from the combination of pattern and path, enabling a scoped search approval to be reused by a broader search within the 4-hour timeout window.

claude-code/hooks/unbound.py — specifically extract_command_for_pretool and the approval_key construction for Grep and Glob.

Comments Outside Diff (1)

  1. claude-code/hooks/unbound.py, line 497-515 (link)

    P2 LS added to NATIVE_FILE_TOOLS and READ_EQUIVALENT_FILE_TOOLS but extract_command_for_pretool was not updated for it. The function explicitly handles Grep (returns pattern) and Glob (returns pattern), but LS falls through to return tool_name — always yielding the literal string "LS". Downstream, approval_key = f"{tool_name}:{command}" becomes "LS:LS" for every single LS invocation, collapsing distinct path listings into one deduplication bucket and sending the gateway an uninformative command value.

Reviews (2): Last reviewed commit: "WEB-4871: only fall back to pattern for ..." | Re-trigger Greptile

MohamedAklamaash and others added 3 commits June 17, 2026 11:22
Grep/Glob/LS are read-equivalent (they expose file contents or enumerate
paths), so the hook now sends them with their target path, letting read /
secret policies evaluate them like a native Read instead of bypassing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread claude-code/hooks/unbound.py Outdated
Grep's `pattern` is a regex, not a path; forwarding it as file_path made the
gateway evaluate a regex as a filesystem path. Glob's `pattern` is path-like
(`**/*.env`) so it keeps the fallback. Grep/LS now use `path` only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vigneshsubbiah16 vigneshsubbiah16 changed the base branch from web-4850 to staging June 17, 2026 19:36
@vigneshsubbiah16 vigneshsubbiah16 requested a review from a team June 17, 2026 19:36
@vigneshsubbiah16

Copy link
Copy Markdown
Collaborator

Superseded by #161 — a clean re-base onto staging containing only the WEB-4871 hook change (this PR's base was web-4850, which dragged in the unrelated 'longest handoff calc' commit). Same two commits, cherry-picked unchanged.

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