Skip to main content

Directory Display

The directory feature shows your current working directory with intelligent home path abbreviation.

How It Works

cc-statusline extracts the current directory from Claude Code’s JSON input and automatically abbreviates your home directory to ~:
# Full path
/Users/yourname/Projects/my-app

# Displayed as
πŸ“ ~/Projects/my-app

Implementation Details

When jq is available, directory extraction is fast and reliable:
current_dir=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // "unknown"' 2>/dev/null | sed "s|^$HOME|~|g")
This looks for:
  1. workspace.current_dir (primary location)
  2. cwd (fallback)
  3. "unknown" (if both fail)

Display Code

From bash-generator.ts:220:
printf 'πŸ“ %s%s%s' "$(dir_color)" "$current_dir" "$(rst)"
The directory is displayed with:
  • πŸ“ folder emoji
  • Sky blue color (ANSI 38;5;117)
  • Color reset after text

Git Integration

The git feature displays your current branch name with automatic detection of git repositories.

Features

Branch Detection

Automatically detects and displays current git branch

Fallback to SHA

Shows short commit SHA in detached HEAD state

Safe Execution

Gracefully handles non-git directories

Performance

Minimal overhead with fast git commands

Configuration

From cli/prompts.ts:26:
{ name: '🌿 Git Branch', value: 'git', checked: true }
The git feature is enabled by default during installation.

Implementation

From features/git.ts:21-25:
export function generateGitBashCode(config: GitFeature, colors: boolean): string {
  return `${colorCode}
# ---- git ----
git_branch=""
if git rev-parse --git-dir >/dev/null 2>&1; then
  git_branch=$(git branch --show-current 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
fi`
}
  1. Check if in git repo: git rev-parse --git-dir >/dev/null 2>&1
    • Silently checks for .git directory
    • Returns exit code 0 if in a git repository
  2. Get branch name: git branch --show-current
    • Gets the current branch name (e.g., main, feature/new-feature)
    • Fails in detached HEAD state
  3. Fallback to commit SHA: git rev-parse --short HEAD
    • If branch detection fails, show short commit hash
    • Useful in detached HEAD state or CI/CD environments

Display Code

From features/git.ts:28-39:
export function generateGitDisplayCode(config: GitFeature, colors: boolean, emojis: boolean): string {
  const branchEmoji = emojis ? '🌿' : 'git:'

  let displayCode = `
# git display
if [ -n "$git_branch" ]; then
  printf '  ${branchEmoji} %s%s%s' "$(git_color)" "$git_branch" "$(rst)"
fi`
  
  return displayCode
}
Branch information is displayed with:
  • 🌿 branch emoji (or git: prefix if emojis disabled)
  • Soft green color (ANSI 38;5;150)
  • Only shown if branch was detected

Example Outputs

# On a feature branch
πŸ“ ~/my-project  🌿 feature/add-statusline

# On main branch
πŸ“ ~/my-project  🌿 main

# Detached HEAD state (showing commit SHA)
πŸ“ ~/my-project  🌿 a3f9c2b

# Not in a git repository
πŸ“ ~/my-project

Color Customization

From features/git.ts:11-18:
const colorCode = colors ? `
# ---- git colors ----
git_color() { if [ "$use_color" -eq 1 ]; then printf '\\033[38;5;150m'; fi; }  # soft green
rst() { if [ "$use_color" -eq 1 ]; then printf '\\033[0m'; fi; }
` : `
git_color() { :; }
rst() { :; }
`
Colors respect the NO_COLOR environment variable. Set NO_COLOR=1 to disable all colors.

Requirements

FeatureRequirementFallback Behavior
DirectoryNone (always works)Shows β€œunknown” if extraction fails
Git Branchgit installedBranch not displayed if git unavailable
ColorsTerminal with ANSI supportPlain text if colors disabled

Performance Notes

Both features are extremely lightweight:
  • Directory: Simple string extraction and replacement (~1ms)
  • Git: Single git command with short-circuit logic (~5-15ms)
  • Total overhead: Less than 20ms combined
Git commands are only executed if the repository check succeeds, minimizing overhead in non-git directories.

Troubleshooting

This can happen if:
  • Claude Code JSON format has changed
  • jq is not installed (install jq for more reliable parsing)
  • There’s an issue with the workspace path
Solution: Install jq and restart Claude Code.
Check if:
  • You’re in a git repository: git status
  • Git is installed: git --version
  • The script has execute permissions: chmod +x .claude/statusline.sh
Solution: Initialize a git repo with git init or ensure git is in your PATH.
Windows paths with backslashes are automatically converted to forward slashes:
# Windows path: C:\Users\name\project
# Displayed as: C:/Users/name/project
This is handled by the sed replacement in the bash fallback parser.

Next Steps

Context Tracking

Monitor your context window usage

Customization

Customize colors and themes

Build docs developers (and LLMs) love