From 2c54b09c8e48f412bb12335c7569f7d830873730 Mon Sep 17 00:00:00 2001 From: broisnischal Date: Mon, 3 Aug 2026 22:33:22 +0545 Subject: [PATCH 1/2] statusline: show the Shift+Tab permission mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The status line had no permission-mode indicator, because the statusLine payload does not carry one — `permission_mode` is absent from the documented schema (code.claude.com/docs/en/statusline), so nothing on stdin exposes it. The transcript does: Claude Code appends a `permission-mode` entry the moment the mode changes, so the badge tracks Shift+Tab live. Reading the transcript on every render would break this file's cheapness contract, so the resolved mode is cached against the transcript size: - transcript unchanged -> one `wc -c` (fstat, ~1ms on a multi-MB file) - transcript grew -> scan only the appended bytes - no cache / rotated -> bootstrap from the last 1MiB, not the whole file (a full scan of a 7.9MB transcript measured 231ms; bounded it is 66ms, and the entry is re-emitted every turn so an older one is superseded shortly) `default` renders nothing, matching Claude Code showing no indicator for it. Set PHOBOS_STATUSLINE_MODE=0 to opt out. --- skills/phobos/hooks/statusline.sh | 51 +++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/skills/phobos/hooks/statusline.sh b/skills/phobos/hooks/statusline.sh index 0e31a85..e284753 100755 --- a/skills/phobos/hooks/statusline.sh +++ b/skills/phobos/hooks/statusline.sh @@ -3,14 +3,15 @@ # Claude Code pipes session JSON on stdin and uses our stdout as the ENTIRE # status line — statusLine is ONE command, not an array — so we render every # badge here, including ponytail's if its flag is present. -# Must stay cheap: fires several times/second. One jq parse, no transcript reads. +# Must stay cheap: fires several times/second. One jq parse; the only transcript +# reads are size-guarded, so an unchanged transcript is never rescanned. set -euo pipefail in=$(cat) # One jq pass. Unit-separator delimited: unlike tabs, \x1f isn't IFS whitespace, # so empty fields (e.g. no transcript_path) don't shift the columns. -IFS=$'\x1f' read -r model dir effort added removed tp ctxpct rlpct < <( +IFS=$'\x1f' read -r model dir effort added removed tp ctxpct rlpct sid < <( printf '%s' "$in" | jq -r '[ (.model.display_name // .model.id // "?"), ((.workspace.current_dir // .cwd // ".") | split("/") | last | split("\\") | last), @@ -19,7 +20,8 @@ IFS=$'\x1f' read -r model dir effort added removed tp ctxpct rlpct < <( (.cost.total_lines_removed // 0), (.transcript_path // ""), (.context_window.used_percentage // -1 | floor), - (.rate_limits.five_hour.used_percentage // -1 | round) + (.rate_limits.five_hour.used_percentage // -1 | round), + (.session_id // "") ] | map(tostring) | join("")' 2>/dev/null ) || true @@ -39,6 +41,49 @@ if [ -f "$pflag" ]; then fi fi +# Permission-mode badge — the Shift+Tab mode, so the status line follows it. +# It is NOT in the statusLine payload (see code.claude.com/docs/en/statusline), +# so read the transcript, which is the live source: Claude Code appends a +# `permission-mode` entry the moment the mode changes. Kept cheap per this +# file's contract — the resolved mode is cached against the transcript size, so +# an idle render costs one `wc -c` and a growing one scans only the new bytes. +if [ "${PHOBOS_STATUSLINE_MODE:-1}" != 0 ] && [ -n "${tp:-}" ] && [ -f "$tp" ]; then + permmode=; csize=0 + mcache="${TMPDIR:-/tmp}/phobos-mode-${sid:-nosession}" + # `wc -c` fstats rather than reading, so this stays ~1ms on a multi-MB file. + tsize=$(wc -c <"$tp" 2>/dev/null) || tsize= + tsize=$(( ${tsize:-0} + 0 )) # BSD wc pads with spaces; normalise to an int + if [ -r "$mcache" ]; then + # Written without a trailing newline, so read reports EOF while still + # populating both fields — hence the `|| true`. + IFS=' ' read -r csize permmode <"$mcache" 2>/dev/null || true + case ${csize:-} in ''|*[!0-9]*) csize=0 ;; esac + fi + if [ "$tsize" -gt 0 ] && [ "$csize" != "$tsize" ]; then + # Resume from the last known offset. With no cache — or after a rotation + # shrank the file — bootstrap from the last 1MiB rather than the whole + # thing: a full scan of a multi-MB transcript costs ~200ms, and Claude Code + # re-emits the entry every turn, so anything older is superseded shortly. + if [ "$csize" -gt 0 ] && [ "$csize" -le "$tsize" ]; then from=$(( csize + 1 )) + elif [ "$tsize" -gt 1048576 ]; then from=$(( tsize - 1048576 )) + else from=1 + fi + found=$(tail -c "+$from" "$tp" 2>/dev/null \ + | grep -o '"permissionMode":"[A-Za-z]*"' | tail -n1 | cut -d'"' -f4) || found= + if [ -n "${found:-}" ]; then permmode=$found; fi + printf '%s %s' "$tsize" "${permmode:-}" >"$mcache" 2>/dev/null || true + fi + # `default` renders nothing — it is the baseline, and Claude Code shows no + # indicator for it either. Colour escalates with how much is being skipped. + case "${permmode:-}" in + plan) out+=" ${blue}[⏸ plan]${rst}" ;; + acceptEdits) out+=" ${green}[⏵ accept edits]${rst}" ;; + auto) out+=" ${yellow}[⏵⏵ auto]${rst}" ;; + bypassPermissions) out+=" ${red}[⏵⏵ bypass]${rst}" ;; + dontAsk) out+=" ${red}[⏵⏵ dont ask]${rst}" ;; + esac +fi + # model · dir out+=" ${dim}${model:-?} · ${dir:-.}${rst}" From 69b61f3bb5a74b4d605d92b35c5a6fc5be6e4619 Mon Sep 17 00:00:00 2001 From: broisnischal Date: Mon, 3 Aug 2026 23:01:09 +0545 Subject: [PATCH 2/2] statusline: only badge the mode when it differs from the default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An always-on `[⏵⏵ auto]` is noise: with permissions.defaultMode=auto you are in auto essentially always, and Claude Code already prints its own `⏵⏵ auto mode on` indicator right below the prompt. The badge only earns its space once you have switched away from the mode you configured. Resolve permissions.defaultMode from settings (local > project > user, with a PHOBOS_STATUSLINE_MODE_DEFAULT override) and render nothing while the current mode matches it. Resolved once per session and cached alongside the mode: defaultMode applies at startup, so editing it mid-session cannot change the mode the session is actually in — caching is correct here, not just cheap. Cache is now `|`-delimited. Space is IFS whitespace, so bash collapses runs of it and an empty permission-mode field would have silently shifted defmode into its place. Legacy space-delimited cache files fail the numeric size check and trigger one harmless re-bootstrap. --- skills/phobos/hooks/statusline.sh | 62 +++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/skills/phobos/hooks/statusline.sh b/skills/phobos/hooks/statusline.sh index e284753..4d528b7 100755 --- a/skills/phobos/hooks/statusline.sh +++ b/skills/phobos/hooks/statusline.sh @@ -11,7 +11,7 @@ in=$(cat) # One jq pass. Unit-separator delimited: unlike tabs, \x1f isn't IFS whitespace, # so empty fields (e.g. no transcript_path) don't shift the columns. -IFS=$'\x1f' read -r model dir effort added removed tp ctxpct rlpct sid < <( +IFS=$'\x1f' read -r model dir effort added removed tp ctxpct rlpct sid pdir < <( printf '%s' "$in" | jq -r '[ (.model.display_name // .model.id // "?"), ((.workspace.current_dir // .cwd // ".") | split("/") | last | split("\\") | last), @@ -21,7 +21,8 @@ IFS=$'\x1f' read -r model dir effort added removed tp ctxpct rlpct sid < <( (.transcript_path // ""), (.context_window.used_percentage // -1 | floor), (.rate_limits.five_hour.used_percentage // -1 | round), - (.session_id // "") + (.session_id // ""), + (.workspace.project_dir // .cwd // "") ] | map(tostring) | join("")' 2>/dev/null ) || true @@ -48,17 +49,42 @@ fi # file's contract — the resolved mode is cached against the transcript size, so # an idle render costs one `wc -c` and a growing one scans only the new bytes. if [ "${PHOBOS_STATUSLINE_MODE:-1}" != 0 ] && [ -n "${tp:-}" ] && [ -f "$tp" ]; then - permmode=; csize=0 + permmode=; defmode=; csize=0; dirty=0 mcache="${TMPDIR:-/tmp}/phobos-mode-${sid:-nosession}" # `wc -c` fstats rather than reading, so this stays ~1ms on a multi-MB file. tsize=$(wc -c <"$tp" 2>/dev/null) || tsize= tsize=$(( ${tsize:-0} + 0 )) # BSD wc pads with spaces; normalise to an int if [ -r "$mcache" ]; then + # `|`, not a space: space is IFS whitespace, so bash collapses runs of it + # and an empty middle field would silently shift the later columns. # Written without a trailing newline, so read reports EOF while still - # populating both fields — hence the `|| true`. - IFS=' ' read -r csize permmode <"$mcache" 2>/dev/null || true + # populating the fields — hence the `|| true`. + IFS='|' read -r csize permmode defmode <"$mcache" 2>/dev/null || true case ${csize:-} in ''|*[!0-9]*) csize=0 ;; esac fi + + # The mode the session started in. The badge only earns space once you have + # switched away from it — in your configured mode Claude Code already prints + # its own indicator, so repeating it here is pure noise. Resolved once per + # session and cached: defaultMode applies at startup, so editing it later + # cannot change the mode this session is actually in. + if [ -z "${defmode:-}" ]; then + defmode=${PHOBOS_STATUSLINE_MODE_DEFAULT:-} + if [ -z "$defmode" ]; then + # Settings precedence, most specific first. + for sf in "${pdir:-.}/.claude/settings.local.json" \ + "${pdir:-.}/.claude/settings.json" \ + "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/settings.json"; do + if [ -f "$sf" ]; then + defmode=$(jq -r '.permissions.defaultMode // empty' "$sf" 2>/dev/null) || defmode= + if [ -n "$defmode" ]; then break; fi + fi + done + fi + if [ -z "$defmode" ]; then defmode=default; fi + dirty=1 + fi + if [ "$tsize" -gt 0 ] && [ "$csize" != "$tsize" ]; then # Resume from the last known offset. With no cache — or after a rotation # shrank the file — bootstrap from the last 1MiB rather than the whole @@ -71,17 +97,23 @@ if [ "${PHOBOS_STATUSLINE_MODE:-1}" != 0 ] && [ -n "${tp:-}" ] && [ -f "$tp" ]; found=$(tail -c "+$from" "$tp" 2>/dev/null \ | grep -o '"permissionMode":"[A-Za-z]*"' | tail -n1 | cut -d'"' -f4) || found= if [ -n "${found:-}" ]; then permmode=$found; fi - printf '%s %s' "$tsize" "${permmode:-}" >"$mcache" 2>/dev/null || true + dirty=1 + fi + if [ "$dirty" = 1 ]; then + printf '%s|%s|%s' "$tsize" "${permmode:-}" "${defmode:-}" >"$mcache" 2>/dev/null || true + fi + + # Only when you have switched away from your default. `default` has no arm of + # its own either way. Colour escalates with how much is being skipped. + if [ "${permmode:-}" != "${defmode:-}" ]; then + case "${permmode:-}" in + plan) out+=" ${blue}[⏸ plan]${rst}" ;; + acceptEdits) out+=" ${green}[⏵ accept edits]${rst}" ;; + auto) out+=" ${yellow}[⏵⏵ auto]${rst}" ;; + bypassPermissions) out+=" ${red}[⏵⏵ bypass]${rst}" ;; + dontAsk) out+=" ${red}[⏵⏵ dont ask]${rst}" ;; + esac fi - # `default` renders nothing — it is the baseline, and Claude Code shows no - # indicator for it either. Colour escalates with how much is being skipped. - case "${permmode:-}" in - plan) out+=" ${blue}[⏸ plan]${rst}" ;; - acceptEdits) out+=" ${green}[⏵ accept edits]${rst}" ;; - auto) out+=" ${yellow}[⏵⏵ auto]${rst}" ;; - bypassPermissions) out+=" ${red}[⏵⏵ bypass]${rst}" ;; - dontAsk) out+=" ${red}[⏵⏵ dont ask]${rst}" ;; - esac fi # model · dir