步骤 0: 检查本地缓存(重要)
在开始任何搜索之前,必须先检查本地缓存。
操作步骤:
- 读取项目根目录下的
claude-code-tips/data/index.json 文件 - 检查用户请求的类别是否已经有缓存数据
- 检查上次更新时间,判断是否需要刷新(默认7天内有效)
- 如果缓存有效,直接返回缓存内容
- 如果缓存过期或不存在,才进行网络搜索
缓存有效期规则:
new_features: 3天(快速更新的功能)core_tips: 7天(核心技巧相对稳定)best_practices: 14天(最佳实践变化较慢)shortcuts: 30天(快捷命令很少变化)skills_plugins: 7天(插件更新频率中等)mcp_servers: 7天(MCP 服务器更新频率中等)agent_sdk: 7天(SDK 文档更新频率中等)troubleshooting: 30天(故障排除内容相对稳定)
示例缓存检查逻辑:
```python
# 伪代码示例
index = read_json("data/index.json")
category = determine_category(user_query)
if index["categories"][category]["last_search"]:
last_update = parse_date(index["categories"][category]["last_search"])
days_since = (today - last_update).days
cache_valid_days = get_cache_valid_days(category)
if days_since < cache_valid_days:
# 缓存有效,返回缓存内容
return read_file(f"data/{index['categories'][category]['file']}")
```
步骤 1: 分析用户请求
根据用户的问题,确定需要搜索的类别:
类别判断关键词:
- "新功能"、"更新"、"最新" →
new_features - "技巧"、"技巧"、"窍门" →
core_tips - "最佳实践"、"建议"、"推荐" →
best_practices - "快捷键"、"命令"、"别名" →
shortcuts - "技能"、"插件"、"skill" →
skills_plugins - "MCP"、"服务器" →
mcp_servers - "Agent SDK"、"agent"、"SDK 开发"、"自定义 Agent" →
agent_sdk - "问题"、"错误"、"故障" →
troubleshooting
步骤 2: 搜索最新信息(仅在缓存过期时)
如果缓存过期或不存在,使用 WebSearch 工具搜索。
搜索关键词策略:
按类别搜索:
```
# 新功能
"Claude Code" new features 2025
"Claude Code" changelog updates
anthropic claude-code release notes
# 核心技巧
"Claude Code" tips tricks 2025
"Claude Code" productivity hacks
"Claude Code" efficient workflow
# 最佳实践
"Claude Code" best practices guide
"Claude Code" workflow optimization
"Claude Code" project setup
# 快捷命令
"Claude Code" CLI commands reference
"Claude Code" keyboard shortcuts
"Claude Code" slash commands
# 技能插件
"Claude Code" skills marketplace
"Claude Code" custom skills
"Claude Code" plugin development
# MCP 服务器
"Claude Code" MCP servers list
"Claude Code" MCP best practices
Model Context Protocol claude-code
# Agent SDK 开发
"Claude Agent SDK" documentation 2025
"Claude Agent SDK" examples tutorial
"Claude Agent SDK" custom agent development
Anthropic agent SDK guide
"Claude Agent SDK" quickstart
"Claude Agent SDK" Python examples
"Claude Agent SDK" TypeScript examples
# 故障排除
"Claude Code" troubleshooting
"Claude Code" common errors
"Claude Code" not working
```
步骤 3: 更新本地缓存
将搜索到的内容整理后保存到本地文件。
操作步骤:
- 整理搜索结果,按类别分组
- 生成结构化的 markdown 内容
- 写入到对应的
.md 文件 - 更新
index.json 中的时间戳和计数 - 将旧内容归档到
archive/ 目录
示例更新逻辑:
```python
# 项目根目录路径(需要根据实际情况确定)
PROJECT_ROOT = get_project_root()
DATA_DIR = f"{PROJECT_ROOT}/claude-code-tips/data"
# 更新数据文件
content = format_markdown(results)
write_file(f"{DATA_DIR}/{category_file}", content)
# 更新索引
index["categories"][category]["last_search"] = today.isoformat()
index["categories"][category]["count"] += len(new_items)
index["search_history"].append({
"date": today.isoformat(),
"category": category,
"items_found": len(new_items)
})
write_file(f"{DATA_DIR}/index.json", json.dumps(index, indent=2))
```
步骤 4: 返回结果给用户
从缓存文件中读取内容并返回给用户。
输出格式:
```markdown
# Claude Code {类别名称}
最后更新:{更新日期}
---
{缓存内容}
---
信息来源: 网络搜索 + 本地缓存
下次更新建议: {下次更新的日期}
```