Skip to main content
ClaudeWave
Slash Command161 estrellas del repoactualizado 8d ago

init

The `/init` slash command generates a complete FILETREE.md file for a repository from scratch. Use this command when starting a new filetree documentation for a project, or when you need to rebuild the entire file index. The command checks for existing FILETREE.md files and prompts for confirmation before overwriting, wires project documentation files like CLAUDE.md or AGENTS.md with references, reads the project's canonical language settings, and creates a comprehensive file tree summary following the repository's defined style rules.

Instalar en Claude Code
Copiar
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/nekocode/filetree-skill/HEAD/commands/init.md -o ~/.claude/commands/init.md
Después abre una sesión nueva de Claude Code; el slash command carga automáticamente.

init.md

Generate FILETREE.md from scratch for the current repository.

**First**, read the shared rules at `${CLAUDE_PLUGIN_ROOT}/skills/filetree/SKILL.md` — it defines the summary style, **summary language**, UNCHANGED bias (not used here, but good to internalize for future `/filetree:update` calls), and parallelization strategy.

Conduct this whole command — your own narration AND every summary — in the project's canonical language. Resolve it ONCE per SKILL.md "Summary language" (don't restate the chain here) — `config.language` from step 3's `todo` output wins when set. Its next source is `CLAUDE.md` / `AGENTS.md`: step 2 opens them only on the wire path — reuse that content if it did, else read now.

The manifest path is configurable via `.filetree.json`. The script is the only config parser: take `manifest_path` from the `wire-target` / `todo` output below and use it everywhere this doc says "the manifest" — never assume `FILETREE.md`, never re-parse `.filetree.json` yourself.

## Steps

1. **Offer config, resolve targets, check existing.** Config comes first because it decides where the manifest goes and what gets indexed — it must be settled before anything is built.

   a. **Create the config, then confirm.** If `.filetree.json` does NOT exist, `Write` the default template below (it equals current defaults, so it changes nothing yet). Then use `AskUserQuestion` to ask whether to keep it. **That open prompt is the user's edit window** — while it waits, they can edit the file now on disk (relocate the manifest, add `exclude` / `include`, pin a `language`), and `wire-target` / `todo` below will pick up whatever they save. On **keep**, proceed. On **discard**, delete the file you just created (`python3 -c "import os; os.remove('.filetree.json')"`) and proceed with defaults. If `.filetree.json` ALREADY exists, do nothing here — never create, edit, or remove a pre-existing one (it's the user's, and may already be customized).
      ```json
      {
        "manifest_path": "FILETREE.md",
        "exclude": [],
        "include": [],
        "language": null,
        "commit_guard": true
      }
      ```

   b. Then run `wire-target` — it returns the configured `manifest_path`, `manifest_exists`, and for each of `CLAUDE.md` / `AGENTS.md` `{exists, is_symlink, real_path, wired, matches}`:
      ```bash
      python3 "${CLAUDE_PLUGIN_ROOT}/skills/filetree/scripts/filetree.py" wire-target
      ```
      If `manifest_exists` is `true`, ask the user to confirm overwrite (they likely meant `/filetree:update`); on decline, stop — do not enter step 2. Skip the prompt when `false`.

2. **Wire `CLAUDE.md` / `AGENTS.md`.** Do this **before** `todo` so the manifest captures the post-wire hash; otherwise the first `/filetree:lint` flags the wired file as drifted. Reuse the `wire-target` output from step 1 (these files are often symlinks → editing the link path fails, so always edit `real_path`). Then per file:

   a. **`exists: false`** → skip; do not create.
   b. **Already wired.** Skip when `wired` is `true` — the script found a `## <manifest>` heading, so the section is present however the body was reworded. Otherwise → 2.c. (`matches` is just the raw mention lines, for the 2.d edit preview; don't re-derive the wired decision from it.)
   c. **Otherwise append a dedicated section to `real_path`** (NEVER the link name — Edit refuses to write through a symlink). Read `real_path` in full, then append the template below as a new top-level `##` section at the END (never merged into an existing `## References` / `## 引用`). Before writing: (1) replace every `FILETREE.md` with the configured `manifest_path` — including the `## ` heading, which MUST keep the bare path verbatim (that exact heading is what 2.b's `wired` check re-detects on the next run); (2) render all prose AND the example summaries in the canonical language resolved above, keeping the fenced block's structure.

      `````markdown
      ## FILETREE.md

      `FILETREE.md` indexes every file with a one-line role summary, grouped by
      directory. Read it to find code by purpose before `ls`/`grep`/`find` — it
      turns "search the repo" into "look it up". Auto-maintained; don't hand-edit.

      ```
      ## (root)/

      - `manage.py`: Django CLI entrypoint

      ## src/auth/

      - `jwt.py`: JWT middleware; parses token, injects user_id
      - `session.py`: Redis-backed server-side session store
      ```
      `````
   d. **Confirm via `AskUserQuestion`** before writing. Put the old → new diff in the `question` body or a `preview`. On decline, skip — do not retry. `Edit` `real_path` (use `Write` only on a zero-byte file).

   Record per-file outcome (wired / absent / already-wired / declined) now — sub-agents in step 4 can evict step-2 context. If step 3 or 5 later crashes, the wire section stays on disk; re-running `/filetree:init` is idempotent (step 2.b's `wired` will be `true` and skip).

3. **Generate work plan.** One call; the script chunks and writes the work to files (you never count or split):
   ```bash
   python3 "${CLAUDE_PLUGIN_ROOT}/skills/filetree/scripts/filetree.py" todo --split
   ```
   With no existing manifest, every tracked file is new work, written into the `batches` files (the full `added` / `changed` lists are omitted from `--split` stdout — drive off `batches`). The output also carries the `config` block (`manifest_path`, `language`) — use `config.language` for the canonical language if set. A wired `CLAUDE.md` / `AGENTS.md` shows up with its post-wire hash. (A gitignored one won't appear — wiring still works on disk, but the manifest only tracks files git sees. `exclude`/`include` from `.filetree.json` are already applied.)

4. **Write summaries.** Process the batches per SKILL.md "Processing the work plan" (0 → skip to apply; otherwise spawn one `claude-haiku-4-5` sub-agent per batch — **every batch, including a lone one**; the main session itself never `Read`s a file or writes a summary). For each item a