agents-md-loader — Claude Code hook: setup and use
This hook adds AGENTS.md to Claude Code’s session context on startup or resume, so project instructions are available without a manual request.
npx claude-code-templates@latest --hook automation/agents-md-loaderWhat agents-md-loader does
On startup and resume, the hook checks for AGENTS.md and passes its contents into the session’s additional context. When the file is absent, it passes an empty context. So the hook supplies no project instructions unless that file exists.
The hook runs a python3 command with a 30-second timeout. To install it, run npx claude-code-templates@latest --hook automation/agents-md-loader, then use .claude/settings.json.
What it helps with
- load project instructions when a Claude Code session starts
- restore
AGENTS.mdcontext when resuming a session - share agent guidance through a common project file
Example prompts for the agent
- Start a session and follow the project guidance in
AGENTS.md. - Resume the session and apply the instructions from
AGENTS.md.
How to install agents-md-loader
1claude-code-templates
npx claude-code-templates@latest --hook automation/agents-md-loader2Manually: put the files in place
.claude/settings.jsonThe hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json
Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command
Questions about agents-md-loader
How do I install agents-md-loader in Claude Code?
Run npx claude-code-templates@latest --hook automation/agents-md-loader, then use .claude/settings.json.
What does agents-md-loader do?
It adds the contents of AGENTS.md to Claude Code’s context when a session starts or resumes. If the file is missing, the hook passes an empty context.
Does agents-md-loader require Python?
Yes. The hook runs through python3.
Source text
agents-md-loader.json · MIT
{
"description": "Automatically loads AGENTS.md configuration file content at session start to ensure Claude Code follows project-specific agent behavior. Only loads if AGENTS.md exists, otherwise passes empty context. Supports the universal AGENTS.md standard for cross-platform AI assistant compatibility.",
"hooks": {
"SessionStart": [
{
"matcher": "startup|resume",
"hooks": [
{
"type": "command",
"command": "python3 -c \"import json, sys, os; agents_content = open('AGENTS.md', 'r').read() if os.path.exists('AGENTS.md') else ''; output = {'hookSpecificOutput': {'hookEventName': 'SessionStart', 'additionalContext': agents_content}}; print(json.dumps(output))\"",
"timeout": 30
}
]
}
]
}
}
© davila7 · MIT · davila7/claude-code-templates