From c75ac36254beca2aee9df26ec976aa6f5214e530 Mon Sep 17 00:00:00 2001 From: hx3333 <258051722@qq.com> Date: Mon, 16 Mar 2026 21:51:31 +0800 Subject: [PATCH 1/2] Add Windows compatibility to context-bar.sh - Use jq.exe from the same directory as the script - Fixes issue where jq is not in PATH on Windows --- scripts/context-bar.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/context-bar.sh b/scripts/context-bar.sh index df23550..16d4b03 100755 --- a/scripts/context-bar.sh +++ b/scripts/context-bar.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Use jq.exe from the same directory (Windows compatibility) +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +JQ="${SCRIPT_DIR}/jq.exe" + # Color theme: gray, orange, blue, teal, green, lavender, rose, gold, slate, cyan # Preview colors with: bash scripts/color-preview.sh COLOR="blue" @@ -24,8 +28,8 @@ esac input=$(cat) # Extract model, directory, and cwd -model=$(echo "$input" | jq -r '.model.display_name // .model.id // "?"') -cwd=$(echo "$input" | jq -r '.cwd // empty') +model=$(echo "$input" | "$JQ" -r '.model.display_name // .model.id // "?"') +cwd=$(echo "$input" | "$JQ" -r '.cwd // empty') dir=$(basename "$cwd" 2>/dev/null || echo "?") # Get git branch, uncommitted file count, and sync status @@ -95,17 +99,17 @@ if [[ -n "$cwd" && -d "$cwd" ]]; then fi # Get transcript path for context calculation and last message feature -transcript_path=$(echo "$input" | jq -r '.transcript_path // empty') +transcript_path=$(echo "$input" | "$JQ" -r '.transcript_path // empty') # Get context window size from JSON (accurate), but calculate tokens from transcript # (more accurate than total_input_tokens which excludes system prompt/tools/memory) # See: github.com/anthropics/claude-code/issues/13652 -max_context=$(echo "$input" | jq -r '.context_window.context_window_size // 200000') +max_context=$(echo "$input" | "$JQ" -r '.context_window.context_window_size // 200000') max_k=$((max_context / 1000)) # Calculate context bar from transcript if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then - context_length=$(jq -s ' + context_length=$("$JQ" -s ' map(select(.message.usage and .isSidechain != true and .isApiErrorMessage != true)) | last | if . then @@ -182,7 +186,7 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then [[ -n "$branch" ]] && plain_output+=" | 🔀${branch} ${git_status}" plain_output+=" | xxxxxxxxxx ${pct}% of ${max_k}k tokens" max_len=${#plain_output} - last_user_msg=$(jq -rs ' + last_user_msg=$("$JQ" -rs ' # Messages to skip (not useful as context) def is_unhelpful: startswith("[Request interrupted") or From 55f67f259448d53a74b02e82279ae9ea458bc850 Mon Sep 17 00:00:00 2001 From: hx3333 <258051722@qq.com> Date: Mon, 16 Mar 2026 23:31:02 +0800 Subject: [PATCH 2/2] Add Windows support for context-bar.sh (fixes #5) Changes: - Detect Windows (Git Bash/MSYS2) via OSTYPE and MSYSTEM env vars - Use jq.exe from script directory on Windows - Use system jq on Linux/Mac (backward compatible) - Add Windows setup instructions to README Co-Authored-By: Claude Sonnet 4.6 --- scripts/README.md | 16 ++++++++++++++++ scripts/context-bar.sh | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index d1417b0..5a7db7f 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -51,6 +51,22 @@ Preview all options by running `bash scripts/color-preview.sh`: - `git` (optional, for branch display) - Claude Code 2.0.65+ (verified to work; older versions may not have the required JSON fields - check earlier commits for older versions) +### Windows Support + +On Windows (Git Bash/MSYS2), the script automatically uses `jq.exe` from the same directory. To set up: + +1. Download `jq.exe` from [jqlang.github.io/jq](https://jqlang.github.io/jq/download/) or [GitHub releases](https://github.com/jqlang/jq/releases) +2. Place `jq.exe` in `~/.claude/scripts/` alongside `context-bar.sh` +3. Use Windows-style path in `settings.json`: + ```json + { + "statusLine": { + "type": "command", + "command": "C:/Users/USERNAME/.claude/scripts/context-bar.sh" + } + } + ``` + ### How it works Claude Code passes session metadata to status line commands via stdin as JSON, including: diff --git a/scripts/context-bar.sh b/scripts/context-bar.sh index 16d4b03..cddfff3 100755 --- a/scripts/context-bar.sh +++ b/scripts/context-bar.sh @@ -1,8 +1,16 @@ #!/bin/bash -# Use jq.exe from the same directory (Windows compatibility) +# Cross-platform jq detection (Windows compatibility) +# On Windows (Git Bash/MSYS), use jq.exe from the same directory +# On Linux/Mac, use system jq SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -JQ="${SCRIPT_DIR}/jq.exe" +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || -n "$MSYSTEM" ]]; then + # Windows (Git Bash/MSYS2) + JQ="${SCRIPT_DIR}/jq.exe" +else + # Linux/Mac - use system jq + JQ="jq" +fi # Color theme: gray, orange, blue, teal, green, lavender, rose, gold, slate, cyan # Preview colors with: bash scripts/color-preview.sh