Skip to content

feat: add hook based context injection for ai agents - #124

Open
dev-ahmadbilal wants to merge 2 commits into
hhsadiq:developfrom
dev-ahmadbilal:feat/ai-agents-helpers
Open

feat: add hook based context injection for ai agents#124
dev-ahmadbilal wants to merge 2 commits into
hhsadiq:developfrom
dev-ahmadbilal:feat/ai-agents-helpers

Conversation

@dev-ahmadbilal

@dev-ahmadbilal dev-ahmadbilal commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Implements hook-based context injection to keep AI coding agents aligned with our hexagonal architecture across sessions and models.

What's included:

  • AGENTS.md — session-level hot memory: layer map, dependency rules, NEVER list, routing table
  • docs/layers/ + docs/cross-cutting/ — 9 leaf docs injected on demand per file type
  • scripts/inject-context.mjs — PreToolUse hook that blocks wrong file placements and injects relevant docs before every edit
  • scripts/arch-validate.sh — PostToolUse hook with 8 blocking checks:
    • domain importing TypeORM
    • service using @InjectRepository
    • raw NestJS exceptions in services
    • unmapped repo returns
    • console.* usage
    • export default
    • wrong directories
  • .claude/settings.json — wires both hooks

Why:

Without enforcement, agents bypass the hexagonal pattern silently — injecting TypeORM directly into services, skipping Mapper.toDomain(), and placing files in incorrect directories. Each violation becomes precedent for the next agent.

The hooks fire unconditionally on every edit; agents cannot proceed past a violation.

See docs/agent-hooks-guide.md for before/after examples and token cost analysis.

Based on: Hook-Based Context Injection for AI Coding Agents by Andrew Patterson.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant