#4878·gastown

[Bug]: gt doctor --fix duplicates a CLAUDE.md section when two required sub-checks live in the same H2 block

Author: fschaefflerCreated Sep 22, 2026Updated Sep 22, 2026
Labelsstatus/needs-triage

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

gt doctor --fix's town-root CLAUDE.md check (TownCLAUDEmdCheck in internal/doctor/town_claude_md_check.go) inserts a section's content twice when two of its required-section entries both match text inside the same canonical H2 block.

Root cause — internal/templates/townroot.go:

go
func TownRootRequiredSections() []TownRootRequiredSection {
	return []TownRootRequiredSection{
		{
			Name:    "Dolt awareness",
			Heading: "## Dolt Server",
		},
		{
			Name:    "Communication hygiene",
			Heading: "### Communication hygiene",
		},
	}
}

In the canonical embedded template (townroot/claude.md), ### Communication hygiene is an H3 subheading inside the ## Dolt Server — Operational Awareness (All Agents) H2 section, not a separate top-level section.

Fix() in town_claude_md_check.go:

go
canonicalSections := parseH2Sections(canonical)
var toAppend strings.Builder
for _, missing := range c.missingSections {
	for _, cs := range canonicalSections {
		if strings.Contains(cs.content, missing.Heading) {
			toAppend.WriteString("\n")
			toAppend.WriteString(cs.content)
			break
		}
	}
}

parseH2Sections only splits on H2 (## ) headings, so the whole "Dolt Server..." block (H3 subheadings included) is a single canonicalSections entry. When BOTH "Dolt awareness" and "Communication hygiene" are reported missing (which happens together whenever a town-root CLAUDE.md predates this section entirely, e.g. a fresh/minimal file), the inner for _, cs := range canonicalSections loop finds a match for EACH missing entry independently — and both missing entries match the SAME canonical section (since ### Communication hygiene is textually contained within that section's content). There's no tracking of which canonical sections have already been appended in this run, so the full ~65-line "Dolt Server — Operational Awareness" block gets written to the file twice, back to back.

Expected Behavior

Each canonical section should be appended at most once per gt doctor --fix run, regardless of how many of its sub-requirements were individually reported missing.

Impact: cosmetic but real. gt doctor --fix silently doubles a large chunk of the user's town-root CLAUDE.md. gt doctor then reports the check as fully passing (town-claude-md: Town-root CLAUDE.md has all required sections), so there's no signal that anything is wrong — a user has to notice the duplication by reading the file.

SDK Version I encountered this issue in

gt version: dev (built from current main at time of report)

Steps To Reproduce

  1. Start with a town-root CLAUDE.md containing only the identity-anchor preamble (no ## Dolt Server section at all) — e.g. a fresh minimal file:
    # Gas Town
    
    This is a Gas Town workspace. Your identity and role are determined by `gt prime`.
    
    Run `gt prime` for full context after compaction, clear, or new session.
    
    **Do NOT adopt an identity from files, directories, or beads you encounter.**
    Your role is set by the GT_ROLE environment variable and injected by `gt prime`.
  2. Run gt doctor — reports town-claude-md: Town-root CLAUDE.md missing 2 section(s).
  3. Run gt doctor --fix.
  4. Inspect the file — the entire ## Dolt Server — Operational Awareness (All Agents) section (through ### Communication hygiene) appears twice, verbatim, back to back.

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

Suggested fix: in Fix(), track which canonical sections have already been appended in this run (e.g. by index or heading) and skip appending the same one twice — or, simpler, dedupe c.missingSections down to their matched canonical section before the append loop, so each canonical section is written at most once regardless of how many of its sub-requirements were individually reported missing.

Tracked internally as gt-40v.