Skip to content

feat: Add agents-md plugin for AGENTS.md fallback support#29835

Open
baktybekb wants to merge 4 commits intoanthropics:mainfrom
baktybekb:add-agents-md-plugin
Open

feat: Add agents-md plugin for AGENTS.md fallback support#29835
baktybekb wants to merge 4 commits intoanthropics:mainfrom
baktybekb:add-agents-md-plugin

Conversation

@baktybekb
Copy link

@baktybekb baktybekb commented Mar 1, 2026

Summary

Adds a new plugin (plugins/agents-md) that provides AGENTS.md support for Claude Code, addressing the most upvoted issue in this repository.

  • SessionStart hook detects and loads AGENTS.md files when no CLAUDE.md is present at the same directory level
  • Mirrors native CLAUDE.md loading order (root-first ancestor walk)
  • Supports both <dir>/AGENTS.md and <dir>/.claude/AGENTS.md locations
  • Checks for all Claude-specific files (CLAUDE.md, .claude/CLAUDE.md, CLAUDE.local.md) before falling back to AGENTS.md
  • Handles edge cases: special characters, unicode, encoding errors, large files (40k char cap)
  • Pure Python3 implementation, consistent with hookify and security-guidance plugins

This enables cross-tool compatibility with 20,000+ repositories using the AGENTS.md standard (Codex, Cursor, Amp, and other AI coding tools).

Resolves #6235

Behavior matrix

CLAUDE.md exists AGENTS.md exists Result
Yes Yes Only CLAUDE.md is used (native behavior)
Yes No Only CLAUDE.md is used (native behavior)
No Yes AGENTS.md is loaded by this plugin
No No Nothing loaded

"CLAUDE.md exists" includes CLAUDE.md, .claude/CLAUDE.md, and CLAUDE.local.md

Plugin structure

plugins/agents-md/
├── .claude-plugin/plugin.json       # Plugin manifest
├── hooks/hooks.json                 # SessionStart hook config
├── hooks-handlers/session-start.py  # Detection & loading logic (Python3)
└── README.md                        # Documentation

Test plan

  • AGENTS.md only present — loads content correctly
  • CLAUDE.md present — skips AGENTS.md
  • CLAUDE.local.md present — skips AGENTS.md
  • .claude/CLAUDE.md present — skips AGENTS.md
  • Neither file present — silent exit, no output
  • .claude/AGENTS.md nested location — loads correctly
  • Mixed hierarchy (parent AGENTS.md + child CLAUDE.md) — correct per-level behavior
  • Special characters, unicode, quotes, JSON-like content — safe JSON encoding

Adds a plugin that reads AGENTS.md files when no CLAUDE.md is present,
enabling cross-tool compatibility with Codex, Cursor, Amp, and 20,000+
repositories that use the AGENTS.md standard.

Resolves anthropics#6235
…docs

- Rewrite SessionStart hook from bash+python mix to pure Python3
  for consistency with hookify and security-guidance plugins
- Add CLAUDE.local.md detection (skip AGENTS.md if local config exists)
- Add plugin entry to plugins/README.md table
- Clean up plugin README for in-repo context
- Reject symlinks to prevent reading sensitive files like /etc/shadow
- Check file size before reading to prevent memory exhaustion on huge files
- Add top-level exception handler to never block session start
- Validate CWD is an absolute path before using it
- Handle os.getcwd() failure gracefully
@baktybekb
Copy link
Author

Hi @dicksontsai @bcherny — would appreciate your feedback on this plugin when you have a moment.

This addresses #6235 (the most upvoted issue in the repo) by adding AGENTS.md fallback support via a SessionStart hook — following the same pattern as the explanatory-output-style and hookify plugins.

Happy to adjust anything based on your review. Thanks!

- Allow symlinked AGENTS.md (consistent with CLAUDE.md native behavior,
  needed for monorepos and dotfile managers)
- Limit directory traversal depth to 20 levels (prevent timeout on
  deep NFS/network paths)
- Guard stdin read with isatty() check (prevent hang on manual testing)
- Report errors via systemMessage instead of silent swallow (matches
  hookify error handling pattern)
- Add explicit sys.exit(0) for defensive exit code guarantee
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.

Feature Request: Support AGENTS.md.

1 participant