Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Because `/data` is per add-on, installing the add-on from a different repository
4. Configure tmux and the `tmux-claude` wrapper
5. Set up persistent Claude (if `use_persistent_claude`)
6. Install or update the bundled Home Assistant plugin (`setup_ha_plugin`, option `home_assistant_plugin`; marketplace copied to `/opt/claude-plugins` at build time from the `HA_PLUGINS_REF` tag)
7. Install the session picker and auth helper, then the status line (`setup_statusline`: sets `statusLine` in `~/.claude/settings.json` only when there is none or it is ours)
7. Install the session picker and auth helper, then the status line (`setup_statusline`: sets `statusLine` in `~/.claude/settings.json` only when there is none or it is ours), and record `/data/uploads` as trusted in `~/.claude.json` (`trust_upload_dir`), so Claude doesn't ask about the `--add-dir` folder every session
8. Set up `persist-install` and auto-install packages listed in the options
9. Start the image service (7680), the login URL watcher (posts Claude's login link as an HA notification) and ttyd (7681)

Expand Down
15 changes: 15 additions & 0 deletions claude-terminal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 2.5.10

### 📚 Documentation - Running More Than One Claude
- **New DOCS section, "Running More Than One Claude"**: the terminal's tmux session can already hold several windows, for example a second Claude while the first is busy, but the docs didn't say how to reach them
- How every device shows the same windows, and follows when you switch on one of them
- The tmux keys for windows (`Ctrl-b c`, `1`…`9`, `n`/`p`, `w`, `,`, `&`), with the usual traps: Caps Lock turns `Ctrl-b c` into the options screen, and `Ctrl-b d` disconnects the panel
- What to expect: memory per Claude, a shared `/config` and shared usage limits

## 2.5.9

### 🐛 Bug Fix - No "Adding a New Directory" Question at Every Start
- **Claude no longer asks to trust `/data/uploads` each time it starts**: the add-on starts Claude with `--add-dir /data/uploads` so it can read files you paste, drop or upload. From Claude Code 2.1.327, Claude asks whether to trust each added folder it has no trust record for, and the answer lasts only for that session, so the question came up at every start, from the first window and from the session picker
- At start-up the add-on now records `/data/uploads` as trusted in `~/.claude.json`, the same record Claude writes when you accept its trust question. The rest of the file is left as it was, and a file that can't be read as JSON is never rewritten. The new file is written beside the old one and renamed into place, so a failed write can't leave a cut-off file, and a folder you have told Claude not to trust (`hasTrustDialogAccepted: false`) stays untrusted
- Only the upload folder is trusted, not `/data`, which also holds your login. Uploads are saved flat with cleaned-up names, so no Claude settings can be placed in that folder

## 2.5.8

### 🐛 Bug Fix - Login Notifications
Expand Down
44 changes: 44 additions & 0 deletions claude-terminal/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The add-on offers several configuration options:
- Behind a reverse proxy (NGINX, Caddy, a tunnel), the proxy's own upload limit applies first. NGINX allows only 1 MB unless told otherwise, so set `client_max_body_size 55m;` for Home Assistant if larger uploads fail with "413 Request Entity Too Large"
- Pasting a file copied in Finder or Explorer works in Safari and recent Chrome/Edge; drag-and-drop works in every browser. On an iPhone or iPad, use 📎 to pick from Photos or the Files app, or copy an image (such as a screenshot) and tap 📥 Paste (see [Pasting Into the Terminal](#pasting-into-the-terminal))
- Claude is started with `--add-dir /data/uploads`, so it can read uploads without asking. If you start `claude` yourself from a shell, add that flag, or Claude asks before reading each one
- The add-on marks `/data/uploads` as a trusted folder in `~/.claude.json` at start-up, so Claude doesn't ask "Adding a new directory: /data/uploads ... Is this a directory you created or one you trust?" at the start of every session (Claude Code 2.1.327 and later ask about each added folder that isn't recorded as trusted)
- Uploads are left out of Home Assistant backups and removed after 30 days. Files you want to keep belong in `/config` or `/share`

### Copying Text Out of the Terminal
Expand Down Expand Up @@ -479,6 +480,49 @@ For the `gh` token login, the picker suggests the `repo`, `read:org` and
`workflow` scopes. A fine-grained token limited to the repositories you want
Claude to work on is safer.

### Running More Than One Claude

The terminal's tmux session can hold several windows, each with its own
Claude or shell, for example a second Claude while the first is busy running
a long command, or a shell beside a Claude whose command you don't want to
interrupt. They all keep running when you switch away or close the panel.

**Every device shows the same windows.** The panel on each phone, tablet and
computer attaches to the same tmux session, so a window opened on one device
appears on the others, and switching windows on one device switches the
others too. That is what lets you start something on one device and carry on
from another. It also means two devices can't show different windows at the
same time.

**tmux keys**, for a keyboard (the phone key bar has no `Ctrl-b`):

| Keys | What it does |
| --- | --- |
| `Ctrl-b c` | New shell window. Run `pwd` to check its working directory and `claude-session-picker` to open the menu |
| `Ctrl-b 1` … `9` | Go to that window |
| `Ctrl-b n` / `Ctrl-b p` | Next / previous window |
| `Ctrl-b w` | List all windows with what each is running; pick one with the arrows and Enter |
| `Ctrl-b ,` | Rename the window (shown in the status bar) |
| `Ctrl-b &` | Close the window, after asking |

- The status bar at the bottom lists the windows: `*` marks the current one
and `-` the one before. A window running Claude from the session picker
(including the first one) is listed as `bash`, because tmux names a window
after the shell that started it; rename it with `Ctrl-b ,`
- Use lower case: `Ctrl-b C` (capital, for example with Caps Lock on) opens
tmux's options screen instead. Press `q` to leave it
- Avoid `Ctrl-b d` (detach): the panel shows a disconnected terminal until it
reconnects
- `tmux new-window claude-session-picker` opens a window that closes when you
exit the picker, with no shell to exit afterwards
- With **tmux Mouse Mode** on, clicking a window name in the status bar
switches too

Each Claude uses roughly 450–500 MB of memory, which matters on a 2–4 GB Pi or
HA Green. Two Claudes share `/config`, so they can overwrite each other's
changes, and one can restart Home Assistant under the other. They also share
your plan's usage limits.

### Logging In

The first time Claude starts it shows a login link. There are two ways to
Expand Down
2 changes: 1 addition & 1 deletion claude-terminal/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "Claude Terminal Pro"
description: "Enhanced terminal interface for Anthropic's Claude Code CLI with persistent auth, package management, and image paste support. Fork of heytcass/home-assistant-addons"
version: "2.5.8"
version: "2.5.10"
slug: "claude_terminal_pro"
init: false

Expand Down
56 changes: 56 additions & 0 deletions claude-terminal/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,61 @@ setup_session_picker() {
fi
}

# Claude is started with --add-dir /data/uploads (build_claude_flags). From
# 2.1.327, Claude Code asks every session whether to trust an added folder
# that has no trust record, so the question came up at each start. Record the
# upload folder as trusted in ~/.claude.json, the same record Claude writes
# when its trust prompt is accepted. Only this folder: a record on /data would
# also cover /data/home and the login. The image service writes uploads flat,
# with cleaned-up, time-stamped names, so no .claude settings can appear in it.
trust_upload_dir() {
local config_file="$HOME/.claude.json"
local dir="/data/uploads"
local filter='
if length != 1 or (.[0] | type) != "object" then
error("expected one config object")
else .[0] end
| .projects[$d].hasTrustDialogAccepted as $trust
| if ($trust | type) == "boolean" then $trust
else .projects[$d].hasTrustDialogAccepted = true end
'
local target tmp updated

if [ -s "$config_file" ]; then
# Never rewrite a file that is not a single config object.
if ! updated=$(jq -s --arg d "$dir" "$filter" "$config_file" 2>/dev/null); then
bashio::log.warning "Not marking ${dir} as trusted: ${config_file} could not be read as a JSON object"
return 0
fi
case "$updated" in
true) return 0 ;;
false)
bashio::log.info "Not marking ${dir} as trusted: ${config_file} records it as not trusted"
return 0
;;
esac
else
updated=$(jq -n --arg d "$dir" '[{}] | '"$filter") || return 0
fi

# Write a copy beside the file and rename it into place, so a failed
# write never leaves a cut-off ~/.claude.json. The copy starts as cp -p
# of the original, so it keeps the owner and permissions; a new file is
# mktemp's 600. A symlink is followed, so the link itself is kept.
target=$(readlink -f "$config_file" 2>/dev/null) || target="$config_file"
if ! tmp=$(mktemp "${target}.XXXXXX" 2>/dev/null); then
bashio::log.warning "Could not mark ${dir} as trusted in ${config_file}"
return 0
fi
if { [ ! -e "$target" ] || cp -p "$target" "$tmp"; } &&
printf '%s\n' "$updated" > "$tmp" && mv -f "$tmp" "$target"; then
bashio::log.info "Marked ${dir} as a trusted folder for Claude"
else
rm -f "$tmp"
bashio::log.warning "Could not mark ${dir} as trusted in ${config_file}"
fi
}

# Home Assistant status line (scripts/ha-statusline.sh). The add-on's
# statusline option is a list of pieces in display order: a piece name
# (ha-statusline --segments), --- for a new line, or an entity as sensor.x or
Expand Down Expand Up @@ -1163,6 +1218,7 @@ main() {
setup_ha_plugin
setup_session_picker
setup_statusline
trust_upload_dir
setup_persistent_packages
check_persisted_alpine_release
run_init_commands
Expand Down
73 changes: 73 additions & 0 deletions tests/test-production-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,77 @@ migrate_legacy_auth_files "$legacy_dst"
[ ! -e "$legacy_dst/configs" ] || fail "after the first pass, files planted in a legacy source must not be copied"
unset LEGACY_AUTH_SOURCES LEGACY_AUTH_MARKER

# The upload folder is recorded as trusted in ~/.claude.json, so Claude
# 2.1.327+ doesn't ask about --add-dir /data/uploads at every start
HOME="$tmp_dir/trust"
trust_cfg="$HOME/.claude.json"
mkdir -p "$HOME"
trust_upload_dir
[ "$(jq -r '.projects["/data/uploads"].hasTrustDialogAccepted' "$trust_cfg")" = true ] || \
fail "a missing ~/.claude.json should be created with the upload folder trusted"
[ "$(stat -c %a "$trust_cfg" 2>/dev/null || stat -f %Lp "$trust_cfg")" = 600 ] || \
fail "a new ~/.claude.json must be private (600)"

cat > "$trust_cfg" <<'JSON'
{"numStartups": 7, "oauthAccount": {"emailAddress": "x"},
"projects": {"/config": {"hasTrustDialogAccepted": true, "allowedTools": ["Bash"]},
"/data/uploads": {"allowedTools": ["Read"]}}}
JSON
chmod 640 "$trust_cfg"
trust_upload_dir
[ "$(jq -r '.projects["/data/uploads"].hasTrustDialogAccepted' "$trust_cfg")" = true ] || \
fail "the upload folder should be marked trusted"
[ "$(jq -c '[.numStartups, .oauthAccount.emailAddress, .projects["/config"], .projects["/data/uploads"].allowedTools]' "$trust_cfg")" = \
'[7,"x",{"hasTrustDialogAccepted":true,"allowedTools":["Bash"]},["Read"]]' ] || \
fail "marking the upload folder must keep the rest of ~/.claude.json"
[ "$(jq -r '.projects | keys | join(",")' "$trust_cfg")" = "/config,/data/uploads" ] || \
fail "only the upload folder may be added (never /data)"
[ "$(stat -c %a "$trust_cfg" 2>/dev/null || stat -f %Lp "$trust_cfg")" = 640 ] || \
fail "an existing ~/.claude.json must keep its permissions"

before=$(cat "$trust_cfg")
trust_upload_dir
[ "$(cat "$trust_cfg")" = "$before" ] || fail "an already trusted upload folder must leave the file untouched"

printf '{"projects": {broken' > "$trust_cfg"
trust_upload_dir
[ "$(cat "$trust_cfg")" = '{"projects": {broken' ] || fail "an unreadable ~/.claude.json must never be rewritten"

for invalid_config in ' ' 'null' '{} {}'; do
builtin printf '%s\n' "$invalid_config" > "$trust_cfg"
before=$(cat "$trust_cfg")
trust_upload_dir
[ "$(cat "$trust_cfg")" = "$before" ] || fail "trust requires exactly one JSON object"
done

# An explicit false is a choice made in Claude, and is kept
printf '%s\n' '{"projects": {"/data/uploads": {"hasTrustDialogAccepted": false, "allowedTools": []}}}' > "$trust_cfg"
before=$(cat "$trust_cfg")
trust_upload_dir
[ "$(cat "$trust_cfg")" = "$before" ] || fail "an explicit hasTrustDialogAccepted: false must be kept"

# A write that fails partway leaves the original whole, and no copy behind.
# The stub writes a cut-off file, then fails, like a full disk.
printf '%s\n' '{"numStartups": 3, "projects": {}}' > "$trust_cfg"
before=$(cat "$trust_cfg")
printf() { builtin printf '{"projects": {"/data/up' > /dev/stdout; return 1; }
trust_upload_dir > /dev/null
unset -f printf
[ "$(cat "$trust_cfg")" = "$before" ] || fail "a failed write must leave ~/.claude.json as it was"
leftover=$(find "$tmp_dir/trust" -name '.claude.json.*')
[ -z "$leftover" ] || fail "a failed write must not leave a temporary copy: $leftover"

# The update is a rename, so a symlinked ~/.claude.json stays a link to the
# file that gets the update
printf '%s\n' '{"projects": {}}' > "$tmp_dir/trust/real.json"
rm -f "$trust_cfg"
ln -s real.json "$trust_cfg"
trust_upload_dir
[ -L "$trust_cfg" ] || fail "a symlinked ~/.claude.json must stay a symlink"
[ "$(jq -r '.projects["/data/uploads"].hasTrustDialogAccepted' "$tmp_dir/trust/real.json")" = true ] || \
fail "the file a symlinked ~/.claude.json points to should be updated"

grep -qE '^ +trust_upload_dir$' <(sed -n '/^main() {/,/^}/p' "$repo_root/claude-terminal/run.sh") || \
fail "main() must run trust_upload_dir"

echo "Production run.sh regression suite passed"
Loading