ccs
CLAUDE.md4 starsChanged 9 months agoMITView on GitHub
npm package that installs a Node.js statusline script into ~/.claude/ and configures settings.json to display real-time usage stats (context %, session %, weekly %, cost). The npm layer is the installer — the actual work happens in scripts/statusline.js. There are no build steps and no linter configured. Smoke tests run via npm test (14 tests in scripts/smoke-test.js). prepublishOnly runs tests automatically before npm publish. bin/cli.js parses argv → dynamic-imports src/install.js, src/uninstall.js, or src/status.js. Install: src/check-deps.js (verifies Node >= 18) →…
- Reads credentials
- Commits and pushes
In this repository5 other files it gives its agents.
- clear-cacheSkill
- dev-installSkill
- statusline-checkSkill
- test-statuslineSkill
- verifySkill
The file
We split this CLAUDE.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 94
Do not create unnecessary files (CHANGELOG, CONTRIBUTING, etc.)
- Very specific: line 95
No hardcoded paths — use src/paths.js for all path constants
≈ “Common” is an estimate: at least 1 in 5 of the 28,029 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ccs-stats (ccs)
npm package that installs a Node.js statusline script into ~/.claude/ and configures settings.json to display real-time usage stats (context %, session %, weekly %, cost). The npm layer is the installer — the actual work happens in scripts/statusline.js.
Commands
# Test CLI locally
node bin/cli.js install
node bin/cli.js uninstall
node bin/cli.js status
# Test statusline.js directly with mock input
echo '{"model":{"display_name":"Opus 4"},"cost":{"total_cost_usd":0.5},"context_window":{"used_percentage":42},"workspace":{"current_dir":"/tmp/test"},"session_id":"dev"}' | node scripts/statusline.js
# Run smoke tests
npm test
# Dry-run npm publish check
npm pack --dry-run
# Publish to npm (runs npm test via prepublishOnly hook)
npm publish
# Release with full checklist (clean state, test, tag, publish)
bash scripts/release.shThere are no build steps and no linter configured. Smoke tests run via npm test (14 tests in scripts/smoke-test.js). prepublishOnly runs tests automatically before npm publish.
Architecture
- ES Modules (
"type": "module") — all.jsfiles useimport/export - Zero dependencies — only Node.js built-ins (fs, os, path, child_process, url)
- Cross-platform — macOS and Linux (verified); Windows experimental (credential access unverified)
Flow
bin/cli.js parses argv → dynamic-imports src/install.js, src/uninstall.js, or src/status.js.
Install: src/check-deps.js (verifies Node >= 18) → copies scripts/statusline.js to ~/.claude/statusline.js → cleans up old statusline.sh if present → settings.js merges statusLine key into ~/.claude/settings.json (with timestamped backup).
Test: scripts/smoke-test.js — runs statusline with 11 mock inputs (normal, null, empty, high, overflow, zero + git repo, dirty state, detached HEAD, non-git dir, nonexistent dir), verifies 2-line output and content (model name, cost format, progress bar chars); injects a mock cache file to test sess/week bar rendering; checks CLI help; ensures no console.log in statusline.js. All paths are __dirname-relative — safe to run from any cwd.
Release: scripts/release.sh — verifies clean git state → npm test → npm pack --dry-run → confirms version → npm publish (triggers prepublishOnly → tests again) → git tag → git push → git push --tags.
Uninstall: deletes the script → removes statusLine key from settings (with backup).
Status: checks if ~/.claude/statusline.js exists and settings.json has statusLine configured → reports ACTIVE, PARTIAL, or NOT INSTALLED.
Key Design Decisions
src/paths.jsusesimport.meta.urlto resolvescripts/statusline.jsrelative to the package, not cwdsettings.jsdoes shallow merge — only touches thestatusLinekey, preserves everything elsehasStatusLine()usesincludes('statusline.')for soft matching (tolerates.shand.jsvariants)- Install is idempotent: re-running updates the script but skips settings if already configured
settings.jsoncommand written asnode ~/.claude/statusline.jsstatusLineconfig includespadding: 2for multi-line output spacing- Install auto-cleans old
statusline.shfor backward compatibility getGitInfo()runsgit rev-parse+git status --porcelain --untracked-files=noper response; returnsnulloutside git repos (branch section hidden automatically)getGitInfo()detached HEAD falls back togit rev-parse --short HEAD(short commit hash)getGitInfo()allexecSynccalls havetimeout: 3000to prevent hangs on network-mounted paths- macOS
securitykeychain call also hastimeout: 3000— locked Keychain would otherwise block indefinitely path.basename(dir)used for folder extraction — cross-platform safe (replaces manual split)homedir()fromosused for credentials path — more reliable thanHOME/USERPROFILEenv chaingetOAuthToken()checksexpiresAton credentials — skips expired tokens rather than attempting a doomed API call- JSON.parse on stdin wrapped in try/catch with
{}fallback — safe against malformed input costcoerced withNumber()— preventstoFixed()crash if API sends cost as a stringfetchUsage()checksresp.okbefore callingresp.json()— non-2xx responses (401/403/500) returnnullsilentlyfetchUsage()prunes cache files older than 24h once per process (guarded by_pruneDoneflag) — prevents unbounded tmpdir growthbackup()insettings.jsis wrapped in try/catch at call sites — disk-full/permission errors log a warning instead of crashing installbin/cli.jsunknown commands printError: unknown command 'X'and exit 1 — help text only shown forhelp/--help/-h
statusline.js Input/Output
Input: JSON via stdin (provided by Claude Code) with fields: model.display_name, cost.total_cost_usd, context_window.used_percentage, workspace.current_dir, session_id.
Output: Two-line ANSI-colored text:
- Line 1:
[Model] 📁 folder | ✹branch | $cost— model (cyan), folder, git branch (green), dirty marker ✹ (purple, hidden when clean), session cost (yellow) - Line 2:
▓▓░░ ctx N% | sess: ▓▓░░ N% Xh | week: ▓▓░░ N% Xd— context + usage bars
Progress bars color-coded via colorForPct(): green (<70%), yellow (70-89%), red (>=90%).
Usage API: Fetches GET https://api.anthropic.com/api/oauth/usage with OAuth token from platform credential store, requires header anthropic-beta: oauth-2025-04-20.
Credential access: priority order: CLAUDE_CODE_OAUTH_TOKEN env var → ~/.claude/.credentials.json file (primary on Linux; present on macOS and Windows when available) → macOS Keychain (security, fallback since macOS deletes the file after login). Verified on macOS and Linux; Windows experimental.
Cache: Isolated per session at <tmpdir>/claude_usage_cache_<session_id>.json with 5-min TTL. Stale files older than 24h are pruned on each cache write. Null values have safe fallbacks (MODEL→"?", COST→0, USED_PCT→0).
Rules
- Conventional commits:
feat:,fix:,refactor:,docs:,chore:,test: - No
console.loginscripts/statusline.js— useprocess.stdout.write()instead - Do not create unnecessary files (CHANGELOG, CONTRIBUTING, etc.)
- No hardcoded paths — use
src/paths.jsfor all path constants
Gotchas
statusline.jsruns on every Claude Code response — keep it fast, no heavy computation- Usage data requires OAuth login (Pro/Max plan) — API key users see only context bar
fetch()requires Node >= 18 — this is whyengines.nodeis set to>=18- Cache files in
tmpdirare per-session — stale data across sessions is expected, not a bug hasStatusLine()soft-matchesstatusline.(not.js) to handle upgrades from old.shinstallsgetGitInfo()adds 2 synchronous git subprocess calls per response — keep surrounding logic minimal- Git branch dirty marker uses true-color ANSI (
\x1b[38;2;R;G;Bm) — requires a truecolor terminal; degrades silently otherwise
CI/CD
GitHub Actions workflows in .github/workflows/:
| Workflow | Trigger | What it does |
ci.yml | Push to main, PRs | Smoke tests + install/uninstall cycle on ubuntu + macOS (2 jobs); each job tests Node 18 → 20 → 22 sequentially |
publish.yml | Tag v* push | Run tests → verify package → npm publish --provenance (requires NPM_TOKEN secret, see setup guide) |
package-audit.yml | PRs | Verify package contents, zero-dep policy, and engine constraint |
Agents
Custom agents are available in .claude/agents/:
| Agent | Purpose |
senior-js-dev | Code writing, review, and refactoring — ES Modules, cross-platform, zero-dep focused |
senior-qa | Testing, edge cases, regression — read-only, reports PASS/FAIL with mock input scenarios |
Hooks
.claude/settings.json configures a PreToolUse hook via .claude/hooks/pre-commit-test.sh:
- Pre-commit test: Runs
npm testautomatically before everygit commit— commit is blocked if tests fail
Skills
Dev and user skills are available in .claude/skills/:
| Skill | Purpose |
/test-statusline [low|medium|high|null] | Test statusline.js with mock JSON input |
/dev-install [install|uninstall|status] | Quick CLI command runner for local dev |
/statusline-check | Health check + troubleshooting for installed statusline |
/clear-cache | Remove usage cache files from /tmp |
/verify | Full project verification — smoke tests, install/uninstall cycle, console.log check, npm pack --dry-run, no hardcoded paths |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

