Skip to content

Harden CLAUDE.md template for agent compliance#1

Merged
calesthio merged 6 commits intomasterfrom
harden-claude-md-template
Mar 25, 2026
Merged

Harden CLAUDE.md template for agent compliance#1
calesthio merged 6 commits intomasterfrom
harden-claude-md-template

Conversation

@calesthio
Copy link
Copy Markdown
Owner

Summary

  • Rewrites claude_md_section.txt template so generated CLAUDE.md instructions are treated as a behavioral contract, not a reference document
  • Adds PATH detection warning to init.py when the CLI is installed but not discoverable
  • Adds tests for new mandatory content and PATH warning

Motivation

In real usage, agents read the generated CLAUDE.md instructions and then ignore them — completing entire sessions without running sessionanchor boot or a single save command. The root cause isn't unclear instructions; it's that the template is structured as passive reference material rather than an active protocol with checkpoints.

Changes

Template (claude_md_section.txt)

  • Section headers now say MANDATORY: — agents scan headers, skim body text
  • Session start says "do this FIRST, before any other work" with install/init recovery steps
  • Added python -m sessionanchor fallback for PATH issues
  • Save method is now platform-adaptive ("background agent if available, otherwise inline") instead of mandating subagents
  • Added self-check rule: "if you have completed 3+ tasks without a save, stop and save now"
  • Reference material (memory tiers, querying, re-indexing) separated from action items under Reference: headers

Init (init.py)

  • After init completes, checks shutil.which("sessionanchor") and warns if the CLI isn't on PATH

Tests (test_init.py)

  • test_claude_md_has_mandatory_sections — verifies all key elements in generated CLAUDE.md
  • test_init_warns_when_cli_not_on_path — monkeypatches shutil.which to verify warning output

Test plan

  • All 59 existing tests pass
  • 2 new tests pass
  • Verify a fresh sessionanchor init on a new repo produces the updated CLAUDE.md

🤖 Generated with Claude Code

calesthio and others added 6 commits March 25, 2026 15:25
The generated CLAUDE.md instructions were being read but not followed by
agents in practice. This rewrites the template to be a behavioral contract
rather than a reference document:

- Mark session start and save sections as MANDATORY in headers
- Add install/init fallback instructions (pip install, python -m)
- Add self-check rule: "if 3+ tasks done without a save, stop and save"
- Make save method platform-adaptive (background agent OR inline)
- Separate reference material (tiers, querying) from action items
- Add PATH warning to init when CLI is installed but not discoverable

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Restore save complete as primary action for finished tasks (P1):
  The previous version directed agents to log completed work as
  session_log entries, leaving action_items permanently active in
  boot briefings. save complete is now the first command shown for
  task completion.

- Use module fallback consistently for init and boot (P2):
  The recovery flow now mentions python -m sessionanchor as a
  drop-in replacement for all commands, not just boot.

- Reword PATH warning for uvx/pipx users (P2):
  The warning no longer claims the package is installed when it may
  have been run via uvx. It now says "not found on PATH" and
  suggests the runner prefix or python -m fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a user asks the agent to work on an unrelated repo mid-session,
the agent should not save that work into the current project's memory.
Adds an explicit instruction with a concrete example.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@calesthio calesthio merged commit 4978f76 into master Mar 25, 2026
2 checks passed
@calesthio calesthio deleted the harden-claude-md-template branch March 25, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant