Skip to content

Change grep default behavior to search tools only#101

Merged
jancurn merged 11 commits intofeat/grep-cmdfrom
claude/grep-opt-in-flags-3d3EM
Mar 24, 2026
Merged

Change grep default behavior to search tools only#101
jancurn merged 11 commits intofeat/grep-cmdfrom
claude/grep-opt-in-flags-3d3EM

Conversation

@jancurn
Copy link
Member

@jancurn jancurn commented Mar 23, 2026

Summary

Modified the grep command to search only tools by default, making --resources and --prompts opt-in filters rather than included by default. This provides a more focused search experience and aligns with the principle of least surprise.

Key Changes

  • Default behavior: grep now searches tools only when no type flags are specified
  • Opt-in filters: --resources and --prompts must be explicitly provided to include those types
  • Updated help text: Clarified descriptions and examples to reflect the new default behavior
  • Logic refactor: Simplified getSearchTypes() function to explicitly handle the default case where only tools are searched
  • Documentation: Updated CHANGELOG to document this breaking change

Implementation Details

  • The getSearchTypes() function now uses a ternary operator to clearly distinguish between "any filter specified" and "default behavior" cases
  • Help text for both global and session-specific grep commands was updated consistently
  • Examples in the help text now show the new default behavior and how to include additional search types
  • The change applies to both the global grep command and session-specific @session grep commands

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

claude and others added 11 commits March 23, 2026 22:24
By default, grep now searches only tools. Users must explicitly pass
--resources and/or --prompts to include those types in search results.
When --tools is combined with other flags, it behaves as an explicit
opt-in just like the others.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
Tools are now always searched by default (additive model):
- No flags → tools only
- --resources → tools + resources
- --prompts → tools + prompts
- --no-tools --resources → resources only

Also adds comprehensive e2e tests for grep covering default
behavior, opt-in flags, regex, case sensitivity, and JSON output.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
No flags → tools only (default). Specifying --resources or --prompts
searches exactly those types, skipping tools. Use --tools alongside
other flags to include tools explicitly. Updated e2e tests to match.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
Session names in sessions.json already include the @ prefix (e.g. "@test"),
but grepAllSessions was prepending another @, producing "@@test" which
failed to resolve. Now correctly checks for existing prefix.

Also changed --tools/--resources/--prompts to explicit selection model:
specifying any flag searches exactly those types, default is tools only.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
…ailable sessions

The grep matcher now builds searchable text as "@session/item-name <JSON schema>"
so patterns can match session names, tool parameters, and other schema metadata.
Unavailable sessions (crashed, disconnected, etc.) are now displayed with their
status instead of being silently skipped.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
Limits the number of results shown. The total match count is still reported
so users know how many were omitted. Works for both single-session and
multi-session grep, with the limit applied globally across sessions.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
- Add test/e2e/suites/basic/grep-global.test.sh covering mcpc grep <pattern>
  across all active sessions (multi-session search, type flags, regex,
  case sensitivity, JSON output, --max-results, no-sessions edge case)
- Add grep section to README with usage examples
- Add grep to command listings in README help block
- Remove per-session "(N matches)" suffix from global grep human output

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
The test's "no sessions" assertions at the end could fail when other
parallel tests had active sessions with matching tools in the shared
home directory.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J
@jancurn jancurn merged commit 7f6e9e8 into feat/grep-cmd Mar 24, 2026
5 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.

3 participants