2026-05-28 16:34:17 +09:00
---
name: init-deep
description: "(builtin) Initialize hierarchical AGENTS.md knowledge base"
---
## Codex Harness Tool Compatibility
This skill may include examples copied from the OpenCode harness. In Codex, do not call OpenCode-only tools such as `call_omo_agent(...)` , `task(...)` , `background_output(...)` , or `team_*(...)` literally. Translate those examples to Codex native tools:
| OpenCode example | Codex tool to use |
| --- | --- |
| `call_omo_agent(subagent_type="explore", ...)` | `spawn_agent(agent_type="explorer", task_name="...", message="...")` |
| `call_omo_agent(subagent_type="librarian", ...)` | `spawn_agent(agent_type="librarian", task_name="...", message="...")` |
| `task(subagent_type="plan", ...)` | `spawn_agent(agent_type="plan", task_name="...", message="...")` |
| `task(subagent_type="oracle", ...)` for final verification | `spawn_agent(agent_type="codex-ultrawork-reviewer", task_name="...", message="...")` |
| `task(category="...", ...)` for implementation or QA | `spawn_agent(agent_type="worker", task_name="...", message="...")` |
| `background_output(task_id="...")` | `wait_agent(...)` to wait for subagent completion and mailbox updates |
| `team_*(...)` | Use Codex native subagents plus `send_message` , `followup_task` , `wait_agent` , and `close_agent` |
When translating `load_skills=[...]` , include the requested skill names in the spawned agent's `message` . If a code block below conflicts with this section, this section wins.
# /init-deep
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
Generate hierarchical AGENTS.md files. Root + complexity-scored subdirectories.
2025-12-28 17:30:27 +09:00
## Usage
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
/init-deep # Update mode: modify existing + create new where warranted
/init-deep --create-new # Read existing → remove all → regenerate from scratch
/init-deep --max-depth=2 # Limit directory depth (default: 3)
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
---
2025-12-31 13:40:57 +09:00
## Workflow (High-Level)
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
1. **Discovery + Analysis ** (concurrent)
- Fire background explore agents immediately
- Main session: bash structure + LSP codemap + read existing AGENTS.md
2. **Score & Decide ** - Determine AGENTS.md locations from merged findings
3. **Generate ** - Root first, then subdirs in parallel
4. **Review ** - Deduplicate, trim, validate
2025-12-28 17:30:27 +09:00
<critical>
2025-12-31 13:40:57 +09:00
**TodoWrite ALL phases. Mark in_progress → completed in real-time. **
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
TodoWrite([
2025-12-31 13:40:57 +09:00
{ id: "discovery", content: "Fire explore agents + LSP codemap + read existing", status: "pending", priority: "high" },
{ id: "scoring", content: "Score directories, determine locations", status: "pending", priority: "high" },
{ id: "generate", content: "Generate AGENTS.md files (root + subdirs)", status: "pending", priority: "high" },
{ id: "review", content: "Deduplicate, validate, trim", status: "pending", priority: "medium" }
2025-12-28 17:30:27 +09:00
])
2026-05-28 16:34:17 +09:00
```
2025-12-31 03:55:48 +00:00
</critical>
2025-12-28 17:30:27 +09:00
2025-12-31 03:55:48 +00:00
---
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
## Phase 1: Discovery + Analysis (Concurrent)
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Mark "discovery" as in_progress. **
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
### Fire Background Explore Agents IMMEDIATELY
2025-12-28 17:30:27 +09:00
2026-04-04 01:27:51 +09:00
Don't wait-these run async while main session works.
2025-12-28 17:30:27 +09:00
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
// Fire all at once, collect results later
2026-02-06 16:01:54 +09:00
task(subagent_type="explore", load_skills=[], description="Explore project structure", run_in_background=true, prompt="Project structure: PREDICT standard patterns for detected language → REPORT deviations only")
task(subagent_type="explore", load_skills=[], description="Find entry points", run_in_background=true, prompt="Entry points: FIND main files → REPORT non-standard organization")
task(subagent_type="explore", load_skills=[], description="Find conventions", run_in_background=true, prompt="Conventions: FIND config files (.eslintrc, pyproject.toml, .editorconfig) → REPORT project-specific rules")
task(subagent_type="explore", load_skills=[], description="Find anti-patterns", run_in_background=true, prompt="Anti-patterns: FIND 'DO NOT', 'NEVER', 'ALWAYS', 'DEPRECATED' comments → LIST forbidden patterns")
task(subagent_type="explore", load_skills=[], description="Explore build/CI", run_in_background=true, prompt="Build/CI: FIND .github/workflows, Makefile → REPORT non-standard patterns")
task(subagent_type="explore", load_skills=[], description="Find test patterns", run_in_background=true, prompt="Test patterns: FIND test configs, test structure → REPORT unique conventions")
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
<dynamic-agents>
**DYNAMIC AGENT SPAWNING ** : After bash analysis, spawn ADDITIONAL explore agents based on project scale:
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
| Factor | Threshold | Additional Agents |
|--------|-----------|-------------------|
| **Total files ** | >100 | +1 per 100 files |
| **Total lines ** | >10k | +1 per 10k lines |
| **Directory depth ** | ≥4 | +2 for deep exploration |
| **Large files (>500 lines) ** | >10 files | +1 for complexity hotspots |
| **Monorepo ** | detected | +1 per package/workspace |
| **Multiple languages ** | >1 | +1 per language |
2025-12-28 17:30:27 +09:00
2026-05-28 16:34:17 +09:00
``` bash
2025-12-31 13:40:57 +09:00
# Measure project scale first
total_files = $( find . -type f -not -path '*/node_modules/*' -not -path '*/.git/*' | wc -l)
total_lines = $( find . -type f \\ ( -name "*.ts" -o -name "*.py" -o -name "*.go" \\ ) -not -path '*/node_modules/*' -exec wc -l { } + 2>/dev/null | tail -1 | awk '{print $1}' )
large_files = $( find . -type f \\ ( -name "*.ts" -o -name "*.py" \\ ) -not -path '*/node_modules/*' -exec wc -l { } + 2>/dev/null | awk '$1 > 500 {count++} END {print count+0}' )
max_depth = $( find . -type d -not -path '*/node_modules/*' -not -path '*/.git/*' | awk -F/ '{print NF}' | sort -rn | head -1)
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
Example spawning:
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
// 500 files, 50k lines, depth 6, 15 large files → spawn 5+5+2+1 = 13 additional agents
2026-02-06 16:01:54 +09:00
task(subagent_type="explore", load_skills=[], description="Analyze large files", run_in_background=true, prompt="Large file analysis: FIND files >500 lines, REPORT complexity hotspots")
task(subagent_type="explore", load_skills=[], description="Explore deep modules", run_in_background=true, prompt="Deep modules at depth 4+: FIND hidden patterns, internal conventions")
task(subagent_type="explore", load_skills=[], description="Find shared utilities", run_in_background=true, prompt="Cross-cutting concerns: FIND shared utilities across directories")
2025-12-31 13:40:57 +09:00
// ... more based on calculation
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
</dynamic-agents>
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
### Main Session: Concurrent Analysis
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
**While background agents run ** , main session does:
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
#### 1. Bash Structural Analysis
2026-05-28 16:34:17 +09:00
``` bash
2025-12-31 13:40:57 +09:00
# Directory depth + file counts
find . -type d -not -path '*/\\.*' -not -path '*/node_modules/*' -not -path '*/venv/*' -not -path '*/dist/*' -not -path '*/build/*' | awk -F/ '{print NF-1}' | sort -n | uniq -c
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
# Files per directory (top 30)
find . -type f -not -path '*/\\.*' -not -path '*/node_modules/*' | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -30
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
# Code concentration by extension
find . -type f \\ ( -name "*.py" -o -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.go" -o -name "*.rs" \\ ) -not -path '*/node_modules/*' | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -20
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
# Existing AGENTS.md / CLAUDE.md
2025-12-31 03:55:48 +00:00
find . -type f \\ ( -name "AGENTS.md" -o -name "CLAUDE.md" \\ ) -not -path '*/node_modules/*' 2>/dev/null
2026-05-28 16:34:17 +09:00
```
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
#### 2. Read Existing AGENTS.md
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
For each existing file found:
Read(filePath=file)
Extract: key insights, conventions, anti-patterns
Store in EXISTING_AGENTS map
2026-05-28 16:34:17 +09:00
```
2025-12-28 19:23:29 +09:00
2026-05-28 16:34:17 +09:00
If `--create-new` : Read all existing first (preserve context) → then delete all → regenerate.
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
#### 3. LSP Codemap (if available)
2026-05-28 16:34:17 +09:00
```
2026-01-16 10:40:44 +09:00
LspServers() # Check availability
2025-12-28 19:23:29 +09:00
2025-12-31 13:40:57 +09:00
# Entry points (parallel)
2026-01-16 10:40:44 +09:00
LspDocumentSymbols(filePath="src/index.ts")
LspDocumentSymbols(filePath="main.py")
2025-12-28 19:23:29 +09:00
2025-12-31 13:40:57 +09:00
# Key symbols (parallel)
2026-01-16 10:40:44 +09:00
LspWorkspaceSymbols(filePath=".", query="class")
LspWorkspaceSymbols(filePath=".", query="interface")
LspWorkspaceSymbols(filePath=".", query="function")
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
# Centrality for top exports
2026-01-16 10:40:44 +09:00
LspFindReferences(filePath="...", line=X, character=Y)
2026-05-28 16:34:17 +09:00
```
2025-12-31 03:55:48 +00:00
2025-12-31 13:40:57 +09:00
**LSP Fallback ** : If unavailable, rely on explore agents + AST-grep.
### Collect Background Results
2025-12-31 03:55:48 +00:00
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
// After main session analysis done, collect all task results
2026-05-28 16:34:17 +09:00
for each background task ID (`bg_...`): background_output(task_id="bg_...")
```
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Merge: bash + LSP + existing + explore findings. Mark "discovery" as completed. **
2025-12-28 17:30:27 +09:00
---
2025-12-31 13:40:57 +09:00
## Phase 2: Scoring & Location Decision
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Mark "scoring" as in_progress. **
2025-12-28 17:30:27 +09:00
### Scoring Matrix
2025-12-31 13:40:57 +09:00
| Factor | Weight | High Threshold | Source |
|--------|--------|----------------|--------|
| File count | 3x | >20 | bash |
| Subdir count | 2x | >5 | bash |
| Code ratio | 2x | >70% | bash |
2025-12-28 19:23:29 +09:00
| Unique patterns | 1x | Has own config | explore |
2025-12-31 13:40:57 +09:00
| Module boundary | 2x | Has index.ts/__init__.py | bash |
| Symbol density | 2x | >30 symbols | LSP |
| Export count | 2x | >10 exports | LSP |
| Reference centrality | 3x | >20 refs | LSP |
2025-12-28 17:30:27 +09:00
### Decision Rules
| Score | Action |
|-------|--------|
2025-12-31 13:40:57 +09:00
| **Root (.) ** | ALWAYS create |
| * * >15** | Create AGENTS.md |
| **8-15 ** | Create if distinct domain |
| * * <8** | Skip (parent covers) |
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
### Output
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
AGENTS_LOCATIONS = [
{ path: ".", type: "root" },
2025-12-31 13:40:57 +09:00
{ path: "src/hooks", score: 18, reason: "high complexity" },
{ path: "src/api", score: 12, reason: "distinct domain" }
2025-12-28 17:30:27 +09:00
]
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Mark "scoring" as completed. **
2025-12-28 17:30:27 +09:00
---
2025-12-31 13:40:57 +09:00
## Phase 3: Generate AGENTS.md
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Mark "generate" as in_progress. **
2025-12-28 17:30:27 +09:00
2026-02-06 16:01:54 +09:00
<critical>
2026-05-28 16:34:17 +09:00
**File Writing Rule ** : If AGENTS.md already exists at the target path → use `Edit` tool. If it does NOT exist → use `Write` tool.
NEVER use Write to overwrite an existing file. ALWAYS check existence first via `Read` or discovery results.
2026-02-06 16:01:54 +09:00
</critical>
2025-12-31 13:40:57 +09:00
### Root AGENTS.md (Full Treatment)
2025-12-28 17:30:27 +09:00
2026-05-28 16:34:17 +09:00
``` markdown
2025-12-28 17:30:27 +09:00
# PROJECT KNOWLEDGE BASE
**Generated: ** {TIMESTAMP}
**Commit: ** {SHORT_SHA}
**Branch: ** {BRANCH}
## OVERVIEW
2025-12-31 13:40:57 +09:00
{1-2 sentences: what + core stack}
2025-12-28 17:30:27 +09:00
## STRUCTURE
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
{root}/
├── {dir}/ # {non-obvious purpose only}
└── {entry}
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
## WHERE TO LOOK
| Task | Location | Notes |
|------|----------|-------|
2025-12-28 19:23:29 +09:00
## CODE MAP
2025-12-31 13:40:57 +09:00
{From LSP - skip if unavailable or project <10 files}
2025-12-28 19:23:29 +09:00
| Symbol | Type | Location | Refs | Role |
|--------|------|----------|------|------|
2025-12-28 17:30:27 +09:00
## CONVENTIONS
2025-12-31 13:40:57 +09:00
{ONLY deviations from standard}
2025-12-28 17:30:27 +09:00
## ANTI-PATTERNS (THIS PROJECT)
2025-12-31 13:40:57 +09:00
{Explicitly forbidden here}
2025-12-28 17:30:27 +09:00
## UNIQUE STYLES
2025-12-31 13:40:57 +09:00
{Project-specific}
2025-12-28 17:30:27 +09:00
## COMMANDS
2026-05-28 16:34:17 +09:00
```bash
2025-12-31 13:40:57 +09:00
{dev/test/build}
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
## NOTES
2025-12-31 13:40:57 +09:00
{Gotchas}
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Quality gates**: 50-150 lines, no generic advice, no obvious info.
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
### Subdirectory AGENTS.md (Parallel)
2025-12-28 17:30:27 +09:00
2026-01-20 16:52:31 +09:00
Launch writing tasks for each location:
2025-12-28 17:30:27 +09:00
2026-05-28 16:34:17 +09:00
```
2025-12-31 13:40:57 +09:00
for loc in AGENTS_LOCATIONS (except root):
2026-05-28 16:34:17 +09:00
task(category="writing", load_skills=[], run_in_background=false, description="Generate AGENTS.md", prompt=`
Generate AGENTS.md for: ${loc.path}
- Reason: ${loc.reason}
2025-12-31 13:40:57 +09:00
- 30-80 lines max
- NEVER repeat parent content
- Sections: OVERVIEW (1 line), STRUCTURE (if >5 subdirs), WHERE TO LOOK, CONVENTIONS (if different), ANTI-PATTERNS
2026-05-28 16:34:17 +09:00
` )
```
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Wait for all. Mark "generate" as completed.**
2025-12-28 17:30:27 +09:00
---
2025-12-31 13:40:57 +09:00
## Phase 4: Review & Deduplicate
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Mark "review" as in_progress.**
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
For each generated file:
- Remove generic advice
- Remove parent duplicates
- Trim to size limits
- Verify telegraphic style
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
**Mark "review" as completed.**
2025-12-28 17:30:27 +09:00
---
## Final Report
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
=== init-deep Complete ===
2025-12-31 13:40:57 +09:00
Mode: {update | create-new}
Files:
2026-01-22 22:48:36 +09:00
[OK] ./AGENTS.md (root, {N} lines)
[OK] ./src/hooks/AGENTS.md ({N} lines)
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
Dirs Analyzed: {N}
2025-12-28 17:30:27 +09:00
AGENTS.md Created: {N}
2025-12-31 13:40:57 +09:00
AGENTS.md Updated: {N}
2025-12-28 17:30:27 +09:00
Hierarchy:
./AGENTS.md
2025-12-31 13:40:57 +09:00
└── src/hooks/AGENTS.md
2026-05-28 16:34:17 +09:00
```
2025-12-28 17:30:27 +09:00
---
2025-12-31 13:40:57 +09:00
## Anti-Patterns
2025-12-28 17:30:27 +09:00
2025-12-31 13:40:57 +09:00
- **Static agent count**: MUST vary agents based on project size/depth
- **Sequential execution**: MUST parallel (explore + LSP concurrent)
- **Ignoring existing**: ALWAYS read existing first, even with --create-new
- **Over-documenting**: Not every dir needs AGENTS.md
- **Redundancy**: Child never repeats parent
2025-12-28 17:30:27 +09:00
- **Generic content**: Remove anything that applies to ALL projects
2026-05-28 16:34:17 +09:00
- **Verbose style**: Telegraphic or die