CLI tools and configuration for using Claude Code with Home Assistant OS.
| File | Description |
|---|---|
bin/ha-api |
REST API CLI for quick state/service operations |
bin/ha-ws |
WebSocket CLI for registry management and detailed lookups |
bin/lovelace-sync |
Push dashboard changes to HA without restart |
install.sh |
Setup script for HA OS (re-run after updates) |
CLAUDE.md |
Instructions file that Claude Code reads automatically |
Install the "Terminal & SSH" add-on from the Home Assistant Add-on Store, then configure it with the required packages:
- Go to Settings → Add-ons → Terminal & SSH → Configuration
- Add these packages to the configuration:
apks:
- gcompat
- libstdc++
- curl
- procps
- coreutils
- tar
- bash
- python3
- py3-pip
- fzf- Save and restart the add-on
- Go to your Home Assistant profile (click your name in sidebar)
- Switch to the Security tab
- Scroll to "Long-Lived Access Tokens"
- Click "Create Token"
- Save the token for the next step
# SSH into your HA OS instance
cd /config
# Clone this repo
git clone https://github.com/danbuhler/claude-code-ha.git
# Run setup (installs dependencies + Claude Code)
cd claude-code-ha
./install.sh
# Edit /config/.env and add your long-lived access token
nano /config/.env# Install dependencies
apk add python3 py3-pip curl jq nodejs npm
pip3 install websockets --break-system-packages
# Install Claude Code
npm install -g @anthropic-ai/claude-code
# Copy scripts to PATH
cp bin/* /usr/local/bin/
chmod +x /usr/local/bin/ha-*
chmod +x /usr/local/bin/lovelace-sync
# Copy CLAUDE.md and .env to your HA config directory
cp CLAUDE.md /config/
cp .env.example /config/.env
nano /config/.env # Add your tokenFast lookups and service calls:
ha-api states # List all entities
ha-api states light # Filter by domain
ha-api state light.kitchen # Get specific entity state
ha-api attr sensor.temperature # Show attributes
ha-api devices motion # Find by device_class
ha-api search bedroom # Search entity IDs
ha-api call light turn_on # Call a service
ha-api history sensor.temp 48 # Get 48h historyRegistry management and detailed entity/device info:
# Entity operations
ha-ws entity list light # List light entities
ha-ws entity get light.kitchen # Full entity details + related items
ha-ws entity update light.old new_entity_id=light.new # Rename
# Device operations
ha-ws device list # List all devices
ha-ws device get <device_id> # Device details + all entities
# Area management
ha-ws area list # List areas
ha-ws area create "Guest Room" # Create area
# Service calls
ha-ws call light.turn_on entity_id=light.kitchen brightness=255
# Raw WebSocket
ha-ws raw config/entity_registry/listEdit .storage/lovelace directly, then push to HA:
# 1. Edit the lovelace file
# 2. Push changes (no restart needed)
lovelace-sync
# 3. Refresh browser to see changesNote: Changes made in the HA web interface will overwrite any unpushed local edits. Always run lovelace-sync before making changes in the UI.
The CLAUDE.md file provides Claude Code with context about:
- These CLI tools and how to use them
- Home Assistant YAML configuration patterns
- Best practices for automation/template syntax
Copy CLAUDE.md to your HA config directory. Claude Code automatically reads it when working there.
> claude
You: "Turn on the kitchen lights"
Claude: *uses ha-api call light turn_on*
You: "What motion sensors do I have?"
Claude: *uses ha-api devices motion*
You: "Rename light.old_lamp to light.bedroom_lamp"
Claude: *uses ha-ws entity update*
The install script creates /config/.env from the template. Edit it with your token:
# /config/.env
HA_URL=https://172.30.32.1:8128 # Internal HA API URL (HA OS default)
HA_TOKEN=your_token_here # Long-lived access tokenThe scripts search for .env in order:
$HA_ENV_FILE(if set)/config/.env(standard location)/homeassistant/.env- Current directory
~/.ha-cli.env
If running Claude Code from outside HA OS:
HA_URL=https://your-ha-domain.com:8123
HA_TOKEN=your_token_hereHA OS updates reset the root filesystem, removing installed packages and PATH modifications. Re-run install.sh after each HA OS update:
cd /config/claude-code-ha # or wherever you cloned it
./install.sh| Item | Action | On Re-run |
|---|---|---|
| System packages (python3, nodejs, etc.) | Installs via apk | Reinstalls (needed after HA update) |
| Python websockets | pip install | Reinstalls (needed after HA update) |
| Claude Code | npm install -g | Reinstalls (needed after HA update) |
ha-api, ha-ws, lovelace-sync |
Symlinks to repo's bin/ |
Recreates (safe) |
CLAUDE.md |
Copies to /config/ |
Skips if exists (preserves customizations) |
.env |
Copies template to /config/.env |
Skips if exists (preserves your token) |
PATH in /etc/profile.d/ |
Creates | Recreates (needed after HA update) |
Symlinks point to the scripts in the repo - updates to the repo are immediately available.
Copies are only made on first run. If you've customized CLAUDE.md, it won't be overwritten. To get updates, manually copy from the repo.
These survive in /config:
- The cloned repo itself
- Your
.envfile (with your token) - Your customized
CLAUDE.md
- Home Assistant (any installation with shell access)
- Python 3 with
websocketspackage curlandjqfor ha-api- Node.js/npm for Claude Code
MIT License - See LICENSE