U

Update Search Smart

All-in-one hook covering automatically, adds, current, year. Includes structured workflows, validation checks, and reusable patterns for pre tool.

HookClipticspre toolv1.0.0MIT
0 views0 copies

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

AspectDetails
Year DetectionChecks for existing 20XX pattern in query
Temporal KeywordsDetects "latest", "recent", "current", "new", "now", "today"
Modification RuleAppends current year only when no year or temporal word is present
ImplementationPython script processing JSON input via stdin
OutputModified 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

ParameterTypeDefaultDescription
matcherstring"WebSearch"Tool invocation to intercept
temporal_keywordsstring[]["latest","recent","current","new","now","today"]Words that indicate the query already has temporal context
year_patternstringr"\b20\d{2}\b"Regex to detect existing year in query
append_formatstring" {year}"How the year is appended to the query
timeoutnumber5Maximum seconds for the hook script to execute

Best Practices

  1. 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.

  2. Handle Edge Cases for Versioning - Queries containing version numbers like "Python 3.12" might match the year pattern incorrectly. The 20XX pattern avoids this for most cases, but test with your common queries.

  3. 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.

  4. 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.

  5. 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

  1. 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.

  2. Python Not Available - The hook uses python3 to process JSON. On minimal Docker images or CI runners, Python may not be installed. Add a fallback or use a shell-based implementation.

  3. 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.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates