/statusline to have CodeBuddy Code help you set up a custom status line. By default, it attempts to replicate your terminal prompt, but you can provide CodeBuddy Code with additional instructions about the desired behavior, such as /statusline display the model name in orange.statusLine command directly in your .codebuddy/settings.json:{"statusLine": {"type": "command","command": "~/.codebuddy/statusline.sh","padding": 0 // Optional: Set to 0 to extend the status line to the edge}}
{"hook_event_name": "Status","session_id": "abc123...","transcript_path": "/path/to/transcript.json","cwd": "/current/working/directory","model": {"id": "gpt-5","display_name": "GPT-5"},"workspace": {"current_dir": "/current/working/directory","project_dir": "/original/project/directory"},"version": "2.9.0","output_style": {"name": "default"},"cost": {"total_cost_usd": 0.01234,"total_duration_ms": 45000,"total_api_duration_ms": 2300,"total_lines_added": 156,"total_lines_removed": 23}}
#!/bin/bash# Read JSON input from stdininput=$(cat)# Extract values with jqMODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}"
#!/bin/bash# Read JSON input from stdininput=$(cat)# Extract values with jqMODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')# Show the git branch if in a git repositoryGIT_BRANCH=""if git rev-parse --git-dir > /dev/null 2>&1; thenBRANCH=$(git branch --show-current 2>/dev/null)if [ -n "$BRANCH" ]; thenGIT_BRANCH=" | 🌿 $BRANCH"fifiecho "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}$GIT_BRANCH"
#!/bin/bash# Read JSON input from stdininput=$(cat)# Extract values with jqMODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')SESSION_ID=$(echo "$input" | jq -r '.session_id' | cut -c1-8)# ANSI Color CodesGREEN='\\033[0;32m'BLUE='\\033[0;34m'YELLOW='\\033[1;33m'NC='\\033[0m' # No color# Get the git branchGIT_BRANCH=""if git rev-parse --git-dir > /dev/null 2>&1; thenBRANCH=$(git branch --show-current 2>/dev/null)if [ -n "$BRANCH" ]; thenGIT_BRANCH=" ${GREEN}on${NC} ${YELLOW}$BRANCH${NC}"fifiecho -e "${BLUE}[$MODEL_DISPLAY]${NC} 📁 ${GREEN}${CURRENT_DIR##*/}${NC}$GIT_BRANCH ${BLUE}(${SESSION_ID})${NC}"
#!/bin/bash# Read JSON input from stdininput=$(cat)# Extract valuesMODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')TOTAL_COST=$(echo "$input" | jq -r '.cost.total_cost_usd')LINES_ADDED=$(echo "$input" | jq -r '.cost.total_lines_added')LINES_REMOVED=$(echo "$input" | jq -r '.cost.total_lines_removed')# Format costsCOST_STR=""if [ "$TOTAL_COST" != "null" ] && [ "$TOTAL_COST" != "0" ]; thenCOST_STR=$(printf " | 💰 \\$%.4f" "$TOTAL_COST")fi# Format code statisticsSTATS=""if [ "$LINES_ADDED" != "null" ] && [ "$LINES_ADDED" != "0" ]; thenSTATS=" | +$LINES_ADDED -$LINES_REMOVED"fiecho "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}$COST_STR$STATS"
#!/usr/bin/env python3import jsonimport sysimport osimport subprocess# Read JSON from stdindata = json.load(sys.stdin)# Extract valuesmodel = data['model']['display_name']current_dir = os.path.basename(data['workspace']['current_dir'])# Check the git branchgit_branch = ""try:branch = subprocess.check_output(['git', 'branch', '--show-current'],stderr=subprocess.DEVNULL).decode('utf-8').strip()if branch:git_branch = f" | 🌿 {branch}"except:pass# ANSI Color CodesBLUE = '\\033[0;34m'GREEN = '\\033[0;32m'NC = '\\033[0m'print(f"{BLUE}[{model}]{NC} 📁 {GREEN}{current_dir}{NC}{git_branch}")
#!/usr/bin/env nodeconst fs = require('fs');const path = require('path');const { execSync } = require('child_process');// Read JSON from stdinlet input = '';process.stdin.on('data', chunk => input += chunk);process.stdin.on('end', () => {const data = JSON.parse(input);// Extract valuesconst model = data.model.display_name;const currentDir = path.basename(data.workspace.current_dir);// Check the git branchlet gitBranch = '';try {const branch = execSync('git branch --show-current', {encoding: 'utf8',stdio: ['pipe', 'pipe', 'ignore']}).trim();if (branch) {gitBranch = ` | 🌿 ${branch}`;}} catch (e) {// Not a git repository or unable to read the branch}// ANSI colorsconst BLUE = '\\x1b[0;34m';const GREEN = '\\x1b[0;32m';const NC = '\\x1b[0m';console.log(`${BLUE}[${model}]${NC} 📁 ${GREEN}${currentDir}${NC}${gitBranch}`);});
#!/bin/bash# Read JSON input onceinput=$(cat)# Common Helper Functions for Extractionget_model_name() { echo "$input" | jq -r '.model.display_name'; }get_model_id() { echo "$input" | jq -r '.model.id'; }get_current_dir() { echo "$input" | jq -r '.workspace.current_dir'; }get_project_dir() { echo "$input" | jq -r '.workspace.project_dir'; }get_version() { echo "$input" | jq -r '.version'; }get_cost() { echo "$input" | jq -r '.cost.total_cost_usd'; }get_duration() { echo "$input" | jq -r '.cost.total_duration_ms'; }get_lines_added() { echo "$input" | jq -r '.cost.total_lines_added'; }get_lines_removed() { echo "$input" | jq -r '.cost.total_lines_removed'; }get_session_id() { echo "$input" | jq -r '.session_id'; }# Using Helper FunctionsMODEL=$(get_model_name)DIR=$(get_current_dir)COST=$(get_cost)# Format costsif [ "$COST" != "null" ] && [ "$COST" != "0" ]; thenCOST_DISPLAY=$(printf " | 💰 \\$%.4f" "$COST")elseCOST_DISPLAY=""fiecho "[$MODEL] 📁 ${DIR##*/}$COST_DISPLAY"
#!/bin/bash# ~/.codebuddy/statusline.sh# CodeBuddy Code Chinese Status Line Example# Read JSON input from stdininput=$(cat)# Extract basic informationMODEL=$(echo "$input" | jq -r '.model.display_name')CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')DIR_NAME=${CURRENT_DIR##*/}# ANSI colorsBLUE='\\033[0;34m'GREEN='\\033[0;32m'YELLOW='\\033[1;33m'CYAN='\\033[0;36m'NC='\\033[0m'# Git InformationGIT_INFO=""if git rev-parse --git-dir > /dev/null 2>&1; thenBRANCH=$(git branch --show-current 2>/dev/null)if [ -n "$BRANCH" ]; then# Check for uncommitted changesif ! git diff-index --quiet HEAD -- 2>/dev/null; thenSTATUS="*"elseSTATUS=""fiGIT_INFO=" ${GREEN}Branch${NC} ${YELLOW}$BRANCH$STATUS${NC}"fifi# Cost InformationCOST=$(echo "$input" | jq -r '.cost.total_cost_usd')COST_INFO=""if [ "$COST" != "null" ] && [ "$COST" != "0" ]; thenCOST_INFO=$(printf " ${CYAN}Cost${NC} \\$%.4f" "$COST")fi# Output the status lineecho -e "${BLUE}[$MODEL]${NC} 📁 ${GREEN}$DIR_NAME${NC}$GIT_INFO$COST_INFO"
#!/bin/bashinput=$(cat)MODEL=$(echo "$input" | jq -r '.model.display_name')DIR=$(echo "$input" | jq -r '.workspace.current_dir')DURATION_MS=$(echo "$input" | jq -r '.cost.total_duration_ms')# Format durationif [ "$DURATION_MS" != "null" ] && [ "$DURATION_MS" != "0" ]; thenDURATION_SEC=$((DURATION_MS / 1000))DURATION_MIN=$((DURATION_SEC / 60))DURATION_SEC=$((DURATION_SEC % 60))TIME_INFO=$(printf " | ⏱️ %dm%ds" "$DURATION_MIN" "$DURATION_SEC")elseTIME_INFO=""fi# Current timeCURRENT_TIME=$(date +"%H:%M:%S")echo "[$MODEL] 📁 ${DIR##*/}$TIME_INFO | 🕐 $CURRENT_TIME"
#!/bin/bashinput=$(cat)MODEL=$(echo "$input" | jq -r '.model.display_name')DIR=$(echo "$input" | jq -r '.workspace.current_dir')COST=$(echo "$input" | jq -r '.cost.total_cost_usd')# Color definitionsGREEN='\\033[0;32m'YELLOW='\\033[1;33m'RED='\\033[0;31m'NC='\\033[0m'# Select a color based on costif [ "$COST" != "null" ]; thenif (( $(echo "$COST < 0.01" | bc -l) )); thenCOST_COLOR=$GREENelif (( $(echo "$COST < 0.1" | bc -l) )); thenCOST_COLOR=$YELLOWelseCOST_COLOR=$REDfiCOST_DISPLAY=$(printf "${COST_COLOR}\\$%.4f${NC}" "$COST")elseCOST_DISPLAY=""fiecho -e "[$MODEL] 📁 ${DIR##*/} | 💰 $COST_DISPLAY"
jq in Bash for JSON parsing (see the example above).echo '{"model":{"display_name":"test"},"workspace":{"current_dir":"/test"}}' | ./statusline.sh
# Text colorsBLACK='\\033[0;30m'RED='\\033[0;31m'GREEN='\\033[0;32m'YELLOW='\\033[0;33m'BLUE='\\033[0;34m'PURPLE='\\033[0;35m'CYAN='\\033[0;36m'WHITE='\\033[0;37m'# Bold colorsBOLD_BLACK='\\033[1;30m'BOLD_RED='\\033[1;31m'BOLD_GREEN='\\033[1;32m'BOLD_YELLOW='\\033[1;33m'BOLD_BLUE='\\033[1;34m'BOLD_PURPLE='\\033[1;35m'BOLD_CYAN='\\033[1;36m'BOLD_WHITE='\\033[1;37m'# Background colorsBG_BLACK='\\033[40m'BG_RED='\\033[41m'BG_GREEN='\\033[42m'BG_YELLOW='\\033[43m'BG_BLUE='\\033[44m'BG_PURPLE='\\033[45m'BG_CYAN='\\033[46m'BG_WHITE='\\033[47m'# ResetNC='\\033[0m' # No Color
chmod +x ~/.codebuddy/statusline.shecho '{}' | ~/.codebuddy/statusline.shexport LANG=zh_CN.UTF-8echo -e to interpret escape sequences..git directory.~/.codebuddy/settings.json:{"statusLine": {"type": "command","command": "~/.codebuddy/statusline.sh","padding": 0}}
.codebuddy/settings.json:{"statusLine": {"type": "command","command": "./.codebuddy/statusline.sh"}}
# macOSbrew install jq bc# Ubuntu/Debiansudo apt-get install jq bc# CentOS/RHELsudo yum install jq bc
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback