tencent cloud

Status Line Configuration

Download
Focus Mode
Font Size
Last updated: 2026-09-30 18:15:49
AI-Translated

Overview

Make CodeBuddy Code more personalized with a custom status line, which is displayed at the bottom of the CodeBuddy Code interface, similar to how terminal prompts (PS1) work in shells such as Oh-my-zsh.

Creating a Custom Status Line

You can choose one of the following methods:
Run /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.
Add the 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
}
}

How It Works

The status line is updated when conversation messages are updated.
Updates run at most once every 300 ms.
The first line of stdout from the command output becomes the status line text.
ANSI color codes are supported for styling the status line.
CodeBuddy Code passes contextual information about the current session (model, directory, and so on) to your script via stdin in JSON format.

JSON Input Structure

Your status line command receives structured data in JSON format via stdin:
{
"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
}
}

Sample Script

Simple Status Line

#!/bin/bash
# Read JSON input from stdin
input=$(cat)

# Extract values with jq
MODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')
CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')

echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}"

Git-Aware Status Line

#!/bin/bash
# Read JSON input from stdin
input=$(cat)

# Extract values with jq
MODEL_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 repository
GIT_BRANCH=""
if git rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git branch --show-current 2>/dev/null)
if [ -n "$BRANCH" ]; then
GIT_BRANCH=" | 🌿 $BRANCH"
fi
fi

echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}$GIT_BRANCH"

Chinese Status Line with Colors

#!/bin/bash
# Read JSON input from stdin
input=$(cat)

# Extract values with jq
MODEL_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 Codes
GREEN='\\033[0;32m'
BLUE='\\033[0;34m'
YELLOW='\\033[1;33m'
NC='\\033[0m' # No color

# Get the git branch
GIT_BRANCH=""
if git rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git branch --show-current 2>/dev/null)
if [ -n "$BRANCH" ]; then
GIT_BRANCH=" ${GREEN}on${NC} ${YELLOW}$BRANCH${NC}"
fi
fi

echo -e "${BLUE}[$MODEL_DISPLAY]${NC} 📁 ${GREEN}${CURRENT_DIR##*/}${NC}$GIT_BRANCH ${BLUE}(${SESSION_ID})${NC}"

Displaying Cost and Statistics

#!/bin/bash
# Read JSON input from stdin
input=$(cat)

# Extract values
MODEL_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 costs
COST_STR=""
if [ "$TOTAL_COST" != "null" ] && [ "$TOTAL_COST" != "0" ]; then
COST_STR=$(printf " | 💰 \\$%.4f" "$TOTAL_COST")
fi

# Format code statistics
STATS=""
if [ "$LINES_ADDED" != "null" ] && [ "$LINES_ADDED" != "0" ]; then
STATS=" | +$LINES_ADDED -$LINES_REMOVED"
fi

echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}$COST_STR$STATS"

Python Example

#!/usr/bin/env python3
import json
import sys
import os
import subprocess

# Read JSON from stdin
data = json.load(sys.stdin)

# Extract values
model = data['model']['display_name']
current_dir = os.path.basename(data['workspace']['current_dir'])

# Check the git branch
git_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 Codes
BLUE = '\\033[0;34m'
GREEN = '\\033[0;32m'
NC = '\\033[0m'

print(f"{BLUE}[{model}]{NC} 📁 {GREEN}{current_dir}{NC}{git_branch}")

Node.js Example

#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Read JSON from stdin
let input = '';
process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', () => {
const data = JSON.parse(input);
// Extract values
const model = data.model.display_name;
const currentDir = path.basename(data.workspace.current_dir);
// Check the git branch
let 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 colors
const BLUE = '\\x1b[0;34m';
const GREEN = '\\x1b[0;32m';
const NC = '\\x1b[0m';
console.log(`${BLUE}[${model}]${NC} 📁 ${GREEN}${currentDir}${NC}${gitBranch}`);
});

Helper Function Methods

For more complex bash scripts, you can create helper functions:
#!/bin/bash
# Read JSON input once
input=$(cat)

# Common Helper Functions for Extraction
get_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 Functions
MODEL=$(get_model_name)
DIR=$(get_current_dir)
COST=$(get_cost)

# Format costs
if [ "$COST" != "null" ] && [ "$COST" != "0" ]; then
COST_DISPLAY=$(printf " | 💰 \\$%.4f" "$COST")
else
COST_DISPLAY=""
fi

echo "[$MODEL] 📁 ${DIR##*/}$COST_DISPLAY"

Complete Chinese Example

#!/bin/bash
# ~/.codebuddy/statusline.sh
# CodeBuddy Code Chinese Status Line Example

# Read JSON input from stdin
input=$(cat)

