Skip to content

iMessage: leading blank lines in streamed messages #5530

@micahbrich

Description

@micahbrich

Bug

Messages sent via iMessage sometimes arrive with leading blank lines at the top.

Root Cause

In the block streaming path, emitBlockChunk (pi-embedded-subscribe.js) strips thinking tags and calls .trimEnd() but not .trim(). When Claude's response starts after a stripped thinking block, leading \n\n survives through the entire pipeline:

  • sanitizeUserFacingText doesn't trim
  • normalizeStreamingText checks .trim() for skip logic but returns untrimmed text
  • deliverReplies (iMessage monitor) never trims
  • sendMessageIMessage passes text straight through

Suggested Fix

Simplest targeted fix — in sendMessageIMessage (imessage/send.js), add .trim() after markdown table conversion:

message = convertMarkdownTables(message, tableMode);
message = message.trim(); // <-- add this

Alternatively, changing .trimEnd() to .trim() in emitBlockChunk would fix it for all channels.

Environment

  • Clawdbot npm latest 2026.1.24-3
  • iMessage channel via imsg-plus
  • macOS 15.6 (arm64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions