OmO
Oh My OpenAgentv4.7.5

Context Injection

Hooks that auto-inject AGENTS.md, README context, conditional rules, and compaction-preserved state.

When an agent reads a file, the context-injection hooks walk the filesystem upward and inject what the rest of the project says about that file. The agent gets project conventions for free — no prompting required.

HookWhen it runsWhat it injects
directory-agents-injectorPreToolUse + PostToolUse on readsEvery AGENTS.md from the file's directory up to the project root. Auto-disabled on OpenCode 1.1.37+ which has native support.
directory-readme-injectorPreToolUse + PostToolUse on readsThe neighboring README.md for directory context.
rules-injectorPreToolUse + PostToolUseFiles under .claude/rules/*.{md,mdc} whose globs match — and any file with alwaysApply: true. Walks up from the file plus ~/.claude/rules/.
compaction-context-injectorEventRe-injects load-bearing context (todo state, plan markers, recent decisions) after a context-window compaction so the agent doesn't lose where it was.
context-window-monitorEventTracks token consumption and surfaces warnings before the limit.
preemptive-compactionEventProactively compacts before hitting hard limits — chosen over reactive recovery.

Hierarchical AGENTS.md

project/
├── AGENTS.md              # injected first
├── src/
│   ├── AGENTS.md          # injected second
│   └── components/
│       ├── AGENTS.md      # injected third
│       └── Button.tsx     # reading this injects all 3

The walk is cheap — the harness caches per session.

Conditional rules

---
globs: ["*.ts", "src/**/*.js"]
description: TypeScript/JavaScript coding rules
---

- Use PascalCase for interface names.
- Use camelCase for function names.

.md and .mdc files are supported. alwaysApply: true skips the glob check.

Source Notes

Aligned with upstream docs/reference/features.md#context--injection and #context-injection.

On this page