Inject Session Context
Read AGENTS.md (or another briefing file) and inject it into the model's context at session start.
ts
#!/usr/bin/env bun
// .hooks/briefing.ts
import { defineHook, run } from "@pivanov/agent-hooks-bridge";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
const hooks = defineHook({
SessionStart: async (event) => {
const cwd = event.cwd ?? process.cwd();
let briefing = "";
for (const candidate of ["AGENTS.md", "CLAUDE.md", ".cursorrules"]) {
try {
briefing = await readFile(join(cwd, candidate), "utf8");
break;
} catch {
// try next
}
}
if (briefing.length === 0) {
return { decision: "allow" };
}
return {
decision: "allow",
additional_context: briefing,
};
},
});
await run(hooks);Install:
bash
bunx @pivanov/agent-hooks-bridge install ./.hooks/briefing.ts --events SessionStartPer-host behavior
additional_context on SessionStart is honored everywhere:
| Host | Wire field |
|---|---|
| Claude | hookSpecificOutput.additionalContext |
| Cursor | additional_context (Cursor's sessionStart accepts it) |
| Codex | hookSpecificOutput.additionalContext |
Use SessionStart whenever the briefing is project-level. For per-prompt enrichment, see the next section.
Per-prompt injection via UserPromptSubmit
UserPromptSubmit lets you read the prompt content and inject related context per-prompt. Per-host support differs:
- Claude: works (
hookSpecificOutput.additionalContextonUserPromptSubmit). - Cursor: dropped. Cursor's
beforeSubmitPromptresponse is allow/deny only; no context-injection field. The bridge logs the drop to stderr. - Codex: works.
If your injection is dynamic per-prompt:
- On Cursor, fall back to
SessionStartfor the briefing (project-level only). - Or move the dynamic injection to
PostToolUsebetween turns. This runs after a tool fires, not before the model reads the prompt.