Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.3.2] — 2026-06-06

### Fixed
- Topic no longer shows the literal `Error: Reached max turns 1` when MCP servers are configured. The async `claude -p` refinement now runs with `--strict-mcp-config` and no tools, so the single allowed turn can't be consumed by a tool call. The call also uses `--output-format json` and only accepts `.result` when `is_error` is false, with a guard that discards any leftover CLI error string so the heuristic topic is kept instead.

## [5.2.4] — 2026-06-01

### Docs
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alexismunozdev/claude-session-topics",
"version": "5.3.1",
"version": "5.3.2",
"description": "Session topics for Claude Code — auto-set and display a topic in the statusline, change anytime with /set-topic",
"bin": {
"claude-session-topics": "bin/install.js"
Expand Down
20 changes: 18 additions & 2 deletions scripts/user-prompt-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,27 @@ refine_topic() {
full_prompt=$(printf '%s\n\nConversación:\n%s' "$instruction" "$context")

local refined out_file="${TOPIC_FILE}.refine.$$"
# --strict-mcp-config + --allowedTools "" load zero MCP servers and no tools,
# so the model can't burn the single turn on a tool call (which would make the
# CLI emit "Error: Reached max turns 1" to stdout and get written as the topic).
# --output-format json lets us accept the result only when is_error is false.
printf '%s' "$full_prompt" | CLAUDE_SESSION_TOPICS_SKIP=1 \
run_with_timeout 30 claude -p --model haiku --max-turns 1 >"$out_file" 2>/dev/null || true
refined=$(tr -d '\r' < "$out_file" 2>/dev/null | grep -v '^[[:space:]]*$' | head -n 1 || true)
run_with_timeout 30 claude -p --model haiku --max-turns 1 \
--strict-mcp-config --allowedTools "" --output-format json >"$out_file" 2>/dev/null || true
if command -v jq >/dev/null 2>&1; then
refined=$(jq -r 'select(.is_error == false) | .result // empty' "$out_file" 2>/dev/null \
| grep -v '^[[:space:]]*$' | head -n 1 || true)
else
refined=$(tr -d '\r' < "$out_file" 2>/dev/null | grep -v '^[[:space:]]*$' | head -n 1 || true)
fi
rm -f "$out_file"

# Guard: never let a CLI error string become the topic (belt-and-suspenders for
# the jq-less path or unexpected error formats).
case "$refined" in
Error:*|*"Reached max turns"*|*"Execution error"*) refined="" ;;
esac

# Sanitize: strip quotes, trim, whitelist chars, truncate
refined=$(printf '%s' "$refined" \
| sed -E 's/^[[:space:]"'"'"'`]+//;s/[[:space:]"'"'"'`.,:;!?]+$//' \
Expand Down
2 changes: 1 addition & 1 deletion skills/set-topic/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: set-topic
description: Set or change the session topic displayed in the statusline
argument-hint: <topic text>
allowed-tools: [Bash]
version: "5.3.1"
version: "5.3.2"
---

Set the session topic to: $ARGUMENTS
Expand Down
Loading