Project Overview
cc-statusline is a TypeScript CLI tool that generates custom statuslines for Claude Code. It creates optimized bash scripts that display directory, git info, model name, usage costs, and session time in the terminal.Architecture Overview
The codebase follows a modular ESM TypeScript architecture with four distinct layers:CLI Layer (src/cli/)
Purpose: User interaction and command handling
- Commander.js-based CLI interface
- Interactive prompts using Inquirer
- Command registration and argument parsing
- User preference collection
commands.ts- CLI command definitionsprompts.ts- Interactive configuration prompts
Generator Layer (src/generators/)
Purpose: Bash script generation based on user configuration
- Template-based bash code generation
- Feature flag-driven conditional sections
- Optimized output with only selected features
- POSIX-compliant script generation
bash-generator.ts- Main bash script generator (src/generators/bash-generator.ts:9)
Feature Modules (src/features/)
Purpose: Isolated implementations for specific statusline features
- Git: Branch detection and status display
- Usage Tracking: Cost and token statistics via ccusage
- Colors: 256-color palette support for terminals
Utility Layer (src/utils/)
Purpose: Supporting functionality for installation and testing
- Installation utilities
- Validation helpers
- Mock testing support
Key Design Patterns
Feature Flags
Feature flags determine which bash code blocks are included in generated scripts:Template-Based Generation
All bash generation uses TypeScript template strings with conditional sections:Mock Testing
The preview command simulates Claude Code’s JSON input for testing:- Generates realistic mock data
- Tests statusline output before installation
- Validates performance metrics
- No Claude Code instance required
Build System
Technology: tsup for ESM bundling Configuration:- Target: Node 16+
- Module format: ESM
- Automatic shebang insertion (
#!/usr/bin/env node) - Source maps for debugging
Generated Scripts
Characteristics
- Self-contained: No external dependencies required
- Fast: Execute in <100ms with minimal resource usage
- Graceful fallbacks: Work without jq, git, or ccusage
- POSIX-compliant: Compatible with sh, bash, zsh
Fallback Strategy
Scripts include multiple layers of fallbacks:- JSON Parsing: jq → bash fallback parser
- Git Integration: git command → skip git features
- Usage Tracking: ccusage → skip usage features
Installation Flow
The installation process follows these steps:- Collect Preferences: Interactive inquirer prompts for features, theme, colors
- Generate Script: Create optimized bash script with only selected features
- Write File: Save to
.claude/statusline.shwith execute permissions - Update Settings: Modify
.claude/settings.jsonto register statusline command
Critical Implementation Details
JSON Parsing in Bash
Thebash-generator.ts file contains a fallback JSON parser for systems without jq (src/generators/bash-generator.ts:88-121):
Quote Escaping
Critical: Lines 100-105 in bash-generator.ts contain grep patterns requiring double escaping:- TypeScript template literal needs
\\for a single backslash - Bash needs
\"for escaped quotes - Combined:
\\"\\${field}\\"produces"${field}"in final bash script
Module System
ESM Conventions
- Use ESM imports with
.jsextensions (even for.tsfiles) - No CommonJS require statements
- Top-level await supported
Performance Characteristics
| Metric | Target | Typical |
|---|---|---|
| Execution Time | <100ms | 45-80ms |
| Memory Usage | <5MB | ~2MB |
| CPU Impact | Negligible | <1% |
| Dependencies | Minimal | jq only |
Security Considerations
- No network requests: Except ccusage integration via npx
- Local file access: Only reads Claude Code JSON input
- Secure defaults: Scripts execute with user permissions only
- No data collection: Zero telemetry or analytics
Code Conventions
- Indentation: 2 spaces
- Semicolons: Not used (follows project style)
- Typing: Strict TypeScript with explicit types
- Commits: Conventional Commits format
Next Steps
Bash Generation
Learn how bash scripts are generated
Testing
Run tests and validate changes