inject
Inject relevant knowledge into session context from .agents/ artifacts. Triggers: "inject knowledge", "recall context", SessionStart hook.
Best use case
inject is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Inject relevant knowledge into session context from .agents/ artifacts. Triggers: "inject knowledge", "recall context", SessionStart hook.
Teams using inject should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/inject/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How inject Compares
| Feature / Agent | inject | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Inject relevant knowledge into session context from .agents/ artifacts. Triggers: "inject knowledge", "recall context", SessionStart hook.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
> **DEPRECATED (removal target: v3.0.0)** — Use `ao lookup --query "topic"` for on-demand learnings retrieval, or see `.agents/AGENTS.md` for knowledge navigation. This skill and the `ao inject` CLI command still work but are no longer called from hooks or other skills.
# Inject Skill
**On-demand knowledge retrieval. Not run automatically at startup (since ag-8km).**
Inject relevant prior knowledge into the current session.
Treat `$inject` as passive context loading, not as a task-planning or task-execution entrypoint.
## How It Works
In the default `manual` startup mode, MEMORY.md is auto-loaded by Codex and no startup injection occurs. Use `$inject` or `ao inject` for on-demand retrieval when you need deeper context.
In `lean` or `legacy` startup modes (set via `AGENTOPS_STARTUP_CONTEXT_MODE`), the SessionStart hook runs:
```bash
# lean mode (MEMORY.md fresh): 400 tokens
ao inject --apply-decay --format markdown --max-tokens 400 \
[--bead <bead-id>] [--predecessor <handoff-path>]
# legacy mode: 800 tokens
ao inject --apply-decay --format markdown --max-tokens 800 \
[--bead <bead-id>] [--predecessor <handoff-path>]
```
This searches for relevant knowledge and injects it into context.
### Work-Scoped Injection
When `--bead` is provided (via `HOOK_BEAD` env var from Gas Town):
- Learnings tagged with the same bead ID get a 1.5x score boost
- Learnings matching bead labels get a 1.2x boost
- Untagged learnings still appear but ranked lower
### Predecessor Context
When `--predecessor` is provided (path to a handoff file):
- Extracts structured context: progress, blockers, next steps
- Injected as "Predecessor Context" section before learnings
- Supports explicit handoffs, auto-handoffs, and pre-compact snapshots
## Manual Execution
Given `$inject [topic]`:
### Step 1: Search for Relevant Knowledge
**With ao CLI:**
```bash
ao inject --context "<topic>" --format markdown --max-tokens 1000
```
**Without ao CLI, search manually:**
```bash
# Global operating memory
sed -n '1,120p' ~/.agents/MEMORY.md 2>/dev/null
# Recent learnings
ls -lt .agents/learnings/ | head -5
# Recent patterns
ls -lt .agents/patterns/ | head -5
# Recent research
ls -lt .agents/research/ | head -5
# Global learnings (cross-repo knowledge)
ls -lt ~/.agents/learnings/ 2>/dev/null | head -5
# Global patterns (cross-repo patterns)
ls -lt ~/.agents/patterns/ 2>/dev/null | head -5
# Legacy patterns (read-only fallback, no new writes)
ls -lt ~/.codex/patterns/ 2>/dev/null | head -5
```
### Step 2: Read Relevant Files
Read the most relevant artifacts based on topic.
### Step 3: Summarize for Context
Present the injected knowledge:
- Global principles or constraints that apply everywhere
- Key learnings relevant to current work
- Patterns that may apply
- Recent research on related topics
### Step 4: Record Citations (Feedback Loop)
After presenting injected knowledge, record which files were injected for the feedback loop:
```bash
mkdir -p .agents/ao
# Record each injected learning file as a citation
for injected_file in <list of files that were read and presented>; do
echo "{\"artifact_path\": \"$injected_file\", \"cited_at\": \"$(date -Iseconds)\", \"session_id\": \"$(date +%Y-%m-%d)\", \"workspace_path\": \"$PWD\"}" >> .agents/ao/citations.jsonl
done
```
Citation tracking enables the feedback loop: learnings that are frequently cited get confidence boosts during `$post-mortem`, while uncited learnings decay faster.
## Knowledge Sources
| Source | Location | Priority | Weight |
|--------|----------|----------|--------|
| Global Memory | `~/.agents/MEMORY.md` | Highest | 1.0 |
| Learnings | `.agents/learnings/` | High | 1.0 |
| Patterns | `.agents/patterns/` | High | 1.0 |
| Global Learnings | `~/.agents/learnings/` | High | 0.8 (configurable) |
| Global Patterns | `~/.agents/patterns/` | High | 0.8 (configurable) |
| Research | `.agents/research/` | Medium | — |
| Retros | `.agents/learnings/` | Medium | — |
| Legacy Patterns | `~/.codex/patterns/` | Low | 0.6 (read-only, no new writes) |
## Decay Model
Knowledge relevance decays over time (~17%/week). More recent learnings are weighted higher.
## Key Rules
- **Runs automatically** - usually via hook
- **Context-aware** - filters by current directory/topic
- **Token-budgeted** - respects max-tokens limit
- **Recency-weighted** - newer knowledge prioritized
## Examples
### SessionStart Hook Invocation (lean/legacy modes only)
**Hook triggers:** `session-start.sh` runs at session start with `AGENTOPS_STARTUP_CONTEXT_MODE=lean` or `legacy`
**What happens:**
1. Hook calls `ao inject --apply-decay --format markdown --max-tokens 400` (lean) or `--max-tokens 800` (legacy)
2. CLI searches `.agents/learnings/`, `.agents/patterns/`, `.agents/research/` for relevant artifacts
3. CLI applies recency-weighted decay (~17%/week) to rank results
4. CLI outputs top-ranked knowledge as markdown within token budget
5. Agent presents injected knowledge in session context
**Result:** Prior learnings, patterns, research automatically available at session start without manual lookup.
**Note:** In the default `manual` mode, MEMORY.md is auto-loaded by Codex and this hook emits only a pointer to on-demand retrieval commands (`ao search`, `ao lookup`).
### Manual Context Injection
**User says:** `$inject authentication` or "recall knowledge about auth"
**What happens:**
1. Agent calls `ao inject --context "authentication" --format markdown --max-tokens 1000`
2. CLI filters artifacts by topic relevance
3. Agent reads top-ranked learnings and patterns
4. Agent summarizes injected knowledge for current work
5. Agent references artifact paths for deeper exploration
**Result:** Topic-specific knowledge retrieved and summarized, enabling faster context loading than full artifact reads.
## Troubleshooting
| Problem | Cause | Solution |
|---------|-------|----------|
| No knowledge injected | Empty knowledge pools or ao CLI unavailable | Run `$post-mortem` to seed pools; verify ao CLI installed |
| Irrelevant knowledge | Topic mismatch or stale artifacts dominate | Use `--context "<topic>"` to filter; prune stale artifacts |
| Token budget exceeded | Too many high-relevance artifacts | Reduce `--max-tokens` or increase topic specificity |
| Decay too aggressive | Recent learnings not prioritized | Check artifact modification times; verify `--apply-decay` flag |
## Local Resources
### scripts/
- `scripts/validate.sh`Related Skills
vibe
Comprehensive code validation. Runs complexity analysis then multi-model council. Answer: Is this code ready to ship? Triggers: "vibe", "validate code", "check code", "review code", "code quality", "is this ready".
validation
Full validation phase orchestrator. Vibe + post-mortem + retro + forge. Reviews implementation quality, extracts learnings, feeds the knowledge flywheel. Triggers: "validation", "validate", "validate work", "review and learn", "validation phase", "post-implementation review".
update
Reinstall all AgentOps skills globally from the latest source. Triggers: "update skills", "reinstall skills", "sync skills".
trace
Trace design decisions and concepts through session history, handoffs, and git. Triggers: "trace decision", "how did we decide", "where did this come from", "design provenance", "decision history".
test
Test generation, coverage analysis, and TDD workflow. Triggers: "test", "generate tests", "test coverage", "write tests", "tdd", "add tests", "test strategy", "missing tests", "coverage gaps".
status
Single-screen dashboard showing current work, recent validations, flywheel health, and suggested next action. Triggers: "status", "dashboard", "what am I working on", "where was I".
standards
Language-specific coding standards and validation rules. Provides Python, Go, Rust, TypeScript, Shell, YAML, JSON, and Markdown standards. Auto-loaded by $vibe, $implement, $doc, $bug-hunt, $complexity based on file types.
shared
Shared reference documents for multi-agent skills (not directly invocable)
security
Continuous repository security scanning and release gating. Triggers: "security scan", "security audit", "pre-release security", "run scanners", "check vulnerabilities".
security-suite
Composable security suite for binary and prompt-surface assurance, static analysis, dynamic tracing, repo-native redteam scans, contract capture, baseline drift, and policy gating. Triggers: "binary security", "reverse engineer binary", "black-box binary test", "behavioral trace", "baseline diff", "prompt redteam", "security suite".
scenario
Author and manage holdout scenarios for behavioral validation. Scenarios are stored in .agents/holdout/ where implementing agents cannot see them. Triggers: "$scenario", "holdout", "behavioral scenario", "create scenario", "list scenarios".
scaffold
Project scaffolding, component generation, and boilerplate setup. Triggers: "scaffold", "new project", "init project", "create project", "generate component", "setup project", "starter", "boilerplate".