Add hooks API.

- Add tests.
- Split into bin.
- Add worker.