agentleFS
vatevstoilvatevstoil/claude-self-learning-os/skills/four-layer-init/SKILL.md

four-layer-init

Skill4 starsChanged 5 months agoMITView on GitHub

Bootstrap a new project with the full 4-layer memory architecture (Pinecone + Obsidian Wiki + GitNexus + CLAUDE.md). Use when user says "setup 4-layer for <project>", "add memory architecture", "onboard <project> to memory ecosystem", "init memory for new project", or similar. Creates reproducible infrastructure that cuts session startup tokens 40-180x across projects.

  • Reads credentials
  • Installs packages

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If any MISSING → see "Initial global setup" at the bottom.

    line 34
  2. Very specific:

    If {{WIKI_PATH}}\<ProjectName>\wiki\ doesn't exist:

    line 77
  3. Distinctive:

    Add this block near the top:

    line 106
  4. Distinctive:

    After Step 7, run these and expect all green:

    line 136
  5. Very specific:

    Create index named memory with:

    line 193
  6. Very specific:

    Ensure contains .env and *.key so credentials never leak.

    line 226
  7. Distinctive:

    Run this skill once per project.

    line 255

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Four-Layer Memory — Project Bootstrap

Reference architecture: {{RESEARCH_PATH}}\Claude Code Resurch\wiki\concepts\Graphify-vs-GitNexus.md Session protocol: ~/.claude/references/session-start.md

Goal: Apply the 4-layer memory stack to ANY project so every session starts with ~5k tokens instead of 400k+.

When to Invoke

Trigger on phrases like:

  • "Setup 4-layer for StroyOffice"
  • "Onboard <project> to memory architecture"
  • "Init GitNexus + Pinecone for <project>"
  • "Apply the memory ecosystem"

Prerequisites Check (run BEFORE onboarding)

# 1. GitNexus installed globally?
gitnexus --version   # should return 1.6.1+

# 2. Pinecone credentials in ~/.claude/.env?
test -f ~/.claude/.env && grep -q PINECONE_API_KEY ~/.claude/.env && echo OK || echo MISSING

# 3. Pinecone wrapper script present?
test -f ~/.claude/scripts/pinecone.py && echo OK || echo MISSING

If any MISSING → see "Initial global setup" at the bottom.

The 7-Step Project Onboarding

Step 1 — Project path + name (ask user)

Project path:   {{CODE_PATH}}\<ProjectName>
Wiki path:      {{WIKI_PATH}}\<ProjectName>\wiki
Pinecone ns:    <ProjectName>           (case-exact, matches folder name)

Step 2 — GitNexus analyze + verify

cd "{{CODE_PATH}}\<ProjectName>"
gitnexus analyze    # ~1-2 min depending on size
gitnexus status     # must show ✅ up-to-date
gitnexus list       # verify project appears in global registry

Expected output: N nodes + M edges. For most projects: 5k–50k nodes.

Step 3 — Git post-commit hook (auto re-index)

cat > .git/hooks/post-commit << 'EOF'
#!/bin/sh
# Auto re-index GitNexus graph after each commit (async, non-blocking).
command -v gitnexus >/dev/null 2>&1 || exit 0
(
  cd "$(git rev-parse --show-toplevel)" && \
  gitnexus analyze > "$TMPDIR/gitnexus-reindex.log" 2>&1 &
) >/dev/null 2>&1
exit 0
EOF
chmod +x .git/hooks/post-commit

⚠ Hooks do NOT copy between git worktrees — re-install per worktree if needed.

Step 4 — Obsidian Wiki structure (Karpathy method)

If {{WIKI_PATH}}\<ProjectName>\wiki\ doesn't exist:

python ~/.claude/skills/dev-wiki/scripts/init_dev_wiki.py --project "<ProjectName>"

Otherwise verify structure:

{{WIKI_PATH}}\<ProjectName>\wiki\
├── index.md          ← Navigation + TOC (<100 lines)
├── SPRINT.md         ← Active sprint (<60 lines)
├── concepts/         ← Cross-cutting patterns
├── sources/          ← Referenced research/docs
├── archive/          ← Completed sprints
└── graph/
    └── knowledge_graph.json   ← Graphify output (L2a)

Premium visual: dev wikis live INSIDE the big {{WIKI_PATH}} vault, which already carries the premium style (gold/dark snippet + project-colored graph) — so a new project subfolder inherits it automatically; do NOT create a nested .obsidian/. ONLY if this project is a standalone vault (its own .obsidian/, e.g. Fakturka.bg / DCTL), style it once:

python ~/.claude/scripts/obsidian_premium_viz.py "{{WIKI_PATH}}\<ProjectName>"

Step 5 — Update project CLAUDE.md (<100 lines)

Add this block near the top:

## 4-Layer Memory (see ~/.claude/references/session-start.md)
- **L4 Pinecone**: `python3 ~/.claude/scripts/pinecone.py query "<ProjectName>" "<q>"`
- **L3 Wiki**: `{{WIKI_PATH}}\<ProjectName>\wiki\`
- **L2b GitNexus**: MCP auto + 7 skills (impact(), pr-review, refactoring, ...)
- **L2a Graphify**: `wiki/graph/knowledge_graph.json` (run `/graphify` if stale)
- **L1**: this CLAUDE.md + `/clear` at 50% context

Step 6 — Graphify JSON (optional, only if project >50 files)

/graphify

Outputs {{WIKI_PATH}}\<ProjectName>\wiki\graph\knowledge_graph.json.

Step 7 — Save initial project summary to Pinecone

python3 ~/.claude/scripts/pinecone.py save "<ProjectName>" \
  "onboarding-$(date +%Y-%m-%d)" \
  "<ProjectName> onboarded to 4-layer memory architecture on $(date +%Y-%m-%d). Stack: <tech-stack>. Main purpose: <one-sentence>. Wiki at {{WIKI_PATH}}\<ProjectName>\wiki\. GitNexus indexed with N nodes. Pinecone namespace: <ProjectName>." \
  --meta "project=<ProjectName>,type=onboarding,date=$(date +%Y-%m-%d)"

Verification Checklist

After Step 7, run these and expect all green:

# 1. GitNexus fresh
cd "{{CODE_PATH}}\<ProjectName>" && gitnexus status | grep -q "up-to-date" && echo "✓ L2b"

# 2. Post-commit hook active
test -x .git/hooks/post-commit && echo "✓ hook"

# 3. Wiki structure
test -f "{{WIKI_PATH}}\<ProjectName>\wiki\index.md" && echo "✓ L3"

# 4. Graphify JSON (if Step 6 done)
test -f "{{WIKI_PATH}}\<ProjectName>\wiki\graph\knowledge_graph.json" && echo "✓ L2a"

# 5. Pinecone writable
python3 ~/.claude/scripts/pinecone.py query "<ProjectName>" "onboarding" --topk 1 | grep -q "onboarding" && echo "✓ L4"

# 6. CLAUDE.md updated
grep -q "4-Layer Memory" "{{CODE_PATH}}\<ProjectName>\CLAUDE.md" && echo "✓ L1"

Output Template (report to user)

✅ <ProjectName> onboarded to 4-layer architecture

| Layer | Status |
|-------|--------|
| L1 CLAUDE.md | updated with 4-layer block |
| L2a Graphify | <fresh/deferred> |
| L2b GitNexus | <N> nodes, <M> edges, ✅ fresh |
| L3 Wiki | {{WIKI_PATH}}\<ProjectName>\wiki\ |
| L4 Pinecone | namespace "<ProjectName>", onboarding saved |

Next sessions will start at ~5k tokens instead of 400k+.
To continue: "Recall last <ProjectName> session"
→ will trigger pinecone.py query + wiki/SPRINT.md read.

Initial Global Setup (one-time, if prerequisites missing)

Install GitNexus globally

# On Windows with npm 11.x bug (Cannot destructure property 'package'):
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\npm-cache\_npx"
npm cache clean --force
npm install -g gitnexus
gitnexus setup    # auto-configs Claude Code MCP + 7 skills + PreToolUse/PostToolUse hooks

Pinecone credentials

  1. Get API key from https://pinecone.io (free tier)
  2. Create index named memory with:
    • dim: 1024
    • metric: cosine
    • model: multilingual-e5-large
  3. Save to ~/.claude/.env:
PINECONE_API_KEY=pcsk_xxxxx
PINECONE_INDEX_HOST=memory-<hash>.svc.<region>.pinecone.io
PINECONE_INDEX_NAME=memory
PINECONE_EMBED_MODEL=multilingual-e5-large
PINECONE_DIMENSION=1024
  1. chmod 600 ~/.claude/.env
  2. Verify:
python3 ~/.claude/scripts/pinecone.py query "test" "hello" --topk 1

Pinecone CLI wrapper

Already at ~/.claude/scripts/pinecone.py — if missing, regenerate via:

Tell Claude: "Re-create pinecone.py CLI wrapper at ~/.claude/scripts/"

Wrapper auto-loads ~/.claude/.env, supports save | query | list | delete per namespace.

~/.claude/.gitignore

Ensure contains .env and *.key so credentials never leak.


Token Savings — Expected Impact

WorkflowBeforeAfterSavings
Session startup30–50k tokens~5k10x
Refactor impact analysis20k+ grep tokens~500 (gitnexus impact)40x
Cross-session recallre-read history~300 (pinecone query)∞
Codebase overview new session50k+ reads~2.6k (Graphify JSON)20x
Typical active session total500k–1M~25k~40x

Supported Projects (one-time onboarding required)

Each project gets its own Pinecone namespace, wiki folder, and gitnexus index:

{{CODE_PATH}}\Facturka.bg          → namespace: "Fakturka.bg"      ✅ onboarded 2026-04-17
{{CODE_PATH}}\StroyOffice-Pro      → namespace: "StroyOffice"      ⚪ pending
{{CODE_PATH}}\Higgsfield           → namespace: "Higgsfield"       ⚪ pending
{{CODE_PATH}}\Cinemind             → namespace: "Cinemind"         ⚪ pending
{{CODE_PATH}}\CasinoScore-AI       → namespace: "CasinoScore"      ⚪ pending
...

Run this skill once per project; then just use the normal session-start protocol.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.