Init new

From lza6/Armor-piercing-system-prompts · View interactive version

Init new is an AI agent skill from the GitHub repository lza6/Armor-piercing-system-prompts. Initialize new CLAUDE.md file(s) and optional skills/hooks with codebase documentation

How to use this skill

Skill file

Set up a minimal CLAUDE.md (and optionally skills and hooks) for this repo. CLAUDE.md is loaded into every Claude Code session, so it must be concise — only include what Claude would get wrong without it.

Phase 0: Check for an existing CLAUDE.md

Before asking anything, check if CLAUDE.md already exists at the project root (just cat ./CLAUDE.md — only the project-root file counts; don't explore the tree yet). This branches Phase 1.

Phase 1: Ask what to set up

Use AskUserQuestion to find out what the user wants. Which question you ask depends on Phase 0. Call AskUserQuestion with only Q1 — do NOT include Q2 in the same call. Only ask Q2 after you've seen the Q1 answer, since "Let Claude decide" skips it.

Before the first question, print this primer as normal assistant text so first-time users know the terms:

Quick context:

- CLAUDE.md files give Claude persistent instructions for a project, your personal workflow, or your organization. Claude reads them at the start of every session.

- Skills are packaged instructions Claude invokes automatically when a task matches, or that you trigger with a slash command (e.g. /frontend-design, /commit-push-pr).

- Hooks allow you to run shell commands automatically on lifecycle events: get notified when Claude is blocked on your input, auto-format after edits, enforce checks before commits — these are deterministic and Claude can't skip them.

If CLAUDE.md already exists, ask:

Options: "Review and improve it" | "Leave it, set up other things" | "Start fresh (replace it)"

Description for improve: "Explore what's changed in the codebase and propose targeted edits to the existing file."

Description for leave it: "Skip CLAUDE.md. Go straight to skills and hooks."

Description for start fresh: "Discard it and write new file(s)."

Routing:

If no CLAUDE.md exists (or the user picked "Start fresh"), ask:

Options: "Project CLAUDE.md" | "Personal CLAUDE.local.md" | "Both project + personal" | "Let Claude decide"

Description for project: "Team-shared instructions checked into source control — architecture, coding standards, common workflows."

Description for personal: "Your private preferences for this project (gitignored, not shared) — your role, sandbox URLs, preferred test data, workflow quirks."

Description for Let Claude decide: "Fastest path — project CLAUDE.md plus whatever skills or hooks fit this repo. No follow-on questions; you'll approve everything before it's written."

If the user picks "Let Claude decide", skip Q2 — treat it as project CLAUDE.md with no skills/hooks constraint.

Options: "Skills + hooks" | "Skills only" | "Hooks only" | "Neither, just CLAUDE.md"

Description for skills: "Packaged instructions Claude invokes automatically when a task matches, or that you trigger with a slash command (e.g. /frontend-design, /commit-push-pr)."

Description for hooks: "Deterministic shell commands that run on tool events (e.g., format after every edit). Claude can't skip them."

Q2 is a hint, not a filter — Phase 3 proposes what fits the codebase and notes any deviation.

Phase 2: Explore the codebase

Launch a subagent to survey the codebase, and ask it to read key files to understand the project: manifest files (package.json, Cargo.toml, pyproject.toml, go.mod, pom.xml, etc.), README, Makefile/build configs, CI config, existing CLAUDE.md, .claude/rules/, AGENTS.md, .cursor/rules or .cursorrules, .github/copilot-instructions.md, .devin/rules/ or .windsurf/rules/ or .windsurfrules, .clinerules, .mcp.json.

Also have the subagent do a cheap presence check (not a read — the contents are handled by the import adapters) for:

Record which of these exist — Phase 8 uses it.

Detect:

Note what you could NOT figure out from code alone — these become interview questions.

Phase 3: Fill in the gaps

Use AskUserQuestion to gather what you still need to write good CLAUDE.md files and skills. Ask only things the code can't answer.

If the user chose project CLAUDE.md, both, or "Let Claude decide": ask about codebase practices — non-obvious commands, gotchas, branch/PR conventions, required env setup, testing quirks. Skip things already in README or obvious from manifest files. Do not mark any options as "recommended" — this is about how their team works, not best practices.

If the user chose personal CLAUDE.local.md or both: ask about them, not the codebase. Do not mark any options as "recommended" — this is about their personal preferences, not best practices. Examples of questions:

If the user picked "Review and improve" in Phase 0: ask just one question — "Has anything changed about how the team works since this CLAUDE.md was written (new conventions, commands, gotchas)?" with options "No, nothing's changed" | "Yes — let me describe". If they pick Yes, ask what changed (free text) before continuing. Then skip to Phase 4.

Synthesize a proposal from Phase 2 findings and the gap-fill answers. For each item, pick the artifact type that fits the evidence:

Include the CLAUDE.md file(s) implied by Q1 (project, personal, both, or "Let Claude decide" → project) as the first bullet(s) of the proposal, with a one-line summary of what each will cover. Then list skills/hooks/notes. On the "Leave it" path, omit CLAUDE.md file bullets and notes (Phase 4 won't run). On the "Start fresh" path with Q1 = personal-only, add a bullet noting the existing project CLAUDE.md will be left untouched (they chose not to replace it with a project file).

Propose what fits. If the user gave a Q2 hint and your proposal deviates from it (e.g. they said "Hooks only" but nothing hook-shaped exists), say so in one line at the top of the proposal and propose the better-fitting artifacts anyway.

Print the proposal as normal assistant text, one bullet per item:

Here's what I'd set up:

• [Artifact type: file/hook/skill/note] — [one-line description]

• …

Then call AskUserQuestion with a simple question ("Does this look right?") and options like "Looks good — proceed" | "Drop the hook" | "Drop the skill". Don't use the preview field — the proposal is already visible in scrollback. The tool auto-adds an "Other" option for custom tweaks.

Build the preference queue from the accepted proposal. Each entry: {type: hook|skill|note, description, target file, any Phase-2-sourced details like the actual test/format command}. Phase 6 and Phase 7's hooks sub-bullet consume this queue; Phases 4/5 gate on the approved proposal's file bullets directly; Phase 7's GitHub-CLI and linting checks run regardless of queue contents.

Phase 4: Write CLAUDE.md (if the approved proposal includes it, or on the "Review and improve" path)

Write a minimal CLAUDE.md at the project root. Every line must pass this test: "Would removing this cause Claude to make mistakes?" If no, cut it.

If the user picked "Review and improve it" in Phase 0: don't write fresh — read the existing file, compare against Phase 2 findings and the Phase 3-lite answer, and propose specific additions/removals as diffs with a one-line reason for each. The existing file is the baseline; your job is to catch what's missing, outdated, or bloated. After printing the diffs, call AskUserQuestion ("Apply these edits?" with options like "Apply all" | "Let me pick which" | "Skip — leave it as is") before writing anything.

Consume note entries from the Phase 3 preference queue whose target is CLAUDE.md (team-level notes) — add each as a concise line in the most relevant section. These are the behaviors the user wants Claude to follow but didn't need guaranteed (e.g., "propose a plan before implementing", "explain the tradeoffs when refactoring"). Leave personal-targeted notes for Phase 5.

Include:

Exclude:

Be specific: "Use 2-space indentation in TypeScript" is better than "Format code properly."

Do not repeat yourself and do not make up sections like "Common Development Tasks" or "Tips for Development" — only include information expressly found in files you read.

Prefix the file with:

# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

For projects with multiple concerns, suggest organizing instructions into .claude/rules/ as separate focused files (e.g., code-style.md, testing.md, security.md). These are loaded automatically alongside CLAUDE.md and can be scoped to specific file paths using paths frontmatter.

For projects with distinct subdirectories (monorepos, multi-module projects, etc.): mention that subdirectory CLAUDE.md files can be added for module-specific instructions (they're loaded automatically when Claude works in those directories). Offer to create them if the user wants.

Phase 5: Write CLAUDE.local.md (if the approved proposal includes it)

Write a minimal CLAUDE.local.md at the project root. This file is automatically loaded alongside CLAUDE.md. After creating it, add CLAUDE.local.md to the project's .gitignore so it stays private.

Consume note entries from the Phase 3 preference queue whose target is CLAUDE.local.md (personal-level notes) — add each as a concise line. If the user chose personal-only in Phase 1, this is the sole consumer of note entries.

Include:

Keep it short — only include what would make Claude's responses noticeably better for this user.

If Phase 2 found multiple git worktrees and the user confirmed they use sibling/external worktrees (not nested inside the main repo): the upward file walk won't find a single CLAUDE.local.md from all worktrees. Write the actual personal content to ~/.claude/<project-name>-instructions.md and make CLAUDE.local.md a one-line stub that imports it: @~/.claude/<project-name>-instructions.md. The user can copy this one-line stub to each sibling worktree. Never put this import in the project CLAUDE.md. If worktrees are nested inside the main repo (e.g., .claude/worktrees/), no special handling is needed — the main repo's CLAUDE.local.md is found automatically.

If CLAUDE.local.md already exists: read it, propose specific additions, and do not silently overwrite.

Phase 6: Suggest and create skills (if the approved proposal includes any)

Skills add capabilities Claude can use on demand without bloating every session.

First, consume skill entries from the Phase 3 preference queue. Each queued skill preference becomes a SKILL.md tailored to what the user described. For each:

Then suggest additional skills beyond the queue when you find:

For each suggested skill, provide: name, one-line purpose, and why it fits this repo.

If .claude/skills/ already exists with skills, review them first. Do not overwrite existing skills — only propose new ones that complement what is already there.

Create each skill at .claude/skills/<skill-name>/SKILL.md:

---
name: <skill-name>
description: <what the skill does and when to use it>
---

<Instructions for Claude>

Both the user (/<skill-name>) and Claude can invoke skills by default. For workflows with side effects (e.g., /deploy, /fix-issue 123), add disable-model-invocation: true so only the user can trigger it, and use $ARGUMENTS to accept input.

Phase 7: Suggest additional optimizations

Tell the user you're going to suggest a few additional optimizations now that CLAUDE.md and skills (if chosen) are in place.

Check the environment and ask about each gap you find (use AskUserQuestion):

For each hook preference (from the queue or the formatter fallback):

1. Target file: default based on the Phase 1 CLAUDE.md choice — project → .claude/settings.json (team-shared, committed); personal → .claude/settings.local.json. Only ask if the user chose "both" in Phase 1 or the preference is ambiguous. Ask once for all hooks, not per-hook.

2. Pick the event and matcher from the preference:

Probe if the preference is ambiguous.

3. Load the hook reference (once per /init run, before the first hook): invoke the Skill tool with skill: 'update-config' and args starting with [hooks-only] followed by a one-line summary of what you're building — e.g., [hooks-only] Constructing a PostToolUse/Write|Edit format hook for .claude/settings.json using ruff. This loads the hooks schema and verification flow into context. Subsequent hooks reuse it — don't re-invoke.

4. Follow the skill's "Constructing a Hook" flow: dedup check → construct for THIS project → pipe-test raw → wrap → write JSON → jq -e validate → live-proof (for Pre|PostToolUse on triggerable matchers) → cleanup → handoff. Target file and event/matcher come from steps 1–2 above.

Act on each "yes" before moving on.

Phase 8: Summary and next steps

Recap what was set up — which files were written and the key points included in each. Remind the user these files are a starting point: they should review and tweak them, and can run /init again anytime to re-scan.

Then tell the user that you'll be introducing a few more suggestions for optimizing their codebase and Claude Code setup based on what you found. Present these as a single, well-formatted to-do list where every item is relevant to this repo. Put the most impactful items first.

When building the list, work through these checks and include only what applies:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.