Skip to content

install --platform claude deletes all CLAUDE.md content below the graphify block when no later H1 exists (regression in 0.9.66, #3741) #3791

Open

Description

@dispather

Summary

Since 0.9.66 (#3741, fix for #3668), graphify install --platform claude deletes all user content in CLAUDE.md below the graphify block when the file has no H1 heading after # graphify. The install prints only Done., with no warning.

This is the default shape of a file that graphify has registered into: the block is written as the H1 # graphify. If the user's own content uses only ## headings (common in CLAUDE.md), the next re-install removes all of it.

Reproduction (0.9.67, macOS)

T=$(mktemp -d)
printf '# graphify\n- **graphify** (`old/path/SKILL.md`) - any input to knowledge graph. Trigger: `/graphify`\nWhen the user types `/graphify`, use the installed graphify skill or instructions before doing anything else.\n\n## My own rules\n- rule one\n- rule two\n' > "$T/CLAUDE.md"
wc -l < "$T/CLAUDE.md"   # 7
CLAUDE_CONFIG_DIR="$T" graphify install --platform claude   # prints "Done."
wc -l < "$T/CLAUDE.md"   # 3 — "## My own rules" and everything below it is gone

On a real global CLAUDE.md this removed 217 lines, and 208 lines in a second config dir. We restored both from a copy made before the install.

Cause

_register_always_on_block → _replace_or_append_section(content, _SKILL_REGISTRATION_MARKER, registration, boundary_prefix="# "). The replaced section runs from # graphify to the next line starting with # , or to EOF if there is none. Our block is 3 lines, but the section runs to the end of the file. Before 0.9.66 the bare substring guard made re-install a no-op, so this path was never reached for files that already had the block.

_remove_claude_skill_registration → _remove_marker_section(..., boundary_prefix="# ") has the same boundary. I have only read this code and not run it, but uninstall looks like it would delete the same content.

Suggested fix

Bound the section by the block graphify itself writes, not by the next heading of the same level. For example:

  • wrap the registration in explicit begin/end markers (<!-- graphify:start --> / <!-- graphify:end -->) and replace only between them, or
  • when no end marker exists (legacy files), replace only the known registration lines. Stop at the first blank line or the first line that is not part of _skill_registration() output, and never extend to EOF.

A cheap guard would also help: refuse to write (and warn) if the replacement would remove more than N lines that graphify did not write.

Workaround

Add any H1 heading directly after the graphify block. Re-install then replaces only the 3-line block.

Activity

  1. EliveltonRepolho commented on Sep 30, 2026

    @EliveltonRepolho

    Another shape of the same cause, still present in 0.9.72: the next H1 exists, but every non-heading line between the graphify block and that H1 is deleted. That includes the markers of other tools that manage a block in the same file, so the "add an H1 after the block" workaround does not protect them.

    Reproduction (0.9.72, Linux):

    T=$(mktemp -d)
    printf '# graphify\n- **graphify** (`old/path/SKILL.md`) - any input to knowledge graph. Trigger: `/graphify`\nWhen the user types `/graphify`, use the installed graphify skill or instructions before doing anything else.\n<!-- BEGIN other-tool -->\n<!-- managed by another tool -->\n\n# Other tool section\ntext\n\n<!-- END other-tool -->\n' > "$T/CLAUDE.md"
    CLAUDE_CONFIG_DIR="$T" graphify install --platform claude   # exit 0, prints no warning
    cat "$T/CLAUDE.md"

    Result: <!-- BEGIN other-tool --> and <!-- managed by another tool --> are gone. <!-- END other-tool --> is left without its pair.

    We hit this on a real ~/.claude/CLAUDE.md during a scheduled update. Our installer found an END marker with no BEGIN marker and refused to touch the block. On our side, we now add our block at the top of the file, so it is never below the graphify section. The explicit <!-- graphify:start --> / <!-- graphify:end --> markers suggested above would fix both shapes.

  2. ujconsulting commented on Oct 11, 2026

    @ujconsulting

    Thanks for the detailed report. Two related observations from our own review that might help prioritise the fix:

    1. fix(install): stop install/uninstall data loss when no matching heading follows a section #3803 narrows the section boundary, which is the right fix for this report. Independently of that, there is still no safety net when a bug of this class hits again: install/uninstall rewrite CLAUDE.md/AGENTS.md (and the user-global ~/.claude/CLAUDE.md) without keeping a copy. settings.json already gets a rolling <name>.graphify-bak (_write_settings_with_backup, claude install --strict overwrites the entire ~/.claude/settings.json (destroys mcpServers, plugins, and all other hooks) with no backup #2167) and SKILL.md gets a .bak (install: --platform X never writes .graphify_version (permanent upgrade warning), and install silently overwrites a modified SKILL.md #3144), so the same single-copy approach for the instruction files would turn a data-loss bug into a recoverable one. fix: clean home-scope skill registration on uninstall; back up config files (#1121) #1310 contains a backup helper for exactly this, if that PR is revived.
    2. claude_uninstall still looks only at the project directory (install.py md_targets), so a global install leaves its block in ~/.claude/CLAUDE.md pointing at a deleted skill; that is fix(install): remove the user-global CLAUDE.md registration on uninstall #3573.

    A regression test for the "foreign content after the block" shape could use: a file with only ## headings after the block, a file with another tool's marker block after it, and a CRLF file - all three must come back byte-identical except for the graphify block.

    Environment: v0.9.84, Windows 11, Claude Code. Found during an internal security review.

    Permalinks:

    • graphify/graphify/install.py

      Lines 2179 to 2183 in 2cb81c6

      md_targets = [
      project_dir / "CLAUDE.md",
      project_dir / "CLAUDE.local.md",
      project_dir / ".claude" / "CLAUDE.local.md",
      ]
    • graphify/graphify/install.py

      Lines 986 to 1000 in 2cb81c6

      def _write_settings_with_backup(settings_path: Path, settings: dict) -> None:
      """Serialize ``settings`` to ``settings_path``, backing up the previous file.
      Skips the write entirely when the output is identical to what is on disk
      (idempotent re-install: no backup churn, no mtime churn). Otherwise copies
      the existing file to ``<name>.graphify-bak`` (single rolling backup) before
      overwriting, so one bad merge can never destroy the user's config (#2167).
      """
      output = json.dumps(settings, indent=2)
      if settings_path.exists():
      if settings_path.read_text(encoding="utf-8") == output:
      return
      backup = settings_path.with_name(settings_path.name + ".graphify-bak")
      shutil.copy2(settings_path, backup)
      settings_path.write_text(output, encoding="utf-8")
  3. singhrohit90 commented on Nov 19, 2026

    @singhrohit90

    Still reproduces in 0.9.112 on Windows, and also with --platform windows, not only --platform claude.

    • Upgraded from 0.7.19 with uv tool install --upgrade graphifyy. The upgrade warning said to run graphify install --platform claude; I ran graphify install --platform windows.
    • The global ~/.claude/CLAUDE.md started with the 3-line # graphify block written by the old version, followed by 48 lines of my own instructions under ## headings only (no later H1).
    • After install the file was 3 lines: only the graphify block. The install printed CLAUDE.md -> skill registered in ... and Done., with no warning. Restored from a copy taken just before the install.

    Two notes from this run:

    1. The upgrade warning points users straight at the destructive command, so anyone upgrading a pre-0.9.66 install with a ##-only CLAUDE.md hits this on the first re-install.
    2. install already keeps SKILL.md.bak when the skill differs from the packaged one; doing the same for CLAUDE.md (or refusing to drop more lines than the block it writes) would make this recoverable even if the boundary bug comes back.
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