Skip to content

Commit 27dfc97

Browse files
committed
claude statusline
1 parent 7425d1c commit 27dfc97

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

ai/claude/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"model": "opus[1m]",
3+
"statusLine": {
4+
"type": "command",
5+
"command": "node ~/.claude/statusline.js"
6+
}
7+
}

ai/claude/statusline.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('node:fs');
4+
const { execSync } = require('node:child_process');
5+
6+
const CLAUDE_DUMB_ZONE = 59;
7+
8+
function getGitBranch() {
9+
try {
10+
return execSync('git branch --show-current 2>/dev/null', { encoding: 'utf-8' }).trim();
11+
} catch {
12+
return '';
13+
}
14+
}
15+
16+
function ansi(text, bgColor, color = 'rgb(255, 255, 255)') {
17+
const RESET = '\x1b[0m';
18+
const bgColorValues = bgColor.match(/\d+/g);
19+
const bgColorAnsi = `\x1b[48;2;${bgColorValues.join(';')}m`;
20+
const colorValues = color.match(/\d+/g);
21+
const colorAnsi = `\x1b[38;2;${colorValues.join(';')}m`;
22+
return `${RESET}${bgColorAnsi}${colorAnsi}${text}${RESET}`;
23+
}
24+
25+
function formatSections(sections) {
26+
27+
const LEFT_ROUND = '\ue0b6';
28+
const RIGHT_ARROW = '\ue0b0';
29+
const RIGHT_ROUND = '\ue0b4';
30+
31+
const coloredSections = sections.map((section, index) => {
32+
const { text, bgColor, color } = section;
33+
const coloredSection = ansi(` ${text} `, bgColor, color);
34+
35+
// First section does not need a leading right arrow
36+
if (index === 0) {
37+
return coloredSection;
38+
}
39+
40+
const prevBgColor = sections[index - 1].bgColor;
41+
const prefix = `${ansi(RIGHT_ARROW, bgColor, prevBgColor)}`;
42+
return prefix + coloredSection;
43+
});
44+
45+
return [
46+
`${ansi(LEFT_ROUND, 'rgb(0,0,0)', sections.at(0).bgColor)}`,
47+
...coloredSections,
48+
`${ansi(RIGHT_ROUND, 'rgb(0,0,0)', sections.at(-1).bgColor)}`,
49+
].join('');
50+
}
51+
52+
try {
53+
const sections = [];
54+
55+
// Read data from Claude Code stdin
56+
const input = JSON.parse(fs.readFileSync(0, 'utf-8'));
57+
58+
const cwd = input.workspace.current_dir;
59+
const dirName = cwd.split('/').at(-1);
60+
sections.push({ text: dirName, bgColor: "rgb(52, 86, 164)" });
61+
62+
const branch = getGitBranch();
63+
if (branch) {
64+
sections.push({ text: branch, bgColor: "rgb(70, 107, 62)" });
65+
}
66+
67+
const model = input.model.display_name;
68+
sections.push({ text: model, bgColor: "rgb(68, 68, 68)" });
69+
70+
// Context window usage
71+
const contextWindow = input.context_window;
72+
73+
if (contextWindow?.current_usage && contextWindow?.context_window_size) {
74+
const usage = contextWindow.current_usage;
75+
const currentTokens = (usage.input_tokens || 0) +
76+
(usage.output_tokens || 0) +
77+
(usage.cache_creation_input_tokens || 0) +
78+
(usage.cache_read_input_tokens || 0);
79+
const contextSize = contextWindow.context_window_size;
80+
const percent = Math.round((currentTokens / contextSize) * 100);
81+
const isDumbZone = percent > CLAUDE_DUMB_ZONE;
82+
const bgColor = isDumbZone ? "rgb(226, 0, 0)" : "rgb(217, 119, 87)";
83+
const color = isDumbZone ? "rgb(255, 255, 255)" : "rgb(0, 0, 0)";
84+
sections.push({ text: `${percent}%`, bgColor, color });
85+
}
86+
87+
console.log(formatSections(sections));
88+
} catch (error) {
89+
console.error('Error:', error.message);
90+
process.exit(1);
91+
}

git/ignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.vscode
2+
3+
**/.claude/settings.local.json

install.conf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
~/.config/kitty/kitty.conf: kitty/kitty.conf
1111
~/.config/nvim/init.vim: vim/.vimrc
1212
~/.claude/CLAUDE.md: ai/AGENTS.md
13+
~/.claude/statusline.js: ai/claude/statusline.js
14+
~/.claude/settings.json: ai/claude/settings.json
1315
~/.cmake-format.yaml: cmake-format/.cmake-format.yaml
1416
~/.config/Code/User/settings.json: vscode/settings.json
1517
~/AGENTS.md: ai/AGENTS.md

0 commit comments

Comments
 (0)