> For the complete documentation index, see [llms.txt](https://commandbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://commandbox.ortusbooks.com/5.3.0/usage/watch-command.md).

# watch Command

There are some specific commands that make use of the Watcher library in CommandBox such as `testbox watch` and `coldbox watch-reinit`. However, there is also a generic watch command that will run any arbitrary command of your choosing when a path matching your file globbing pattern is added/updated/deleted.

```bash
watch *.json "echo 'config file updated!'"
```

The following environment variables will be available to your command

* **watcher\_added** - A JSON array of relative paths added in the watch directory
* **watcher\_removed** - A JSON array of relative paths removed in the watch directory
* **watcher\_changed** - A JSON array of relative paths changed in the watch directory

Since escaping meta characters can get tricky with nested strings, you can declare the command as an environment variable and then just reference it like so:

```bash
set command = "echo 'You added \${item}!'"
watch command="foreach '\${watcher_added}' \${command}" --verbose
```

That example runs the `foreach` command over each item in the `watcher_added` array and then runs an `echo` statement to output the name of each added path.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://commandbox.ortusbooks.com/5.3.0/usage/watch-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
