# gtapps/claude-code-hermit architecture

> Architecture diagram of the GitHub repository gtapps/claude-code-hermit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gtapps/claude-code-hermit
- Repository: https://github.com/gtapps/claude-code-hermit

## Overview

#### Purpose and Repository Shape
This monorepo delivers Claude Code plugins centered on **Hermit**, a persistent, proactive, cost-aware agent runtime. The core plugin turns a local Claude Code installation into an operator-governed always-on agent; domain plugins extend it for development, Home Assistant, fitness, feeds, Laravel Forge, and GitHub issue filing. Plugin manifests are the installation entry points: `plugins/claude-code-hermit/.claude-plugin/plugin.json` and sibling plugin manifests.

#### Core Hermit Runtime
The primary executable surface is Bun/TypeScript scripts under `plugins/claude-code-hermit/scripts/`. Lifecycle commands start, stop, pause, and supervise the resident Claude session: `scripts/hermit-start.ts`, `scripts/hermit-stop.ts`, `scripts/hermit-pause.ts`, and `scripts/hermit-watchdog.ts`. Generated per-installation shell entry points and state templates live in `plugins/claude-code-hermit/state-templates/bin/` and `plugins/claude-code-hermit/state-templates/`.

#### Setup, Configuration, and State Boundary
`/hatch` establishes an installation-specific `.claude-code-hermit` state area, scaffolds operator/state documents, and creates validated configuration. The orchestration path is `scripts/domain-hatch.ts`, `scripts/hatch-config.ts`, and `scripts/hatch-scaffold.ts`; configuration reads, validation, and settings registry behavior are centralized in `scripts/lib/config-read.ts`, `scripts/lib/settings/registry.ts`, and `scripts/validate-config.ts`. Repository plugin code is distinct from mutable operator state, including session records, knowledge, budget/cost logs, and generated Docker files.

#### Event-Driven Scheduling and Session Control
The system avoids model wakes unless filesystem prechecks determine work is due. Heartbeats, scheduled routines, monitors, and watchdog recovery form the control plane: `scripts/heartbeat.ts`, `scripts/routine-monitor.sh`, `scripts/routines.ts`, and `scripts/lib/routines/`. Prompt handling passes through a staged pipeline that applies context, channel command, pause, verification, and shutdown gates before model work: `scripts/user-prompt-pipeline.ts` and `scripts/lib/prompt-stages/`. `tmux`, cron/Monitor scheduling, and optional Docker provide the durable process boundary.

#### Learning, Knowledge, and Proposals
Session output and observations become durable evidence, then feed an operator-gated improvement loop. Key stages include session archival/digests (`scripts/session-archive.ts`, `scripts/transcript-digest.ts`), reflection evaluation (`scripts/evaluate-session.ts`, `scripts/apply-reflection-actions.ts`), and proposal lifecycle management (`scripts/proposal.ts`, `scripts/lib/proposals/`). Knowledge follows a raw-to-compiled model, with startup context bounded and searchable through `scripts/startup-context.ts`, `scripts/knowledge-lint.ts`, and `scripts/search.ts`. Proposal acceptance is the explicit boundary before runtime/self-modifying changes.

#### External Interfaces, Safety, and Observability
Claude Code is the host runtime and subscription-backed model provider. Optional integrations include Discord/Telegram channels, native push notifications, Claude Code Artifacts or a configured MCP artifact backend, and Claude remote control. Channel transport and trust controls are implemented in `scripts/channel-hook.ts`, `scripts/channel-send.ts`, and `scripts/lib/channel-auth.ts`. Safety is enforced at hook/tool boundaries through deny patterns, ask/pause gates, injection scanning, guest-session detection, and permission alerts: `scripts/ask-gate.ts`, `scripts/pause-gate.ts`, `scripts/enforce-deny-patterns.ts`. Cost/usage accounting and artifact reporting use `scripts/cost-tracker.ts`, `scripts/report-export.ts`, and `scripts/lib/dashboard.ts`.

#### Deployment and Extension Model
Docker setup renders a hardened baseline plus optional network-security overlay from `plugins/claude-code-hermit/state-templates/docker/`; preflight and template renderers are `scripts/docker-preflight.ts` and `scripts/render-docker-templates.ts`. Extension plugins independently contribute Claude skills, hooks, agents, settings, and sometimes domain runtimes. Notable code-backed extensions are Home Assistant’s Bun CLI/API layer (`plugins/claude-code-homeassistant-hermit/src/cli.ts`, `src/ha-api.ts`, `src/policy.ts`) and Laravel Forge’s PHP SDK wrapper (`plugins/laravel-forge-hermit/php/forge.php`, `php/forge-operation.php`). Root workflows and `scripts/test-all.sh` coordinate cross-plugin validation.

