From bc-harness
Generates or refreshes the canonical AGENTS context tree (AGENTS.md, CLAUDE.md, docs/agents/*.md) from implemented code. Idempotent upsert — updates only what drifted. Accepts path, +/- filter flags, and --adopt.
How this command is triggered — by the user, by Claude, or both
Slash command
/bc-harness:ai-context [path] [+file] [-file] [--adopt]This command is limited to the following tools:
The summary Claude sees in its command listing — used to decide when to auto-load this command
# ai-context You are the router and orchestrator for the AGENTS context tree. You parse input, verify preconditions, delegate inspection and writing to agents, verify artifacts on disk, and report. You never author artifact content yourself — all template knowledge lives in the agents. ## Objective Keep the canonical AGENTS context tree in sync with the target repository's **implemented code**. First run creates the tree; later runs detect drift and update only the artifacts whose canonical content changed. Safe to re-run at any time. The tree documents reality, not intent: source code,...
You are the router and orchestrator for the AGENTS context tree. You parse input, verify preconditions, delegate inspection and writing to agents, verify artifacts on disk, and report. You never author artifact content yourself — all template knowledge lives in the agents.
Keep the canonical AGENTS context tree in sync with the target repository's implemented code. First run creates the tree; later runs detect drift and update only the artifacts whose canonical content changed. Safe to re-run at any time.
The tree documents reality, not intent: source code, manifests, CI config, and configs are the only sources of truth. Planning artifacts (.spec/, .specs/, spec/) are invisible to this command — never read, never cited, in any step.
| id | Path | Content |
|---|---|---|
AGENTS | AGENTS.md | 6 numbered sections: commands, conventions, behavioral rules, setup, references, docs index |
CLAUDE | CLAUDE.md | ≤400-byte redirect to AGENTS.md |
project_overview | docs/agents/project_overview.md | Purpose, consumers, macro flow |
architecture | docs/agents/architecture.md | Style, layout, layer responsibilities |
tech_stack | docs/agents/tech_stack.md | Language, framework, runtime, test tooling |
coding_guidelines | docs/agents/coding_guidelines.md | ≥3 observed patterns + enforcement |
domain_rules | docs/agents/domain_rules.md | Business rules as implemented |
api_contracts | docs/agents/api_contracts.md | Endpoints, payloads, message formats |
data_model | docs/agents/data_model.md | Entities, storage, migrations |
dependencies | docs/agents/dependencies.md | External services, internal libs, shared infra |
$ARGUMENTS$ARGUMENTS
| Token | Meaning |
|---|---|
| absolute path | target repo root |
| relative path / bare name | resolve against current working directory |
| (no path) | target = current working directory |
+<id> | include-only mode: generate ONLY the listed ids |
-<id> | exclude mode: generate all except the listed ids |
--adopt | take ownership of pre-existing hand-written artifacts (see Ownership) |
Validation: mixing + and - flags is an error — abort with a one-line explanation. Unknown id → abort listing valid ids. No filter flags → all 10 ids.
Every generated file carries this banner on line 3:
<!-- Generated by /ai-context. Manual edits are overwritten on re-run. -->
| On-disk state | Default | With --adopt |
|---|---|---|
| absent | create | create |
banner present (owned) | regenerate, byte-diff, update only if changed | same |
exists without banner (not-owned) | skip + warn — never clobber hand-written files | fold its concrete rules into the generated tree, then overwrite (adopted) |
Parse $ARGUMENTS per the table above. Resolve the target to an absolute path. Compute include_files (set of ids) and adopt (boolean).
git -C <target> rev-parse --is-inside-work-tree
Fails → abort with Target <path> is not a git repository — aborting. Write nothing.
ai-context-inspector)Spawn the ai-context-inspector agent (plugin-namespaced, e.g. bc-harness:ai-context-inspector) with the target path. It returns the structured digest: stack, verbatim commands, layout, dependency list, API/async/persistence signals, domain signals, legacy seeds, and the ownership classification of all 10 canonical paths.
Hold the digest for step 4. Do not re-inspect the repo yourself.
ai-context-core + ai-context-docs, in parallel)Spawn both writer agents in the same message so they run concurrently — they write disjoint files and both consume the digest read-only:
ai-context-core — inputs: target, full digest, include_files ∩ {AGENTS, CLAUDE}, adopt. Writes AGENTS.md + CLAUDE.md.ai-context-docs — inputs: target, full digest, include_files ∩ {8 doc ids}, adopt. Writes docs/agents/*.md.If a writer's entire slice of include_files is empty, skip spawning it.
Inject the digest verbatim into each agent prompt — writers must not re-explore the repo for facts the digest already carries.
If a writer fails mid-run: stop, report which artifacts were touched and the failure message. Never synthesize artifact content from the agent's output text — the only recovery is re-invoking the agent.
Trust but verify — run these checks yourself (parallel Bash calls) on every id in include_files whose reported status is not skipped (not owned) / disabled:
# size checks ignore foreign marker blocks (third-party <tag>...</tag> regions, e.g. Laravel Boost)
strip_foreign() { awk '/^<[A-Za-z][-A-Za-z0-9]*>$/{skip=1} !skip{print} /^<\/[A-Za-z][-A-Za-z0-9]*>$/{skip=0}' "$1"; }
test -f <path> # exists
[ "$(wc -c < <path>)" -ge 120 ] # non-trivial body (skip for CLAUDE.md)
grep -Fq '<!-- Generated by /ai-context.' <path> # ownership banner
[ "$(strip_foreign <target>/CLAUDE.md | wc -c)" -le 400 ] # CLAUDE.md only
grep -Fq '## 6. Agent Documentation' <target>/AGENTS.md # AGENTS.md only
grep -Fq '## AS IS — Current state' <path> # docs/agents/* only
Any check fails → abort with a message naming the offending paths. Do not fix content yourself; report.
Emit one table:
| Artifact | Status |
|---|---|
<path> | created / updated / unchanged / adopted / skipped (N/A) / skipped (not owned) / disabled |
After the table:
skipped (not owned) entries → 1 line: re-run with --adopt to take ownership.No changes — tree already in sync.git diff and commits manually. Cosmetic-only diffs (reworded prose, same structure/evidence) may be discarded; structural or evidence-bearing diffs should be committed..spec/, .specs/, spec/ are never read or cited by any step of this pipeline.--adopt.<tag>...</tag> regions (e.g. <laravel-boost-guidelines>) in owned files are re-appended verbatim on regeneration, never reworded, never seeded; size checks ignore them..env is never read; env var names come from .env.example only.npx claudepluginhub beerandcodeteam/beer-and-code-harness/agentsGenerates AGENTS.md files for repository folders where missing, providing coding agents with build commands, test instructions, code style, and project boundaries.
/generate-AGENTS-fileGenerates or updates AGENTS.md with project-specific context, domain knowledge, constraints, rules, and git patterns for AI coding assistants like Claude Code, Cursor, and Copilot.
/init-syncScans the codebase and populates or updates CLAUDE.md and AGENTS.md files with actual project data and metadata.
/aiwg-regenerate-agentsRegenerates AGENTS.md by analyzing project state and preserving team directives. Supports --dry-run, --no-backup, --show-preserved, --full, and --interactive flags.
/map-codebaseSurveys project and generates missing CLAUDE.md, ARCHITECTURE.md, CODE-PATTERNS.md for SoloFlow agent shared context. Idempotent; supports skip flags.
/sync-contextAnalyzes codebase patterns and conventions, then intelligently updates CLAUDE.md with current project structure, coding standards, agent usage, and environment info. Also supports --section and --dry-run flags.