diff --git a/plugins/README.md b/plugins/README.md index cf4a21ecc5..eca44b2a60 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -25,6 +25,7 @@ Learn more in the [official plugins documentation](https://docs.claude.com/en/do | [pr-review-toolkit](./pr-review-toolkit/) | Comprehensive PR review agents specializing in comments, tests, error handling, type design, code quality, and code simplification | **Command:** `/pr-review-toolkit:review-pr` - Run with optional review aspects (comments, tests, errors, types, code, simplify, all)
**Agents:** `comment-analyzer`, `pr-test-analyzer`, `silent-failure-hunter`, `type-design-analyzer`, `code-reviewer`, `code-simplifier` | | [ralph-wiggum](./ralph-wiggum/) | Interactive self-referential AI loops for iterative development. Claude works on the same task repeatedly until completion | **Commands:** `/ralph-loop`, `/cancel-ralph` - Start/stop autonomous iteration loops
**Hook:** Stop - Intercepts exit attempts to continue iteration | | [security-guidance](./security-guidance/) | Security reminder hook that warns about potential security issues when editing files | **Hook:** PreToolUse - Monitors 9 security patterns including command injection, XSS, eval usage, dangerous HTML, pickle deserialization, and os.system calls | +| [session-rename](./session-rename/) | Rename sessions for easier identification in `/resume` | **Command:** `/rename` - Set a custom title for the current session via `.meta.json` sidecar files | ## Installation diff --git a/plugins/session-rename/.claude-plugin/plugin.json b/plugins/session-rename/.claude-plugin/plugin.json new file mode 100644 index 0000000000..2894bb4c60 --- /dev/null +++ b/plugins/session-rename/.claude-plugin/plugin.json @@ -0,0 +1,9 @@ +{ + "name": "session-rename", + "description": "Rename Claude Code sessions for easier identification in /resume", + "version": "1.0.0", + "author": { + "name": "Anthropic", + "email": "support@anthropic.com" + } +} diff --git a/plugins/session-rename/README.md b/plugins/session-rename/README.md new file mode 100644 index 0000000000..ff76c010fb --- /dev/null +++ b/plugins/session-rename/README.md @@ -0,0 +1,55 @@ +# Session Rename Plugin + +Rename Claude Code sessions for easier identification when using `/resume`. + +## Problem + +Claude Code sessions are auto-named based on date and context (e.g., "Mar 24 – Analyst meta"), but there is no way to rename them. When working on multiple tasks, sessions accumulate with generic names, making it hard to find past conversations. + +See [#38173](https://github.com/anthropics/claude-code/issues/38173) for the full feature request. + +## Commands + +### `/rename ` + +Renames the current session by creating a `.meta.json` sidecar file alongside the session's `.jsonl` file. + +**Usage:** +``` +/rename Fix authentication bug +/rename Sprint 47 planning +/rename +``` + +If called without arguments, prompts for a name interactively. + +## How It Works + +1. Locates the current session's `.jsonl` file in `~/.claude/projects/{encodedPath}/` +2. Creates or updates a `{sessionId}.meta.json` file with the structure: + ```json + { + "title": "User-provided session name", + "renamed_at": "2026-03-24T09:00:00Z", + "auto_title": null + } + ``` +3. The `.jsonl` file is never modified — the metadata file is a non-breaking sidecar + +## Integration Path + +This plugin establishes a `.meta.json` convention that the core CLI can adopt to: +- Display custom titles in `/resume` session picker +- Show renamed sessions in the session list UI +- Preserve backward compatibility (fall back to auto-generated title when no `.meta.json` exists) + +## Installation + +Add to your project's `.claude/settings.json`: +```json +{ + "plugins": ["session-rename"] +} +``` + +Or install from the plugins directory in this repository. diff --git a/plugins/session-rename/commands/rename.md b/plugins/session-rename/commands/rename.md new file mode 100644 index 0000000000..201eb66388 --- /dev/null +++ b/plugins/session-rename/commands/rename.md @@ -0,0 +1,66 @@ +--- +description: Rename the current session for easier identification in /resume +argument-hint: +allowed-tools: Bash(ls:*), Bash(cat:*), Bash(echo:*), Bash(mkdir:*), Bash(python3:*), Bash(date:*), Read, Write +--- + +# Rename Current Session + +Rename the current Claude Code session by writing a metadata file alongside the session JSONL. + +## Your Task + +The user wants to rename this session to: `$ARGUMENTS` + +**If $ARGUMENTS is empty**, ask the user what they'd like to name this session using AskUserQuestion. Do not proceed until you have a name. + +**If $ARGUMENTS is provided**, rename the session: + +1. Determine the current session's storage path. The session JSONL file is located at: + ``` + ~/.claude/projects/{encodedProjectPath}/{sessionId}.jsonl + ``` + where `{encodedProjectPath}` is the current working directory with `/` replaced by `-` and `{sessionId}` is a UUID. + + To find the correct file, run: + ```bash + ls -t ~/.claude/projects/*/ 2>/dev/null | grep "\.jsonl$" | head -20 + ``` + Then identify the session file that corresponds to the current project path by checking which project directory matches the current working directory. + + A more reliable approach: use `python3` to find the session file for the current project: + ```python + import os, glob, json + cwd = os.getcwd() + encoded = cwd.replace("/", "-") + project_dir = os.path.expanduser(f"~/.claude/projects/{encoded}") + # List .jsonl files sorted by modification time (newest first) + jsonl_files = sorted( + glob.glob(os.path.join(project_dir, "*.jsonl")), + key=os.path.getmtime, reverse=True + ) + # The most recently modified session is likely the current one + if jsonl_files: + print(jsonl_files[0]) + ``` + +2. Write a `{sessionId}.meta.json` file in the same directory as the `.jsonl` file: + ```json + { + "title": "", + "renamed_at": "", + "auto_title": null + } + ``` + + If a `.meta.json` already exists, read it first and update only the `title` and `renamed_at` fields, preserving any other fields. + +3. Confirm the rename to the user with a brief message like: + ``` + Session renamed to "". + Metadata saved to: ~/.claude/projects/.../{sessionId}.meta.json + ``` + +**Important**: Do not modify the `.jsonl` file itself. The metadata file is a sidecar that can be read by future versions of Claude Code or by other plugins. + +You MUST complete this in a single message with tool calls. Do not send any other text besides the confirmation.