A typescript library
npm install agents-mdWe need an elegant and scalable vibe coding solution.
Your project grows, but your AGENTS.md doesn't scale:
``bash`
project/
├── AGENTS.md ← single file, static name, impossible to sustain
├── docs/
├── api/
Split context into organized fragments, then compose:
`bash`
project/
├── AGENTS.md ← auto-generated
├── docs/
│ └── overview.agents.md ← parsed
├── api/
│ ├── AGENTS.md ← auto-generated
│ └── endpoints.agents.md ← parsed
├── agents-md/
│ └── epics/
│ └── epic-one.md ← parsed
│ └── epic-two.md ← parsed
One command builds them all:
`bash`
npx agents-md compose
Compose canonical AGENTS.md from sustainable and elegant file structures. Keep agent context current, composable, and shareable with your human docs. Abstract-context-as-code is what we aim to achieve.
- Initialize: npx agents-md init (creates root AGENTS.md if missing)/agents-md//*.md
- Update fragment files in any of these path formats:
- */.agents.md
- */
- */.
- npx agents-md compose
- Compose:
Generated files are owned by agents-md. Don't hand‑edit AGENTS.md — edit source fragments instead.
To have multiple AGENTS.md files for dynamic location-based context, simply add an empty AGENTS.md file in any target directory and rerun bun agents-md compose.
Keep your AGENTS.md files automatically up-to-date with a pre-commit hook:
`bash`
npx agents-md setup:compose-before-commit
The setup command works with any git repository, regardless of language (JavaScript, Python, Go, Rust, etc.):
What it does:
1. Creates a git hook in .git/hooks/pre-commitnpx agents-md compose
2. Makes it executable automatically
3. Runs and stages AGENTS.md files before each commit
Performance tip: For faster commits, install agents-md globally:`bash`
npm install -g agents-md
This avoids npx downloading the package on every commit.
To regenerate the hook (after updating agents-md):
`bash`
npx agents-md setup:compose-before-commit
To bypass temporarily (not recommended):
`bash`
git commit --no-verify
Common pain points today:
- Single, static AGENTS.md per directory; no native "imports" or multi‑file composition.AGENTS.md
- No glob‑based includes in itself; no spec for dynamic content (e.g., JSDoc or config extraction).AGENTS.md
- Some tools don't read ;.ruler/
- Existing options like Ruler assume and don't curate dynamic content outside of those directories.
- Inputs (fragment files): Accept all Markdown files in /agents-md//.md and /.agents.md. Meanwhile, all file paths are configurable.AGENTS.md
- Outputs ( target files): One AGENTS.md per target directory (nearest‑wins by default) with deterministic ordering and source annotations.CLAUDE.md
- Routing: Markdown directives map fragments to targets.
- Interop: Optional can import @AGENTS.md for tools that don't read AGENTS.md.
- agents-md initAGENTS.md
- Initialize agents-md in this project; creates root if missing (use compose if already initialized).agents-md compose
- agents-md report [--json]
- Build outputs from fragments.
- --json
- Show outputs, sizes (k chars), token estimates, and warnings (use for CI).agents-md watch [--verbose]
- --verbose
- Rebuild on changes silently; use to log rebuilds.agents-md setup:compose-before-commit
- agents-md help|version
- Setup pre-commit hook to auto-compose AGENTS.md files before each commit (works with any codebase: Node.js, Python, Go, etc.).
-
Exit codes: 0 success, 1 generic error, 2 invalid config, 4 limit violation.
Use agents-md.config.ts (or .js/.mjs) at repo root. Defaults are zero‑config; customize only as needed. See full schema in docs/design.md.
Key options
| Option | Type | Default | Purpose |
| --- | --- | --- | --- |
| include | string[] | ['/agents-md//.md','/.agents.md'] | Fragment discovery globs |exclude
| | string[] | ['/node_modules/','/.git/'] | Ignore patterns |includeFiles
| | (ctx) => boolean | undefined | Advanced per‑file filter |defaultTarget
| | 'nearest'|'root' | 'nearest' | Fallback routing behavior |annotateSources
| | boolean | true | Wrap fragments with / comments |truncate
| | { atChars, strategy } | undefined | Trim oversized outputs |limits
| | { warn/max source/output } | undefined | Size limits and warnings |
- Target routing
-
-
- (relative dir)
- Imports
-
-
- Ordering and metadata
- (higher numbers surface earlier)
- (optional heading hint)
Rules: keys are comma/space separated (key=value); paths start with @ for Claude Code compatibility; resolution is relative to the fragment file.
- Discovery: collect fragments from include globs.defaultTarget
- Targeting: directive > (nearest).priority
- Ordering: by (descending), then by path (stable and deterministic).
- Annotation: optionally wrap fragments with and comments.AGENTS.md
- Output: write one per selected target with a generated‑file banner.
- Shows: target tree, output sizes, token estimates, source counts, limit status.
- JSON mode: agents-md report --json for CI and tooling.
- init moves content from AGENTS.md/CLAUDE.md into fragments, scaffolds config, and creates a root AGENTS.md when absent.CLAUDE.md
- For Claude Code, create with: @AGENTS.md (imports generated content).
- Can be combined with distribution tools (e.g., Ruler) if needed.
- Why not hand‑write AGENTS.md? Fragments scale better and enable reuse.AGENTS.md
- Do I need more than one files? No — start with zero‑config and a single root 'AGENTS.md' generated by init or compose.
- Are directives required? No — they only override defaults when needed.
- Official plugin kit (extract JSDoc, TypeScript types, DB schemas).
- Better hot reload support for ecosystem tools (Vite, Bun, etc.).
- MCP for cross-directory reference support.
- Thanks to OpenAI's AGENTS.md` standardization efforts.
- Inspired by Ruler for distribution ideas.