which-claude-code
🔧 Maintained, analyzed, and integrated by Elisha Ng'etich
GitHub: https://github.com/Kipkiruie
🚀 Overview
which-claude-code is a developer productivity plugin for Claude Code that automatically generates context-aware session titles and assigns unique visual identifiers to each session.
When working with multiple Claude Code sessions across different terminals, it becomes difficult to track context. This tool solves that by automatically summarizing your active task and displaying it directly in the CLI statusline.
🎯 Use Case
This tool is especially useful for developers who:
- Work with multiple AI-assisted coding sessions simultaneously
- Debug different features in parallel
- Need fast visual context switching across terminal tabs
It eliminates confusion and improves workflow efficiency in complex development environments.
✨ Key Features
-
🧠 Automatic Session Titles
Generates concise 3–6 word summaries using Claude Haiku after each prompt
-
🎨 Color-Coded Sessions
Each session gets a unique, stable color derived from its session ID
-
⚡ Non-blocking Execution
Runs asynchronously (~10ms overhead) without delaying user prompts
-
🔒 Recursion-Safe Architecture
Multiple safeguards prevent infinite subprocess spawning
-
🧩 Seamless CLI Integration
Works natively with Claude Code plugin system
📸 Example Output
● Fix Autopublish Double-Publish Bug · Opus 4.7 · project-x (main)
● Refactor Dashboard Credits Panel · Opus 4.7 · project-x (dash-credits)
● Ship WhatsApp Alert Routing · Opus 4.7 · project-x (wa-routing)
📌 Add a screenshot in assets/demo.png to visually demonstrate this in your environment.
🧰 Tech Stack
- Bash / Shell scripting
- Claude CLI (
claude -p)
- JSON configuration
- Unix process management
- CLI plugin architecture
⚙️ Installation
1. Add marketplace and install plugin
/plugin marketplace add jbarbier/which-claude-code
/plugin install which-claude-code@jbarbier
2. Restart Claude Code and configure
/which-claude-code:setup
3. Restart Claude Code again
The statusline is loaded at startup, so a final restart is required.
🧠 How It Works
1. Prompt Hook (UserPromptSubmit)
- Captures user prompt input
- Stores a limited session history (max 5 lines × 200 chars)
- Sends request to Claude Haiku
- Generates a short descriptive title
- Writes result to a per-session file
2. Statusline Renderer
- Reads the generated session title
- Displays:
● <title> · <model> · <cwd> (<branch>)
- Applies consistent color using:
cksum(session_id)
This ensures:
- Same session → same color
- Different sessions → visually distinct
🛡️ Recursion Safety Design
Hooks that invoke claude -p can cause infinite recursion if not handled properly.
This project implements six independent safeguards:
| Guard | Purpose |
|---|
| Env-var flag | Prevents child processes from re-triggering hooks |
| Content marker | Detects and blocks recursive prompt generation |
| Atomic lock | Prevents concurrent executions |
| Rate limiting | Enforces minimum delay between executions |
| Bounded history | Limits memory and disk usage |
| Safe failure | Timeout + no retries + controlled logging |
These protections prevent:
- runaway processes
- disk explosion
- token exhaustion
🧪 Testing
Run test suite:
bash tests/run.sh
Manual validation includes:
- process monitoring
- filesystem growth checks
- prompt history validation
- session title updates
💰 Cost
- Uses
claude -p --model haiku
- ~200–500 tokens per prompt
- Negligible usage under normal workflows
🧩 Requirements
- Claude Code 2.x
claude CLI on $PATH
jq
- Unix tools (
awk, sed, cksum)
- Linux / macOS (or WSL)
🔧 My Contributions & Learning
While working with this project, I:
- Configured and deployed the plugin in a real development setup
- Analyzed the UserPromptSubmit hook lifecycle
- Studied and validated recursion prevention strategies
- Explored shell-based plugin architecture and CLI integrations
- Integrated the tool into a multi-session development workflow
Skills Strengthened
- Debugging system-level CLI issues
- Managing asynchronous shell processes
- Designing safe automation workflows
- Understanding real-world developer tooling
🚀 Future Improvements
- Customizable statusline themes
- Toggle session title generation
- UI preview for generated titles
- Session analytics and logging dashboard
🔧 Troubleshooting
Logs and state are stored in:
~/.claude/which-claude-code/
Key files: