Skip to content

UnicodeEncodeError on Windows when session contains special characters #6

Description

@tusharmoranij

Description

When converting a session file that contains special Unicode characters (like ⚙), the tool fails with a UnicodeEncodeError on Windows.

Error

Traceback (most recent call last):
  ...
  File "...\claude_code_transcripts\__init__.py", line 897, in generate_html
    (output_dir / f"page-{page_num:03d}.html").write_text(page_content)
  File "...\Lib\pathlib.py", line 1048, in write_text
    return f.write(data)
  File "...\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2699' in position 15742: character maps to <undefined>

Cause

The write_text() call on line 897 doesn't specify an encoding, so it defaults to the system encoding (cp1252 on Windows), which cannot handle Unicode characters like \u2699 (⚙ gear symbol).

Suggested Fix

Explicitly specify UTF-8 encoding when writing HTML files:

(output_dir / f"page-{page_num:03d}.html").write_text(page_content, encoding="utf-8")

This should be applied to all write_text() calls in the codebase.

Environment

  • OS: Windows 10/11
  • Python: 3.12.8
  • claude-code-transcripts: 0.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions