Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 18 additions & 6 deletions scripts/context-bar.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/bash

# 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)"
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
COLOR="blue"
Expand All @@ -24,8 +36,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
Expand Down Expand Up @@ -95,17 +107,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
Expand Down Expand Up @@ -182,7 +194,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
Expand Down