# Extract basic information
MODEL=$(echo "$input" | jq -r '.model.display_name')
CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')
DIR_NAME=${CURRENT_DIR##*/}

# ANSI colors
BLUE='\\033[0;34m'
GREEN='\\033[0;32m'
YELLOW='\\033[1;33m'
CYAN='\\033[0;36m'
NC='\\033[0m'

# Git Information
GIT_INFO=""
if git rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git branch --show-current 2>/dev/null)
if [ -n "$BRANCH" ]; then
# Check for uncommitted changes
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
STATUS="*"
else
STATUS=""
fi
GIT_INFO=" ${GREEN}Branch${NC} ${YELLOW}$BRANCH$STATUS${NC}"
fi
fi

# Cost Information
COST=$(echo "$input" | jq -r '.cost.total_cost_usd')
COST_INFO=""
if [ "$COST" != "null" ] && [ "$COST" != "0" ]; then
COST_INFO=$(printf " ${CYAN}Cost${NC} \\$%.4f" "$COST")
fi

# Output the status line
echo -e "${BLUE}[$MODEL]${NC} 📁 ${GREEN}$DIR_NAME${NC}$GIT_INFO$COST_INFO"

Advanced Example

Displaying Current Time and Session Duration

#!/bin/bash
input=$(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 duration
if [ "$DURATION_MS" != "null" ] && [ "$DURATION_MS" != "0" ]; then
DURATION_SEC=$((DURATION_MS / 1000))
DURATION_MIN=$((DURATION_SEC / 60))
DURATION_SEC=$((DURATION_SEC % 60))
TIME_INFO=$(printf " | ⏱️ %dm%ds" "$DURATION_MIN" "$DURATION_SEC")
else
TIME_INFO=""
fi

# Current time
CURRENT_TIME=$(date +"%H:%M:%S")

echo "[$MODEL] 📁 ${DIR##*/}$TIME_INFO | 🕐 $CURRENT_TIME"

Displaying Different Colors Based on Cost

#!/bin/bash
input=$(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 definitions
GREEN='\\033[0;32m'
YELLOW='\\033[1;33m'
RED='\\033[0;31m'
NC='\\033[0m'

# Select a color based on cost
if [ "$COST" != "null" ]; then
if (( $(echo "$COST < 0.01" | bc -l) )); then
COST_COLOR=$GREEN
elif (( $(echo "$COST < 0.1" | bc -l) )); then
COST_COLOR=$YELLOW
else
COST_COLOR=$RED
fi
COST_DISPLAY=$(printf "${COST_COLOR}\\$%.4f${NC}" "$COST")
else
COST_DISPLAY=""
fi

echo -e "[$MODEL] 📁 ${DIR##*/} | 💰 $COST_DISPLAY"

Note

Keep the status line concise - it should fit on a single line.
Use emoji (if your terminal supports them) and colors to make the information easy to scan.
Use jq in Bash for JSON parsing (see the example above).
Test your script by manually running it with mock JSON input:
echo '{"model":{"display_name":"test"},"workspace":{"current_dir":"/test"}}' | ./statusline.sh
Consider caching expensive operations (such as git status) if necessary.
Ensure that the script output is valid UTF-8 to display Chinese characters and emoji correctly.

Common ANSI Color Codes

# Text colors
BLACK='\\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 colors
BOLD_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 colors
BG_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'

# Reset
NC='\\033[0m' # No Color

Troubleshooting

Status Line Not Displayed

Check whether the script is executable: chmod +x ~/.codebuddy/statusline.sh
Ensure that the script outputs to stdout (not stderr).
Verify that the JSON path is correct: echo '{}' | ~/.codebuddy/statusline.sh

Garbled Chinese or emoji Display

Ensure that the terminal supports UTF-8 encoding.
Check that the script file is saved in UTF-8 format.
Add the following at the beginning of the script: export LANG=zh_CN.UTF-8

Colors Not Displayed

Check whether the terminal supports ANSI colors.
Ensure that you use echo -e to interpret escape sequences.
Verify that the color codes are correct.

Git Information Not Displayed

Ensure that you run it in a git repository.
Check whether the git command is in the PATH.
Verify that you have permission to read the .git directory.

Slow Script Execution

Cache expensive operations (such as git status).
Avoid making network requests in status line scripts.
Update the cached information using a background process.

Configuration Example

User-Level Configuration

In ~/.codebuddy/settings.json:
{
"statusLine": {
"type": "command",
"command": "~/.codebuddy/statusline.sh",
"padding": 0
}
}

Project-Level Configuration

In .codebuddy/settings.json:
{
"statusLine": {
"type": "command",
"command": "./.codebuddy/statusline.sh"
}
}
This allows different projects to use different status line styles.

Recommended Utilities

jq: a required JSON parsing tool.
bc: used for floating-point calculations (cost comparison).
git: displays branch and status information.
date: displays time information.

Installation

# macOS
brew install jq bc

# Ubuntu/Debian
sudo apt-get install jq bc

# CentOS/RHEL
sudo yum install jq bc

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback