Skip to content

(Claude) Session previews: skip leading YAML front matter - #355

Merged
cboos merged 2 commits into
mainfrom
dev/preview-frontmatter
Oct 8, 2026
Merged

cboos merged 2 commits into
mainfrom
dev/preview-frontmatter

Conversation

@cboos

@cboos cboos commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What

A session's preview is the first user message's label in the table of contents, the index cards and the TUI. When that message opened with YAML front matter (a pasted note, a skill or memory file), the preview showed the YAML block, starting with ---.

utils.create_session_preview now skips leading front matter, so the preview starts at the body. It uses the same detector as the rendering since #351 (frontmatter.split_frontmatter), so the two agree on what front matter is:

  • it counts only at the very start (after any system reminder, which the rendered text doesn't include);
  • it uses the same fences;
  • a --- followed by a blank line stays a horizontal rule, and the preview keeps it as before.

The detector is imported lazily, and only for text that starts with ---, so CLI start-up doesn't load PyYAML for it.

A message holding only front matter gives an empty preview. The next user message then supplies the preview, as it already does for any empty first message.

Accepted limitation: cached previews

The preview is also stored in the SQLite cache (first_user_message). This change adds no cache invalidation: no breaking_changes entry, no migration, no cache version change. A preview cached before this change keeps its front matter until that session is cached again. The case is rare, so it's accepted. New and re-cached sessions get the fixed preview.

Tests

test/test_session_preview_frontmatter.py:

  • create_session_preview skips front matter; front matter only gives an empty preview; front matter after a system reminder is skipped too. A leading horizontal rule, a --- block later in the text, and ordinary text are unchanged.
  • Through both producers of the stored and displayed preview, the cache's compute_session_data and the session navigation's _collect_session_info: a front-matter first message previews its body; a front-matter-only first message takes the next message's text; an ordinary session is unchanged.

The front-matter tests (7 of 11) fail without the change. No snapshot changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Session previews now omit recognized leading YAML front matter, including when it follows a system reminder. Front matter-only messages produce an empty preview, while ordinary text and unrecognized or non-leading front matter remain unchanged.
    • Session navigation uses the first message’s preview, falling back to the next user message when that preview is empty.

cboos and others added 2 commits October 8, 2026 00:37
A session's preview is the first user message's label in the table of
contents, the index cards and the TUI. For a message opening with
front matter, the preview showed the YAML block. It now starts at the
body, using the same detector the rendering uses. A `---` followed by
a blank line is still a horizontal rule and stays. A message holding
only front matter gives an empty preview, so the next user message
supplies it, as for any empty first message.

Previews already stored in the cache keep their front matter until the
session is cached again. There is no cache invalidation for this: the
case is rare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
utils is imported by nearly every module. A top-level import of the
detector loaded PyYAML and wenmode's front-matter plugin on every CLI
start: about +54 ms, or +23% on `import claude_code_log.cli`. It is now
imported inside create_session_preview, and only for text that starts
with `---`, as the other front-matter call sites do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9d2f24ea-fe38-4739-803b-1186aed9925b
📥 Commits

Reviewing files that changed from the base of the PR and between e5bea96 and e37a276.

📒 Files selected for processing (2)
  • claude_code_log/utils.py
  • test/test_session_preview_frontmatter.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Session previews now skip recognized leading YAML front matter after system reminders are removed. Tests cover preview content and verify that cached session data and session navigation use the expected first-user-message preview.

Changes

Session preview front matter

Layer / File(s) Summary
Preview handling and focused tests
claude_code_log/utils.py, test/test_session_preview_frontmatter.py
create_session_preview uses the stripped body when leading YAML front matter is recognized. Tests cover front matter, front-matter-only input, and content that remains unchanged.
Transcript preview validation
test/test_session_preview_frontmatter.py
Transcript tests check previews reported by cached session data and session navigation, including fallback behavior when the first preview is empty.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: daaain

Merge Risk: ⚪ Minimal · up to e37a2

The preview change appears mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: skipping leading YAML front matter in Claude session previews.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cboos
cboos merged commit 6ad6110 into main Oct 8, 2026
17 checks passed
@cboos
cboos deleted the dev/preview-frontmatter branch October 8, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant