{"slug": "you-can-use-ruby-to-set-the-status-line-in-claude-code", "title": "You can use Ruby to set the status line in Claude Code", "summary": "Claude Code's status line can be configured to run a Ruby script, as demonstrated by developer Lucian Ghinda, who shared a setup using a `statusLine` command in `settings.json` to display context window usage, git branch, and current directory. The script reads JSON session data from stdin and outputs a formatted string, with an optional `refreshInterval` for more frequent updates. Ghinda warns that forking git processes can cause timeouts on large repositories.", "body_md": "Claude Code can run executables to show the status line, and, of course, that executable can be a Ruby script.\n\nHere is the simple setup to do that:\n\n```\n{\n  \"statusLine\": {\n    \"type\": \"command\",\n    \"command\": \"/Users/lucianghinda/.claude/statusline.rb\"\n  }\n}\n```\n\n`statusLine`\n\nis a top-level setting and sits on the same level as `permissions`\n\nand `hooks`\n\n. If you want to apply it to all projects, put that configuration in `~/.claude/settings.json`\n\n.\n\nThe script that you specify there should be marked as executable with `chmod +x`\n\n, and it should include this at the top of the file:\n\n``` bash\n#!/usr/bin/env ruby\n```\n\nI have not yet tested whether I can remove that shebang instruction and change the “command” argument to `ruby /Users/lucianghinda/.claude/statusline.rb`\n\n. I would assume it could work but have not yet tested it.\n\nThe status line behaves like a filter: Claude sends a [JSON session data](https://code.claude.com/docs/en/statusline#full-json-schema) to a script that you set up there and expects to get back a string, which will be displayed as the status line.\n\nThe flow looks like this:\n\nThere is also an optional `refreshInterval`\n\nthat can rerun the command more often if you like.\n\nYou can find the list of events that will trigger a status line update at [How status lines work](https://code.claude.com/docs/en/statusline#how-status-lines-work).\n\nHere is the script that I used (that Claude generated for me when asked):\n\n``` python\ndef compact(tokens)\n  return tokens.to_s if tokens < 1_000\n  return format('%.1fk', tokens / 1_000.0).sub('.0k', 'k') if tokens < 1_000_000\n\n  format('%.2fM', tokens / 1_000_000.0).sub('.00M', 'M')\nend\n\ndef color_for(percent)\n  return RED if percent >= 80\n  return YELLOW if percent >= 50\n\n  GREEN\nend\n\ndef git_branch(cwd)\n  branch = `cd #{cwd.shellescape} && git -c core.fileMode=false rev-parse --abbrev-ref HEAD 2>/dev/null`.strip\n  branch.empty? ? 'no-git' : branch\nend\n\ndef context_segment(window)\n  return nil unless window\n\n  used    = window['total_input_tokens'].to_i\n  size    = window['context_window_size'].to_i\n  percent = window['used_percentage']\n  percent = (size.positive? ? (used.to_f / size * 100).round : 0) if percent.nil?\n\n  label = \"ctx #{compact(used)}/#{compact(size)}\"\n  \"#{label} #{color_for(percent)}#{percent}%#{RESET}#{DIM}\"\nend\n\ninput = begin\n  JSON.parse($stdin.read)\nrescue StandardError\n  {}\nend\ncwd   = input.dig('workspace', 'current_dir') || input['cwd'] || Dir.pwd\n\nparts = [File.basename(cwd), git_branch(cwd)]\nparts << context_segment(input['context_window'])\n\nputs \"#{DIM}#{parts.compact.join(' | ')}#{RESET}\"\n```\n\nIn my case, I want to pay attention only to the context window, and that is the most important piece of information added there.\n\nYou can test the script by doing something like this:\n\n```\necho '{\"workspace\":{\"current_dir\":\"/Users/lucianghinda/.claude\"},\"context_window\":{\"total_input_tokens\":123456,\"context_window_size\":1000000}}' | ~/.claude/statusline.rb\n```\n\nOutput should be:\n\n```\n.claude | no-git | ctx 123.5k/1M 12%\n```\n\nMy current script checks git with `rev-parse`\n\n, which forks a process each time it runs. For a normal repository, that should return quickly, but in case of a slow network or a more complex repository with many objects in Git, it can take longer, and Claude will time out on the command and not display anything in the status line.", "url": "https://wpnews.pro/news/you-can-use-ruby-to-set-the-status-line-in-claude-code", "canonical_source": "https://allaboutcoding.ghinda.com/you-can-use-ruby-to-set-the-status-line-in-claude-code/", "published_at": "2026-08-19 10:41:40+00:00", "updated_at": "2026-08-21 20:44:16.493666+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools"], "entities": ["Claude Code", "Lucian Ghinda", "Ruby", "JSON"], "alternates": {"html": "https://wpnews.pro/news/you-can-use-ruby-to-set-the-status-line-in-claude-code", "markdown": "https://wpnews.pro/news/you-can-use-ruby-to-set-the-status-line-in-claude-code.md", "text": "https://wpnews.pro/news/you-can-use-ruby-to-set-the-status-line-in-claude-code.txt", "jsonld": "https://wpnews.pro/news/you-can-use-ruby-to-set-the-status-line-in-claude-code.jsonld"}}