From 6653462c302be3e8547504343dbcac4aec01ec7c Mon Sep 17 00:00:00 2001 From: Neil Sleightholm Date: Wed, 18 Nov 2026 09:27:37 +0800 Subject: [PATCH 1/2] 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 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 2/2] 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"