MCP comment tool escapes ! in HTML comments, making markers visible
Bug
When using mcp__github_comment__update_claude_comment to post a comment containing an HTML comment marker like <!-- claude-code-review -->, the ! character gets escaped to \!, resulting in <\!-- claude-code-review --> being stored in the comment body.
Since <\!-- is not valid HTML comment syntax, GitHub renders it as visible text instead of hiding it.
Reproduction
- Configure a workflow that uses
claude-code-actionwith a prompt instructing Claude to include<!-- some-marker -->in a comment body viamcp__github_comment__update_claude_comment - Trigger the workflow
- Observe the posted comment contains
<\!-- some-marker -->(with\!)
Expected behavior
The HTML comment <!-- some-marker --> should be posted verbatim, so GitHub hides it as intended.
Actual behavior
The ! is escaped to \!, producing <\!-- some-marker --> which renders as visible text.
Root cause
This is likely bash history expansion escaping the ! character when the comment body passes through a shell context with double quotes. In bash, ! triggers history expansion inside double-quoted strings and gets escaped to \!.
Example
- PR: https://github.com/shellhub-io/shellhub/pull/5868
- Comment with the issue: https://github.com/shellhub-io/shellhub/pull/5868#issuecomment-3950939724
Environment
anthropics/claude-code-action@v1--model claude-opus-4-6- Using
track_progressandmcp__github_comment__update_claude_comment
I've submitted a fix for this in https://github.com/anthropics/claude-code-action/pull/1028.
Root cause: The MCP comment servers (github-comment-server, github-inline-comment-server) used sanitizeContent() on outgoing comment bodies. That function is designed for input sanitization (stripping hidden content to prevent prompt injection) — but when applied to output, it also strips all HTML comments. Separately, ! in <!-- gets escaped to \! upstream, producing <\!-- which doesn't match the strip regex and passes through as visible text.
Fix: Added sanitizeOutputContent() for outgoing comment bodies that:
- Unescapes
<\!--back to<!--(only when a matching-->exists) - Preserves HTML comments in output
- Still redacts GitHub tokens and strips invisible characters
sanitizeContent() remains unchanged for input paths.
Edge cases tested:
- Token inside HTML comment (
<!-- ghp_xxx -->) — still redacted - Double-escaped
\\!— not over-unescaped, stays as\\! - Mixed escaped and unescaped comments in same body — both handled correctly
\!inside fenced code blocks (e.g. bash\!42) — preserved, not mangled- Unclosed
<\!--with no matching-->— left escaped to prevent eating rest of page - Multiline HTML comments — works
- Adjacent comments with no whitespace — both unescaped
- Prompt injection via HTML comment — output preserves (Claude's own output), input sanitizer still strips (user content)
All 666 tests pass, typecheck clean, formatting clean.
cc @OctavianGuzu @ashwin-ant