From 6653462c302be3e8547504343dbcac4aec01ec7c Mon Sep 17 00:00:00 2001 From: Neil Sleightholm Date: Wed, 18 Nov 2026 09:27:37 +0800 Subject: [PATCH 1/4] Trust /data/uploads so Claude stops asking at every start (2.5.9) Record projects["/data/uploads"].hasTrustDialogAccepted in ~/.claude.json at start-up. The update is written to a copy beside the file and renamed into place, so a failed write can't cut the file short; an explicit false is kept. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- claude-terminal/CHANGELOG.md | 7 ++++ claude-terminal/DOCS.md | 1 + claude-terminal/config.yaml | 2 +- claude-terminal/run.sh | 51 +++++++++++++++++++++++++++ tests/test-production-run.sh | 67 ++++++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 20f3ac66..472dd4c7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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) diff --git a/claude-terminal/CHANGELOG.md b/claude-terminal/CHANGELOG.md index ebd9f3ee..47cb2cd7 100644 --- a/claude-terminal/CHANGELOG.md +++ b/claude-terminal/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 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 diff --git a/claude-terminal/DOCS.md b/claude-terminal/DOCS.md index 9ea2fd23..6b83d8f2 100644 --- a/claude-terminal/DOCS.md +++ b/claude-terminal/DOCS.md @@ -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 diff --git a/claude-terminal/config.yaml b/claude-terminal/config.yaml index cb37e38f..f98c7a32 100644 --- a/claude-terminal/config.yaml +++ b/claude-terminal/config.yaml @@ -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.9" slug: "claude_terminal_pro" init: false diff --git a/claude-terminal/run.sh b/claude-terminal/run.sh index 7a1266f4..a1981192 100644 --- a/claude-terminal/run.sh +++ b/claude-terminal/run.sh @@ -654,6 +654,56 @@ 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="${CLAUDE_GLOBAL_CONFIG:-$HOME/.claude.json}" + local dir="${UPLOAD_TRUST_DIR:-/data/uploads}" + local filter='.projects[$d] = ((.projects[$d] // {}) + {hasTrustDialogAccepted: true})' + local target tmp updated + + if [ -s "$config_file" ]; then + # Already decided: true needs nothing, and an explicit false is a + # choice made in Claude, which is kept + case "$(jq -r --arg d "$dir" '.projects[$d].hasTrustDialogAccepted | if type == "boolean" then . else "unset" end' "$config_file" 2>/dev/null)" in + true) return 0 ;; + false) + bashio::log.info "Not marking ${dir} as trusted: ${config_file} records it as not trusted" + return 0 + ;; + esac + # Never rewrite a file jq can't read: Claude may restore it from a backup + if ! updated=$(jq --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 JSON" + return 0 + fi + 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 @@ -1163,6 +1213,7 @@ main() { setup_ha_plugin setup_session_picker setup_statusline + trust_upload_dir setup_persistent_packages check_persisted_alpine_release run_init_commands diff --git a/tests/test-production-run.sh b/tests/test-production-run.sh index e936eb82..74ad6f31 100755 --- a/tests/test-production-run.sh +++ b/tests/test-production-run.sh @@ -384,4 +384,71 @@ 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 +trust_cfg="$tmp_dir/trust/.claude.json" +mkdir -p "$tmp_dir/trust" +export CLAUDE_GLOBAL_CONFIG="$trust_cfg" UPLOAD_TRUST_DIR=/data/uploads +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" + +# 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" +unset CLAUDE_GLOBAL_CONFIG UPLOAD_TRUST_DIR + +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" From a431ce992c6bfc7bbd6f680a0471187aea54a95e Mon Sep 17 00:00:00 2001 From: Neil Sleightholm Date: Wed, 25 Nov 2026 09:53:09 +0800 Subject: [PATCH 2/4] docs: running more than one Claude (tmux windows) (2.5.10) Document the tmux window keys, how every device follows the same windows, and what to expect with several Claudes (memory, shared /config). Co-Authored-By: Claude Opus 5.5 --- claude-terminal/CHANGELOG.md | 8 +++++++ claude-terminal/DOCS.md | 43 ++++++++++++++++++++++++++++++++++++ claude-terminal/config.yaml | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/claude-terminal/CHANGELOG.md b/claude-terminal/CHANGELOG.md index ebd9f3ee..f41bdcaf 100644 --- a/claude-terminal/CHANGELOG.md +++ b/claude-terminal/CHANGELOG.md @@ -1,5 +1,13 @@ # 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.8 ### 🐛 Bug Fix - Login Notifications diff --git a/claude-terminal/DOCS.md b/claude-terminal/DOCS.md index 9ea2fd23..2416dc95 100644 --- a/claude-terminal/DOCS.md +++ b/claude-terminal/DOCS.md @@ -479,6 +479,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 window (a shell in `/config`; run `claude-session-picker` in it for 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 diff --git a/claude-terminal/config.yaml b/claude-terminal/config.yaml index cb37e38f..40431930 100644 --- a/claude-terminal/config.yaml +++ b/claude-terminal/config.yaml @@ -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 From 1381088c7eea6088cb733415b053013a7c4607f7 Mon Sep 17 00:00:00 2001 From: ESJavadex <11579714+ESJavadex@users.noreply.github.com> Date: Wed, 25 Nov 2026 17:32:31 +0100 Subject: [PATCH 3/4] Validate the Claude config before recording upload trust --- claude-terminal/run.sh | 29 +++++++++++++++++------------ tests/test-production-run.sh | 14 ++++++++++---- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/claude-terminal/run.sh b/claude-terminal/run.sh index a1981192..b51a42e8 100644 --- a/claude-terminal/run.sh +++ b/claude-terminal/run.sh @@ -662,28 +662,33 @@ setup_session_picker() { # 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="${CLAUDE_GLOBAL_CONFIG:-$HOME/.claude.json}" - local dir="${UPLOAD_TRUST_DIR:-/data/uploads}" - local filter='.projects[$d] = ((.projects[$d] // {}) + {hasTrustDialogAccepted: true})' + 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 - # Already decided: true needs nothing, and an explicit false is a - # choice made in Claude, which is kept - case "$(jq -r --arg d "$dir" '.projects[$d].hasTrustDialogAccepted | if type == "boolean" then . else "unset" end' "$config_file" 2>/dev/null)" in + # 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 - # Never rewrite a file jq can't read: Claude may restore it from a backup - if ! updated=$(jq --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 JSON" - return 0 - fi else - updated=$(jq -n --arg d "$dir" "$filter") || return 0 + updated=$(jq -n --arg d "$dir" '[{}] | '"$filter") || return 0 fi # Write a copy beside the file and rename it into place, so a failed diff --git a/tests/test-production-run.sh b/tests/test-production-run.sh index 74ad6f31..a6d31d1d 100755 --- a/tests/test-production-run.sh +++ b/tests/test-production-run.sh @@ -386,9 +386,9 @@ 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 -trust_cfg="$tmp_dir/trust/.claude.json" -mkdir -p "$tmp_dir/trust" -export CLAUDE_GLOBAL_CONFIG="$trust_cfg" UPLOAD_TRUST_DIR=/data/uploads +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" @@ -420,6 +420,13 @@ 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") @@ -446,7 +453,6 @@ 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" -unset CLAUDE_GLOBAL_CONFIG UPLOAD_TRUST_DIR grep -qE '^ +trust_upload_dir$' <(sed -n '/^main() {/,/^}/p' "$repo_root/claude-terminal/run.sh") || \ fail "main() must run trust_upload_dir" From 5688dc44b83a953073362178b2de8b1db926abc5 Mon Sep 17 00:00:00 2001 From: ESJavadex <11579714+ESJavadex@users.noreply.github.com> Date: Wed, 25 Nov 2026 17:32:47 +0100 Subject: [PATCH 4/4] Clarify the starting directory of new tmux windows --- claude-terminal/DOCS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/claude-terminal/DOCS.md b/claude-terminal/DOCS.md index 2416dc95..9cdfbb77 100644 --- a/claude-terminal/DOCS.md +++ b/claude-terminal/DOCS.md @@ -497,7 +497,7 @@ same time. | Keys | What it does | | --- | --- | -| `Ctrl-b c` | New window (a shell in `/config`; run `claude-session-picker` in it for the menu) | +| `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 |