Skip to content

Instantly share code, notes, and snippets.

@intrd
Last active December 10, 2025 12:21
Show Gist options
  • Select an option

  • Save intrd/fdbe8efb1a75dbaf0142b2e82cd21abe to your computer and use it in GitHub Desktop.

Select an option

Save intrd/fdbe8efb1a75dbaf0142b2e82cd21abe to your computer and use it in GitHub Desktop.
Simple one-shot script to extract Claude Code "Plan usage limits" using tmux
#!/usr/bin/env bash
## Simple one-shot script to extract Claude Code "Plan usage limits" using tmux.
# Author: intrd@dann.com.br
# Tags: claude, quota
SESSION="claude-usage-$$"
# Start Claude Code in a detached tmux session
tmux new-session -d -s "$SESSION" 'claude'
# Wait for Claude Code UI to fully load (look for the title line)
for i in {1..10}; do
tmux capture-pane -pt "$SESSION" | grep -q "Claude Code" && break
sleep 0.5
done
# Send `/usage` command to open the Usage tab
tmux send-keys -t "$SESSION" -l "/usage"
tmux send-keys -t "$SESSION" Enter
sleep 0.3
tmux send-keys -t "$SESSION" Enter
# Wait until the Usage screen is visible (look for "Current session")
for i in {1..7}; do
tmux capture-pane -pt "$SESSION" | grep -q "Current session" && break
sleep 0.5
done
# Give the UI a bit more time to render completely
sleep 2
# Capture tmux pane contents and strip ANSI color codes
panel=$(
tmux capture-pane -pt "$SESSION" -S -1000 \
| sed -E 's/\x1b\[[0-9;]*m//g'
)
# Cleanly stop Claude Code and remove the tmux session
tmux send-keys -t "$SESSION" C-c
sleep 0.5
tmux kill-session -t "$SESSION"
# ---- PARSING ----
# First and second "% used" values
session_used=$(
printf '%s\n' "$panel" \
| grep '% used' \
| sed -n '1s/.*\([0-9]\+% used\).*/\1/p'
)
week_used=$(
printf '%s\n' "$panel" \
| grep '% used' \
| sed -n '2s/.*\([0-9]\+% used\).*/\1/p'
)
# First and second "Resets ..." lines
session_reset=$(
printf '%s\n' "$panel" \
| grep '^ Resets ' \
| sed -n '1s/^ *//p'
)
week_reset=$(
printf '%s\n' "$panel" \
| grep '^ Resets ' \
| sed -n '2s/^ *//p'
)
# ---- OUTPUT ----
# echo "Current session : $session_used | $session_reset"
# echo "Current week : $week_used | $week_reset"
# ---- SIMPLE ONE-LINE OUTPUT ----
echo "${session_used%%% *} ~ $(echo "${session_reset#Resets }" | sed 's/ (.*)//') | ${week_used%%% *} ~ $(echo "${week_reset#Resets }" | sed 's/ (.*)//')"
$ ./claude-usage.sh
Current session : 2% used | Resets 11am (America/Sao_Paulo)
Current week : 5% used | Resets Dec 15, 11pm (America/Sao_Paulo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment