以下为本文档的中文说明file-watcher 是一个文件监听技能用于配置文件监听钩子使其能够自动响应配置文件变更、环境文件更新和依赖修改等事件从而创建响应式的工作流。该技能利用 Claude Code 的 FileChanged 和 CwdChanged 钩子机制来实现文件系统变更的自动响应。其工作原理是通过在 SessionStart 和 CwdChanged 钩子脚本中注册 watchPaths 来监听指定文件路径。当被监听的文件发生变化时FileChanged 事件会被触发自动执行预定义的操作。使用场景包括设置配置文件的热重载机制——当 .env 文件或 config 文件发生变化时自动重新加载配置监听依赖文件如 package.json 的变化在依赖更新时自动重新安装监控构建输出目录在构建完成时自动触发后续处理流程以及创建响应式开发工作流让 AI 代理自动感知环境变化并做出相应调整。该技能支持的监听路径配置格式为 JSON 结构需要指定钩子事件名称和要监听的绝对路径列表。核心特点包括基于事件驱动的文件变更响应机制、支持多种钩子事件类型SessionStart、CwdChanged、FileChanged、灵活的路径配置方式、与 Claude Code 原生集成的零额外依赖设计、以及自动化的环境感知能力。对于追求开发流程自动化的团队来说这个技能可以将原本需要手动触发的各种操作转变为自动化的响应式流程显著提升开发效率。File WatcherUse Claude Code’sFileChangedandCwdChangedhooks to create reactive workflows that respond to file system changes.TriggerUse when:Setting up auto-reload for config changesWatching for dependency updatesMonitoring build outputCreating reactive development workflowsHow File Watching WorksClaude Code’sSessionStartandCwdChangedhooks support returningwatchPathsto register file watchers. The currentcwd-changed.jsscript focuses on env injection; to add watch registration, your hook script must output this JSON structure:{hookSpecificOutput:{hookEventName:SessionStart,watchPaths:[/absolute/path/to/.env,/absolute/path/to/package.json]}}When watched files change, theFileChangedhook fires with:{hook_event_name:FileChanged,file_path:/path/to/changed/file,event:change}Environment InjectionCwdChangedandFileChangedhooks can write toCLAUDE_ENV_FILEto inject environment variables into subsequent Bash commands:echoexport PROJECT_TYPEnode$CLAUDE_ENV_FILEechoexport TEST_CMDnpm test$CLAUDE_ENV_FILECommon Watch PatternsWatch .env for ChangesconstenvFilepath.join(projectRoot,.env);if(fs.existsSync(envFile)){output.hookSpecificOutput{hookEventName:SessionStart,watchPaths:[envFile]};}Watch package.json for Dependency ChangesDetect when dependencies change and remind to runnpm install.Watch tsconfig.json for Config ChangesRemind to restart TypeScript checks when config changes.SetupAdd to hooks.json:{FileChanged:[{matcher:.env|package.json|tsconfig.json,hooks:[{type:command,command:node scripts/file-changed.js}]}]}RulesUse absolute paths for watchPaths (required by Claude Code)Matcher uses pipe-separated filenamesWatcher uses 500ms stability threshold and 200ms poll intervalKeep file-changed handlers fast (5s) to avoid blockingUseCLAUDE_ENV_FILEfor injecting env vars, not direct export