Dynamic Tmux Window Naming with Claude Code

on Dragoș Străinu's blog

When working with Claude Code in tmux, I wanted a way to automatically update my window names based on what I’m currently working on. Instead of manually renaming windows or having generic names, I set up Claude Code to dynamically update the window name as I switch between tasks.

The Setup

The goal was to have Claude Code automatically rename the tmux window with:

Examples:

Step 1: Custom Instructions

First, I created a custom instructions file that Claude Code reads on startup:

mkdir -p ~/.claude

Create ~/.claude/instructions.md:

# Tmux Window Management

When running inside a tmux session, automatically manage the window name:

- Always use "claude-" prefix followed by 2-3 words separated by dashes
- Update the window name ONLY when the topic changes significantly:
  - After `/clear` command is used
  - When starting a new task or issue
  - When making significant progress on a task
  - When switching between different work contexts
- Use the command: `tmux rename-window "name-here"`
- Do it silently without announcing the rename to the user
- Keep names concise and descriptive of the current work

Initial name: "claude-code"

Step 2: Auto-Approve Tmux Commands

Claude Code has a permission system that prompts for approval before running bash commands. To make the window renaming seamless, I needed to auto-approve tmux rename-window commands using a PreToolUse hook.

Create ~/.claude/approve-tmux.py:

#!/usr/bin/env python3
import json
import sys

def main():
    # Read the hook input from stdin
    hook_input = json.loads(sys.stdin.read())

    # Check if this is a Bash tool use
    if hook_input.get("tool") == "Bash":
        command = hook_input.get("parameters", {}).get("command", "")

        # Auto-approve tmux rename-window commands
        if command.startswith("tmux rename-window"):
            response = {
                "hookSpecificOutput": {
                    "hookEventName": "PreToolUse",
                    "permissionDecision": "allow",
                    "permissionDecisionReason": "Tmux rename-window auto-approved"
                }
            }
            print(json.dumps(response))
            return

    # For all other commands, no decision (normal flow)
    print("{}")

if __name__ == "__main__":
    main()

Make it executable:

chmod +x ~/.claude/approve-tmux.py

Step 3: Configure the Hook

Update ~/.claude/settings.json to add the PreToolUse hook:

{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/approve-tmux.py"
          }
        ]
      }
    ]
  }
}

How It Works

Once configured, Claude Code will:

  1. Read the instructions on startup and understand its role in managing tmux window names
  2. Monitor task changes during the session
  3. When a significant topic change occurs, run tmux rename-window with an appropriate name
  4. The PreToolUse hook intercepts the bash command and auto-approves it
  5. The window name updates seamlessly without any user prompts

Result

Now my tmux status bar always shows what Claude Code is currently helping me with. It’s especially useful when running multiple tmux sessions - I can quickly identify which window has Claude Code and what it’s working on.

The window names update naturally as I work:

This small automation makes tmux window management effortless and gives me better context awareness across my terminal sessions.

Liked this post? Follow me @strdr4605 to get more updates.