<!-- source: https://deepwiki.com/qhkm/zeptoclaw/5.6-hot-reload -->

# Hot Reload

- src/cli/watch.rs
- src/config/mod.rs
- src/config/types.rs

## Purpose and Scope

Hot Reload enables the ZeptoClaw gateway to apply configuration changes without restarting the process. The configuration system supports loading from `~/.zeptoclaw/config.json` [src/config/mod.rs4](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L4-L4) transparent decryption of `ENC[...]` secrets [src/config/mod.rs83-88](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L83-L88) and environment variable overrides [src/config/mod.rs95-96](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L95-L96)

The mechanism relies on the `ConfigWatcher` polling the configuration file, detecting modifications, validating the new configuration against a schema [src/config/mod.rs98-122](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L98-L122) and applying changes to specific sections transactionally.

Sources: [src/config/mod.rs4-122](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L4-L122)

## Configuration Watcher Architecture

### Polling-Based Change Detection

The `ConfigWatcher` (implemented in `src/config/watcher.rs`) monitors the configuration file defined at `Config::path()` [src/config/mod.rs59-61](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L59-L61) It ensures that updates are only applied if the file content is valid and the system can safely transition.

**ConfigWatcher Polling Flow**

```

```

Sources: [src/config/mod.rs59-106](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L59-L106)

### Change Detection and Application

Sources: [src/config/mod.rs78-106](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L78-L106)

## Supported Sections

### Hot-Reloadable Configuration

The system distinguishes between sections that can be updated at runtime and those requiring a full process restart.

**Section Support Matrix**

```

```

Sources: [src/config/types.rs58-139](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/types.rs#L58-L139) [src/config/mod.rs142-189](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L142-L189)

Sources: [src/config/types.rs58-139](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/types.rs#L58-L139) [src/config/mod.rs144-189](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L144-L189)

## Transactional Application with Rollback

### Agent and Provider Rebuild

When the Gateway receives a new `Config` from the watcher, it attempts a transactional update. If the new configuration fails validation or initialization, the system rolls back to the last known good state.

**Hot Reload Application Flow**

```

```

Sources: [src/config/mod.rs128-137](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L128-L137) [src/config/mod.rs98-122](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L98-L122)

### Configuration State Management

The global configuration is stored in a `OnceCell<RwLock<Config>>` named `CONFIG` [src/config/mod.rs22](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L22-L22)

- Reload Logic : The Config::reload() method src/config/mod.rs 128-131 calls Config::load() src/config/mod.rs 68-70 which performs the file read, decryption, and environment override application src/config/mod.rs 78-96
- Validation : Before swapping the RwLock content, validate_provider_api_bases src/config/mod.rs 98-106 and other diagnostics are run. If any diagnostic level is Error , the reload is aborted src/config/mod.rs 118-122

Sources: [src/config/mod.rs22-131](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L22-L131) [src/config/mod.rs98-122](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L98-L122)

## URL Watcher (Utility)

In addition to the internal `ConfigWatcher`, ZeptoClaw provides a `watch` command for monitoring external web resources [src/cli/watch.rs1-2](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L1-L2) This is a separate utility used by agents or users to track external changes.

**URL Watcher Component Mapping**

```

```

Sources: [src/cli/watch.rs44-93](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L44-L93) [src/cli/watch.rs59-80](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L59-L80)

### URL Watcher Features

- SSRF Protection : Uses resolve_and_check_host and is_blocked_host to prevent monitoring local/private network resources src/cli/watch.rs 67-74
- Snapshot Storage : Hashes URLs via DefaultHasher to create safe filenames in ~/.zeptoclaw/watch/ src/cli/watch.rs 44-56
- Resource Limits : Limits response body reads to 800KB ( MAX_WATCH_BYTES ) to prevent memory exhaustion src/cli/watch.rs 10-11
- Interval Parsing : Supports human-readable intervals like 1h , 30m , or 60s with a minimum of 10s to prevent abuse src/cli/watch.rs 13-41

Sources: [src/cli/watch.rs10-74](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L10-L74) [src/cli/watch.rs44-56](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L44-L56) [src/cli/watch.rs13-41](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L13-L41)

## Implementation References

### Key Code Locations

Sources: [src/config/mod.rs22-122](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/config/mod.rs#L22-L122) [src/cli/watch.rs17-167](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/cli/watch.rs#L17-L167)
