fix: detect Claude Code 2.1+ session title requests for optimization skip

Expand is_title_generation_request to match sentence-case/JSON title prompts
in addition to legacy new-conversation-topic copy. Add unit test for the
current session-title system text shape.
This commit is contained in:
Alishahryar1 2026-04-25 00:44:25 -07:00
parent 2df42c1846
commit 080ebefc7b
2 changed files with 28 additions and 1 deletions

View file

@ -31,11 +31,24 @@ def is_title_generation_request(request_data: MessagesRequest) -> bool:
Title generation requests are detected by a system prompt containing
title extraction instructions, no tools, and a single user message.
Matches both legacy phrasing and Claude Code 2.1+ session title prompts
(JSON \"title\" field, sentence-case title instructions, etc.).
"""
if not request_data.system or request_data.tools:
return False
system_text = extract_text_from_content(request_data.system).lower()
return "new conversation topic" in system_text and "title" in system_text
if "title" not in system_text:
return False
return (
"new conversation topic" in system_text
or "sentence-case title" in system_text
or (
"return json" in system_text
and "field" in system_text
and ("coding session" in system_text or "this session" in system_text)
)
)
def is_prefix_detection_request(request_data: MessagesRequest) -> tuple[bool, str]: