statusline footer compresses on message re-render (terminal width cache missing)
Bug
The PAI statusline footer switches from normal mode (full sparklines) to mini mode (no sparklines) when Claude Code re-renders it after a message appears. The footer renders correctly at session start, then degrades on every subsequent re-render.
Root Cause
detect_terminal_width() in statusline-command.sh relies entirely on live TTY detection:
- Kitty IPC (
kitten @ ls) - Direct TTY query (
stty size </dev/tty) - tput fallback (
tput cols) - Environment variable (
${COLUMNS:-80})
Claude Code runs the statusLine command as a Node.js subprocess — without a controlling TTY. When all live detection tiers fail, it falls through to ${COLUMNS:-80}. If COLUMNS isn't exported in that subprocess environment, or if the terminal is slightly under 80 cols, the mode drops to mini — losing sparklines and compressing the footer.
Note on Tier 1 (Kitty IPC): This was reproduced on Kitty terminal. Tier 1 also failed to prevent the bug, suggesting KITTY_WINDOW_ID is not exported to Claude Code's statusLine subprocess environment.
Environment
- macOS
- Kitty terminal
- PAI v3.0
- Claude Code v2.1.50
Fix
Add a persistent width cache as a fallback tier between tput cols and ${COLUMNS:-80}. When any live detection tier succeeds, persist the value to a state file. On TTY-less subprocess re-renders, read from cache instead of guessing.
Add before the function definition:
TERM_WIDTH_CACHE="$PAI_DIR/MEMORY/STATE/terminal-width.txt"
In detect_terminal_width(), after Tier 3 (tput) and before Tier 4 (COLUMNS):
# Tier 4: Cached width from last successful detection (survives subprocess re-renders)
[ -z "$width" ] || [ "$width" = "0" ] || [ "$width" = "null" ] && \
[ -f "$TERM_WIDTH_CACHE" ] && width=$(cat "$TERM_WIDTH_CACHE" 2>/dev/null)
At the end of the function, before echo "$width":
# Persist successful detection to cache (only valid widths > 20)
if [ -n "$width" ] && [ "$width" != "0" ] && [ "$width" != "null" ] && [ "$width" -gt 20 ] 2>/dev/null; then
mkdir -p "$(dirname "$TERM_WIDTH_CACHE")" 2>/dev/null
echo "$width" > "$TERM_WIDTH_CACHE" 2>/dev/null
fi
Fix verified locally on PAI v3.0 / Kitty / macOS (terminal width: 147 cols). Session start correctly detects and caches the width; all subsequent subprocess re-renders read from cache and maintain normal mode.
Fixed in v4.0.2 — added a persistent width cache file (/tmp/pai-term-width-*) so that when the terminal width can't be detected on re-render, it uses the last known width instead of dropping to 80 and triggering mini mode. Thanks for the detailed report!