Main entry points: [`plugins/claude-code-hermit/.claude-plugin/plugin.json`](https://github.com/gtapps/claude-code-hermit/blob/main/plugins/claude-code-hermit/.claude-plugin/plugin.json) (Hermit plugin manifest), [`plugins/claude-code-homeassistant-hermit/src/cli.ts`](https://github.com/gtapps/claude-code-hermit/blob/main/plugins/claude-code-homeassistant-hermit/src/cli.ts) (Home Assistant extension), [`plugins/laravel-forge-hermit/php/forge.php`](https://github.com/gtapps/claude-code-hermit/blob/main/plugins/laravel-forge-hermit/php/forge.php) (Laravel Forge extension)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Hermit Runtime"]
  node_plugin["Hermit plugin manifest<br/>plugin entry<br/>[plugin.json]"]
  node_hatch["Hatch setup<br/>setup orchestration"]
  node_config["Config registry<br/>configuration"]
  node_operator_state[("Operator state<br/>mutable state")]
  node_lifecycle["Resident session lifecycle<br/>Bun commands"]
  node_process_boundary{{"Durable process boundary"}}
end

subgraph group_control["Control Plane"]
  node_heartbeat["Heartbeat prechecks<br/>scheduler gate"]
  node_routines["Routines and monitors<br/>scheduled work"]
  node_watchdog["Watchdog recovery<br/>supervisor"]
  node_prompt_pipeline["Prompt gate pipeline<br/>staged prompt handling"]
end

subgraph group_learning["Learning Loop"]
  node_session_archive["Session archive and digest<br/>evidence capture"]
  node_reflection["Reflection evaluation<br/>improvement analysis"]
  node_proposals["Proposal lifecycle<br/>operator approval"]
  node_knowledge[("Compiled knowledge<br/>searchable context")]
end

subgraph group_interfaces["Interfaces &amp; Safety"]
  node_channels["Channel transport<br/>Discord / Telegram"]
  node_safety{{"Tool and prompt safety gates<br/>policy enforcement"}}
  node_observability["Cost and artifact reporting<br/>usage reporting"]
  node_docker["Docker hardening<br/>deployment renderer"]
  node_claude_code(("Claude Code"))
end

subgraph group_extensions["Extensions"]
  node_home_assistant["Home Assistant extension<br/>Bun CLI and API<br/>[cli.ts]"]
  node_forge["Laravel Forge extension<br/>PHP SDK wrapper<br/>[forge.php]"]
end

node_plugin -->|"installs"| node_hatch
node_hatch -->|"creates and validates"| node_config
node_hatch -->|"scaffolds"| node_operator_state
node_config -->|"configures"| node_lifecycle
node_lifecycle -->|"runs within"| node_process_boundary
node_process_boundary -->|"supervised by"| node_watchdog
node_watchdog -->|"recovers"| node_lifecycle
node_routines -->|"schedules"| node_heartbeat
node_heartbeat -->|"wakes only when due"| node_prompt_pipeline
node_prompt_pipeline -->|"enforces gates"| node_safety
node_channels -->|"delivers prompts"| node_prompt_pipeline
node_prompt_pipeline -->|"authorizes model work"| node_claude_code
node_claude_code -->|"produces session output"| node_session_archive
node_session_archive -->|"stores evidence"| node_operator_state
node_session_archive -->|"feeds"| node_reflection
node_reflection -->|"creates improvements"| node_proposals
node_proposals -.->|"accepted changes apply to"| node_lifecycle
node_session_archive -->|"contributes observations"| node_knowledge
node_knowledge -->|"supplies startup context"| node_prompt_pipeline
node_claude_code -->|"usage tracked by"| node_observability
node_docker -.->|"optional isolation"| node_process_boundary
node_home_assistant -->|"extends"| node_claude_code
node_forge -->|"extends"| node_claude_code

click node_plugin "https://github.com/gtapps/claude-code-hermit/blob/main/plugins/claude-code-hermit/.claude-plugin/plugin.json"
click node_home_assistant "https://github.com/gtapps/claude-code-hermit/blob/main/plugins/claude-code-homeassistant-hermit/src/cli.ts"
click node_forge "https://github.com/gtapps/claude-code-hermit/blob/main/plugins/laravel-forge-hermit/php/forge.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_plugin,node_hatch,node_config,node_operator_state,node_lifecycle,node_process_boundary toneBlue
class node_heartbeat,node_routines,node_watchdog,node_prompt_pipeline toneAmber
class node_session_archive,node_reflection,node_proposals,node_knowledge toneMint
class node_channels,node_safety,node_observability,node_docker,node_claude_code toneRose
class node_home_assistant,node_forge toneIndigo
```

## Components

### Hermit Runtime

- [Hermit plugin manifest](https://github.com/gtapps/claude-code-hermit/blob/main/plugins/claude-code-hermit/.claude-plugin/plugin.json): plugin entry · Installation entry point for the core plugin. · `plugins/claude-code-hermit/.claude-plugin/plugin.json`
- **Hatch setup**: setup orchestration · Creates and validates an installation-specific runtime.
- **Config registry**: configuration · Centralized configuration reads, validation, and settings.
- **Operator state**: mutable state · Per-installation sessions, knowledge, budgets, and generated files.
- **Resident session lifecycle**: Bun commands · Starts, stops, pauses, and supervises Claude sessions.
- **Durable process boundary**: tmux / scheduler / Docker · Keeps the resident runtime alive across operator sessions.

### Control Plane

- **Heartbeat prechecks**: scheduler gate · Avoids model wakes until filesystem checks find due work.
- **Routines and monitors**: scheduled work · Runs heartbeats, routines, monitors, and recovery checks.
- **Watchdog recovery**: supervisor
- **Prompt gate pipeline**: staged prompt handling · Applies context, channel, pause, verification, and shutdown gates.

### Learning Loop

- **Session archive and digest**: evidence capture · Turns session output into durable records and digests.
- **Reflection evaluation**: improvement analysis · Evaluates sessions and derives follow-up actions.
- **Proposal lifecycle**: operator approval · Acceptance gates runtime and self-modifying changes.
- **Compiled knowledge**: searchable context · Bounds startup context while retaining searchable knowledge.

### Interfaces & Safety

- **Channel transport**: Discord / Telegram · Receives and sends trusted remote channel messages.
- **Tool and prompt safety gates**: policy enforcement · Enforces deny, ask, pause, injection, and guest-session controls.
- **Cost and artifact reporting**: usage reporting · Tracks usage and exports reports or artifacts.
- **Docker hardening**: deployment renderer · Renders hardened baseline and optional network overlays.
- **Claude Code**: host runtime and model provider · Subscription-backed host for resident model sessions.

### Extensions

- [Home Assistant extension](https://github.com/gtapps/claude-code-hermit/blob/main/plugins/claude-code-homeassistant-hermit/src/cli.ts): Bun CLI and API · `plugins/claude-code-homeassistant-hermit/src/cli.ts`
- [Laravel Forge extension](https://github.com/gtapps/claude-code-hermit/blob/main/plugins/laravel-forge-hermit/php/forge.php): PHP SDK wrapper · `plugins/laravel-forge-hermit/php/forge.php`

## Connections

- Hermit plugin manifest → Hatch setup: installs
- Hatch setup → Config registry: creates and validates
- Hatch setup → Operator state: scaffolds
- Config registry → Resident session lifecycle: configures
- Resident session lifecycle → Durable process boundary: runs within
- Durable process boundary → Watchdog recovery: supervised by
- Watchdog recovery → Resident session lifecycle: recovers
- Routines and monitors → Heartbeat prechecks: schedules
- Heartbeat prechecks → Prompt gate pipeline: wakes only when due
- Prompt gate pipeline → Tool and prompt safety gates: enforces gates
- Channel transport → Prompt gate pipeline: delivers prompts
- Prompt gate pipeline → Claude Code: authorizes model work
- Claude Code → Session archive and digest: produces session output
- Session archive and digest → Operator state: stores evidence
- Session archive and digest → Reflection evaluation: feeds
- Reflection evaluation → Proposal lifecycle: creates improvements
- Proposal lifecycle → Resident session lifecycle: accepted changes apply to
- Session archive and digest → Compiled knowledge: contributes observations
- Compiled knowledge → Prompt gate pipeline: supplies startup context
- Claude Code → Cost and artifact reporting: usage tracked by
- Docker hardening → Durable process boundary: optional isolation
- Home Assistant extension → Claude Code: extends
- Laravel Forge extension → Claude Code: extends
