Skip to content

Filter <local-command-caveat>-wrapped caveat messages (Claude Code ≥ ~2.1)#269

Merged
daaain merged 2 commits into
mainfrom
fix/wrapped-caveat-detection
Jul 7, 2026
Merged

Filter <local-command-caveat>-wrapped caveat messages (Claude Code ≥ ~2.1)#269
daaain merged 2 commits into
mainfrom
fix/wrapped-caveat-detection

Conversation

@daaain

@daaain daaain commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Newer Claude Code versions wrap the local-command caveat in a XML tag instead of emitting the bare "Caveat: ..." text, so is_system_message() stopped matching it. The wrapped caveat then leaked into session previews / page titles (showing as the "first message" of any session that opens with a slash command) and rendered as a slash-command message in transcripts. It also promoted command-only sessions (e.g. a lone /model invocation) into the session index, which previously had no eligible first user message and were skipped.

Match the tag prefix in is_system_message and bump the cache compatibility floor so caches with the caveat baked into first_user_message rebuild on upgrade.

Summary by CodeRabbit

  • Bug Fixes
    • Improved message filtering so caveat messages wrapped in special tags are now correctly treated as system messages, excluding them from conversation previews and generated output while keeping regular quoted text intact.
  • Documentation
    • Added clearer notes about cache compatibility behavior for older versions.
  • Tests
    • Added coverage to verify wrapped caveat filtering and ensure surrounding normal messages are still rendered.

…~2.1)

Newer Claude Code versions wrap the local-command caveat in a
<local-command-caveat> XML tag instead of emitting the bare
"Caveat: ..." text, so is_system_message() stopped matching it.
The wrapped caveat then leaked into session previews / page titles
(showing as the "first message" of any session that opens with a
slash command) and rendered as a slash-command message in
transcripts. It also promoted command-only sessions (e.g. a lone
/model invocation) into the session index, which previously had no
eligible first user message and were skipped.

Match the tag prefix in is_system_message and bump the cache
compatibility floor so caches with the caveat baked into
first_user_message rebuild on upgrade.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 641c123b-2226-499e-8b86-03d3ad785af4

📥 Commits

Reviewing files that changed from the base of the PR and between e3e6e59 and b0e057d.

📒 Files selected for processing (1)
  • claude_code_log/cache.py
✅ Files skipped from review due to trivial changes (1)
  • claude_code_log/cache.py

📝 Walkthrough

Walkthrough

This PR extends system message filtering to recognize caveat text wrapped in <local-command-caveat> XML tags, treats it like bare caveat text, adds a related cache comment, and adds tests covering session preview selection and rendered HTML filtering.

Changes

Wrapped Caveat Filtering

Layer / File(s) Summary
Caveat filtering logic and cache comment
claude_code_log/factories/system_factory.py, claude_code_log/cache.py
is_system_message() now matches caveats wrapped in <local-command-caveat> tags; the cache compatibility comment for "1.4.0" is expanded to describe older first_user_message caveat-text behavior.
Wrapped caveat test coverage
test/test_message_filtering.py
Adds should_use_as_session_starter import and test_wrapped_caveat_message_filtering, covering wrapped caveat detection, session preview exclusion, and HTML filtering.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: filtering -wrapped caveat messages in newer Claude Code versions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wrapped-caveat-detection

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.

@daaain daaain merged commit e76e1a6 into main Jul 7, 2026
17 checks passed
Comment thread claude_code_log/cache.py
# (Claude Code ≥ ~2.1) from session previews: caches built
# earlier have the caveat text baked into first_user_message
# for affected sessions.
"1.4.0": "1.5.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see 1.5.0 is brewing ;-)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised we should have done it ages ago 😅 should probably cut a release once a week after every few PRs!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cboos also wanted to email you about publishing to PyPI, but the address on your Github profile bounced my email. Mine is working, please drop me a message!

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.

2 participants