Skip to content
Back to skills

File Watcher

ASecurity

Configure file watching hooks to auto-react to config changes, env file updates, and dependency modifications. Use to set up reactive workflows.

  • 2,892 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added May 28, 2026
ai-agentsjavascripttypescriptjavabashreactnode

Works with

  • claude code

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned May 28, 2026

npx -y skills add rohitg00/pro-workflow --skill file-watcher --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of File Watcher?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for File Watcher
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rohitg00-file-watcher/badge)](https://www.skillsdirectory.com/skills/rohitg00-file-watcher)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: file-watcher
description: Configure file watching hooks to auto-react to config changes, env file updates, and dependency modifications. Use to set up reactive workflows.
---

# File Watcher

Use Claude Code's `FileChanged` and `CwdChanged` hooks to create reactive workflows that respond to file system changes.

## Trigger

Use when:
- Setting up auto-reload for config changes
- Watching for dependency updates
- Monitoring build output
- Creating reactive development workflows

## How File Watching Works

Claude Code's `SessionStart` and `CwdChanged` hooks support returning `watchPaths` to register file watchers. The current `cwd-changed.js` script focuses on env injection; to add watch registration, your hook script must output this JSON structure:

```json
{
  "hookSpecificOutput": {
    "hookEventName": "SessionStart",
    "watchPaths": [
      "/absolute/path/to/.env",
      "/absolute/path/to/package.json"
    ]
  }
}
```

When watched files change, the `FileChanged` hook fires with:
```json
{
  "hook_event_name": "FileChanged",
  "file_path": "/path/to/changed/file",
  "event": "change"
}
```

## Environment Injection

`CwdChanged` and `FileChanged` hooks can write to `CLAUDE_ENV_FILE` to inject environment variables into subsequent Bash commands:

```bash
echo "export PROJECT_TYPE=node" >> "$CLAUDE_ENV_FILE"
echo "export TEST_CMD='npm test'" >> "$CLAUDE_ENV_FILE"
```

## Common Watch Patterns

### Watch .env for Changes
```javascript
const envFile = path.join(projectRoot, '.env');
if (fs.existsSync(envFile)) {
  output.hookSpecificOutput = {
    hookEventName: 'SessionStart',
    watchPaths: [envFile]
  };
}
```

### Watch package.json for Dependency Changes
Detect when dependencies change and remind to run `npm install`.

### Watch tsconfig.json for Config Changes
Remind to restart TypeScript checks when config changes.

## Setup

Add to hooks.json:
```json
{
  "FileChanged": [{
    "matcher": ".env|package.json|tsconfig.json",
    "hooks": [{
      "type": "command",
      "command": "node scripts/file-changed.js"
    }]
  }]
}
```

## Rules

- Use absolute paths for watchPaths (required by Claude Code)
- Matcher uses pipe-separated filenames
- Watcher uses 500ms stability threshold and 200ms poll interval
- Keep file-changed handlers fast (<5s) to avoid blocking
- Use `CLAUDE_ENV_FILE` for injecting env vars, not direct export

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.