Update Search Smart
All-in-one hook covering automatically, adds, current, year. Includes structured workflows, validation checks, and reusable patterns for pre tool.
Update Search Smart
Automatically appends the current year to web search queries that lack temporal context, ensuring search results are current and relevant.
When to Use This Hook
Attach this hook when you need to:
- Ensure Claude's web searches return current-year results without manually adding dates
- Prevent outdated search results when researching libraries, APIs, or best practices
- Maintain search relevance for fast-moving domains like AI, frameworks, and security advisories
Consider alternatives when:
- You intentionally search for historical information and do not want year appended
- Your queries already contain temporal keywords like "latest" or "recent"
Quick Start
Configuration
name: update-search-smart type: hook trigger: PreToolUse category: pre-tool
Example Trigger
# Hook triggers before a WebSearch tool invocation claude> Search for "Next.js server components tutorial" # Hook modifies query to "Next.js server components tutorial 2026"
Example Output
Search query updated: "Next.js server components tutorial" → "Next.js server components tutorial 2026"
Core Concepts
Query Modification Logic Overview
| Aspect | Details |
|---|---|
| Year Detection | Checks for existing 20XX pattern in query |
| Temporal Keywords | Detects "latest", "recent", "current", "new", "now", "today" |
| Modification Rule | Appends current year only when no year or temporal word is present |
| Implementation | Python script processing JSON input via stdin |
| Output | Modified tool input via hookSpecificOutput |
Query Processing Workflow
WebSearch Invoked
|
Parse Query String
|
Contains Year (20XX)?
/ \
Yes No
| |
Skip Contains Temporal
Keyword?
/ \
Yes No
| |
Skip Append Year
|
Return Modified
Query
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
matcher | string | "WebSearch" | Tool invocation to intercept |
temporal_keywords | string[] | ["latest","recent","current","new","now","today"] | Words that indicate the query already has temporal context |
year_pattern | string | r"\b20\d{2}\b" | Regex to detect existing year in query |
append_format | string | " {year}" | How the year is appended to the query |
timeout | number | 5 | Maximum seconds for the hook script to execute |
Best Practices
-
Expand Temporal Keywords - Add domain-specific temporal words like "upcoming", "roadmap", "changelog", or "release notes" to the skip list. These queries inherently seek current information.
-
Handle Edge Cases for Versioning - Queries containing version numbers like "Python 3.12" might match the year pattern incorrectly. The
20XXpattern avoids this for most cases, but test with your common queries. -
Keep the Script Lightweight - The 5-second timeout is generous for a simple string operation. The Python script should parse, check, and return in under 100ms to avoid perceptible delay.
-
Log Modified Queries - During initial setup, log both original and modified queries to verify the hook is making correct decisions. Disable logging once you are confident in the logic.
-
Support Multiple Search Tools - If your setup includes multiple search-capable tools, add matchers for each one rather than only
WebSearch. Custom MCP search tools benefit from the same year-appending logic.
Common Issues
-
Year Appended to Historical Queries - Searching for "Python 2.7 migration guide" gets "2026" appended, skewing results. Add a mechanism to detect version-focused queries and skip appending.
-
Python Not Available - The hook uses
python3to process JSON. On minimal Docker images or CI runners, Python may not be installed. Add a fallback or use a shell-based implementation. -
Double Year on Retry - If a search is retried and the modified query already contains the year, the regex check should prevent double-appending. Verify your year pattern matches at word boundaries.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.