Skip to content

install/uninstall still rewrite line endings of CLAUDE.md, AGENTS.md and related files (remaining paths after #3741) #4360

Closed

Description

@ujconsulting

Summary

#3741 fixed the CRLF conversion in _register_always_on_block and in the Gemini install path. The remaining writers listed below still use Path.write_text without newline="", and all of them read existing files through Path.read_text, which normalises CRLF to LF before the text is modified. When these paths rewrite an existing file, its line endings are normalised to CRLF or LF depending on platform and writer; the original convention is not reliably preserved. (An install that changes nothing, or an uninstall without a graphify section, leaves the file untouched.)

Where (v0.9.84, graphify/install.py)

  • Still without newline="": claude_install L2047, _agents_install L1809, codebuddy_install L2238, _strip_graphify_md_section L2216 (uninstall of CLAUDE.md), _agents_uninstall L1983 (AGENTS.md), gemini_uninstall L1060, vscode_install L1117 (L1120 creates a new file), vscode_uninstall L1160, codebuddy_uninstall L2311.
  • Fixed in fix(install): stop corrupting line endings and fix the re-install guard in _register_always_on_block #3741: _register_always_on_block L498-L533 and gemini_install L935-L948 - but these still read with read_text(encoding="utf-8").
  • Permalink:

    graphify/graphify/install.py

    Lines 2197 to 2218 in 2cb81c6

    def _strip_graphify_md_section(target: Path) -> bool:
    """Strip the ## graphify section from one CLAUDE.md-style file.
    Returns True if a section was removed. Deletes the file if nothing else
    remains after removal.
    """
    try:
    content = target.read_text(encoding="utf-8")
    except (OSError, UnicodeDecodeError):
    # An unreadable/undecodable CLAUDE.md-style file (e.g. non-UTF-8, or a
    # directory of that name) must not abort uninstall - nothing to strip.
    return False
    # Remove graphify's ## graphify section (heading matched exactly, never as a
    # substring of a user's ### graphify) from the marker to the next H2 or EOF.
    cleaned = _remove_marker_section(content, _CLAUDE_MD_MARKER)
    if cleaned is None:
    return False
    # A symlink stays: writing through it cleans the file it points to.
    if cleaned or target.is_symlink():
    target.write_text(cleaned + "\n", encoding="utf-8")
    print(f"graphify section removed from {target.resolve()}")
    else:

Why it matters

On Windows, these writes convert the normalised LF text to CRLF whenever a rewrite happens. That changes the bytes of an LF file in the working tree and can show up as an every-line diff where git does not normalise line endings (with * text eol=lf, git diff may hide it). On Linux/macOS a CRLF file loses its \r the same way. For CLAUDE.md/AGENTS.md, which are often shared and reviewed, that can hide the real change in noise and trip line-ending checks.

Minimal reproduction (Windows, Git Bash, Python 3.12)

  1. In a project directory, create CLAUDE.md with LF line endings (printf 'a b ' > CLAUDE.md).
  2. Run graphify claude install, then graphify uninstall.
  3. Inspect the file (file CLAUDE.md).

Expected: only the graphify block is added and later removed; the remaining lines keep LF.
Actual: the file is rewritten with CRLF line endings. The same read-modify-write pattern in isolation (read_text, append, write_text) turns both LF and CRLF input into CRLF on Windows with the default write, or into LF with newline=""; neither choice preserves both input conventions.

Suggested fix

Read the existing file without newline translation (open(..., newline=""), or read bytes and decode; Path.read_text(newline=...) needs Python 3.13), detect its line ending, write the new block with that ending (the helpers currently join with a hard-coded ), and write with newline="" everywhere. A single helper used by all install/uninstall writers would cover the remaining paths and keep them from drifting apart again. A round-trip test per writer (LF file and CRLF file in, same endings out, only the graphify block changed) would pin it.

Environment

graphify 0.9.84 (release commit above). Windows 11, Claude Code. Found during an internal security review.

Activity

  1. github-actions commented on Oct 12, 2026

    @github-actions

    Thanks for opening this issue, @ujconsulting. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. safishamsi commented on Oct 12, 2026

    @safishamsi
    Member

    Fixed in v0.9.88 (graphifyy 0.9.88 on PyPI) via #4372.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions