将Claude Code的会话标题总结改为中文
- 内容介绍
- 文章标签
- 相关推荐
最近从ghostty换成了cmux,侧边栏显示每个会话的标题切换起来很方便,但是默认总结的都是英文,看起来不是很方便,于是查了下实际是有内置系统提示词的默认输出几个英文单词,可以通过patch将他改成输出中文
直接命令行执行即可,仅支持npm安装方式
f="$(npm root -g)/@anthropic-ai/claude-code/cli.js"; cp -n "$f" "$f.bak"; python3 - "$f" <<'PY'
from pathlib import Path
import re, sys
p = Path(sys.argv[1])
s = p.read_text()
pat = re.compile(r'''Generate a concise, sentence-case title \(3-7 words\) that captures the main topic or goal of this coding session\. The title should be clear enough that the user recognizes the session in a list\. Use sentence case: capitalize only the first word and proper nouns\.
Return JSON with a single "title" field\.
Good examples:
\{"title": "Fix login button on mobile"\}
\{"title": "Add OAuth authentication"\}
\{"title": "Debug failing CI tests"\}
\{"title": "Refactor API client error handling"\}
Bad \(too vague\): \{"title": "Code changes"\}
Bad \(too long\): \{"title": "Investigate and fix the issue where the login button does not respond on mobile devices"\}
Bad \(wrong case\): \{"title": "Fix Login Button On Mobile"\}''', re.S)
new = '''用中文生成一个简洁的标题(8-15字),概括这次编程会话的主要目标或主题。标题应足够清晰,让用户在列表中一眼识别该会话。
用JSON格式回复,只包含一个 "title" 字段。
好的例子:
{"title": "修复移动端登录按钮无响应"}
{"title": "添加 OAuth 认证功能"}
{"title": "调试 CI 测试失败问题"}
{"title": "重构 API 客户端错误处理"}
太模糊: {"title": "改代码"}
太长: {"title": "调查并修复移动设备上登录按钮在某些情况下点击后没有任何响应的问题以及相关联的样式错乱"}
格式错误: {"title": "修复 移动端 登录 按钮"}'''
s2, n = pat.subn(new, s, count=1)
if n != 1:
raise SystemExit(f"replace failed: matched {n} blocks")
p.write_text(s2)
PY
rg -n -C 1 '用中文生成一个简洁的标题|Generate a concise, sentence-case title' "$f"
网友解答:
--【壹】--:
感谢大佬
最近从ghostty换成了cmux,侧边栏显示每个会话的标题切换起来很方便,但是默认总结的都是英文,看起来不是很方便,于是查了下实际是有内置系统提示词的默认输出几个英文单词,可以通过patch将他改成输出中文
直接命令行执行即可,仅支持npm安装方式
f="$(npm root -g)/@anthropic-ai/claude-code/cli.js"; cp -n "$f" "$f.bak"; python3 - "$f" <<'PY'
from pathlib import Path
import re, sys
p = Path(sys.argv[1])
s = p.read_text()
pat = re.compile(r'''Generate a concise, sentence-case title \(3-7 words\) that captures the main topic or goal of this coding session\. The title should be clear enough that the user recognizes the session in a list\. Use sentence case: capitalize only the first word and proper nouns\.
Return JSON with a single "title" field\.
Good examples:
\{"title": "Fix login button on mobile"\}
\{"title": "Add OAuth authentication"\}
\{"title": "Debug failing CI tests"\}
\{"title": "Refactor API client error handling"\}
Bad \(too vague\): \{"title": "Code changes"\}
Bad \(too long\): \{"title": "Investigate and fix the issue where the login button does not respond on mobile devices"\}
Bad \(wrong case\): \{"title": "Fix Login Button On Mobile"\}''', re.S)
new = '''用中文生成一个简洁的标题(8-15字),概括这次编程会话的主要目标或主题。标题应足够清晰,让用户在列表中一眼识别该会话。
用JSON格式回复,只包含一个 "title" 字段。
好的例子:
{"title": "修复移动端登录按钮无响应"}
{"title": "添加 OAuth 认证功能"}
{"title": "调试 CI 测试失败问题"}
{"title": "重构 API 客户端错误处理"}
太模糊: {"title": "改代码"}
太长: {"title": "调查并修复移动设备上登录按钮在某些情况下点击后没有任何响应的问题以及相关联的样式错乱"}
格式错误: {"title": "修复 移动端 登录 按钮"}'''
s2, n = pat.subn(new, s, count=1)
if n != 1:
raise SystemExit(f"replace failed: matched {n} blocks")
p.write_text(s2)
PY
rg -n -C 1 '用中文生成一个简洁的标题|Generate a concise, sentence-case title' "$f"
网友解答:
--【壹】--:
感谢大佬

