Skip to content

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 SessionStart

Per-host behavior

additional_context on SessionStart is honored everywhere:

HostWire field
ClaudehookSpecificOutput.additionalContext
Cursoradditional_context (Cursor's sessionStart accepts it)
CodexhookSpecificOutput.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.additionalContext on UserPromptSubmit).
  • Cursor: dropped. Cursor's beforeSubmitPrompt response 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 SessionStart for the briefing (project-level only).
  • Or move the dynamic injection to PostToolUse between turns. This runs after a tool fires, not before the model reads the prompt.

Not affiliated with Anthropic, Anysphere, or OpenAI. Supported by LogicStar AI.