# Claude Code Integration

`llm-wiki-kit` installs command hooks into `~/.claude/settings.json`.

It also syncs the bundled `llm-wiki-*` skills into the personal Claude Code skill root:

```bash
~/.claude/skills/<skill-name>/SKILL.md
```

The installer uses the same conservative policy as Codex skill sync: missing bundled skills are installed, unmanaged same-name active skills are preserved, kit-managed unmodified skills are updated, and locally edited managed active skills are skipped. Obsolete public llm-wiki skills are removed from active skill roots. Use `--no-claude` to skip Claude hooks and Claude skills, or `--no-skills` to leave both Codex and Claude skill roots untouched.

The command target is:

```bash
llm-wiki hook claude <EventName>
```

The installed hook stores the Node executable and the absolute package binary path. A system-wide npm install usually points at:

```bash
/usr/lib/node_modules/llm-wiki-kit/bin/llm-wiki.js
```

User-local fallback installs may instead point under `$HOME/.local/lib/node_modules`.

Handled events on compatible Claude Code versions:

- `SessionStart`
- `InstructionsLoaded`
- `UserPromptSubmit`
- `PreToolUse`
- `PostToolUse`
- `PostToolBatch`
- `PreCompact`
- `PostCompact`
- `SubagentStop`
- `Stop`
- `SessionEnd`

`llm-wiki install` detects `claude --version` and installs a conservative event set when the local Claude Code binary is older or cannot be detected. `SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `PreCompact`, `PostCompact`, `SubagentStop`, and `Stop` are treated as the stable set. `InstructionsLoaded`, `PostToolBatch`, and `SessionEnd` are installed only for newer compatible versions, or when `LLM_WIKI_KIT_CLAUDE_MODERN_HOOKS=1` is set. Existing kit-managed hooks for unsupported event keys are removed during install so Claude Code does not skip the entire settings file with an “Invalid key in record” error.

Claude Code reads `CLAUDE.md`. For project compatibility, the kit creates a `CLAUDE.md` stub containing:

```text
@AGENTS.md
```

when no project `CLAUDE.md` exists. Existing `CLAUDE.md` files are not overwritten.

The hook records redacted turn summaries but does not deny tool calls only because an input looks sensitive. Hook payloads are stored as small redacted event envelopes rather than full transcripts, and context output is redacted field by field before it is returned to Claude Code.

In an explicitly initialized project, `SessionStart`/`InstructionsLoaded` may recover queue-worthy stale turn state, perform a cached npm update notice check for npm installs, report managed-template or maintenance drift, and inject functional compact context. They do not bootstrap a workspace, refresh templates, remove legacy files, migrate layouts, or apply lifecycle changes. At `UserPromptSubmit`, the hook may recover queue-worthy stale turn state, search wiki pages, expand one-hop wikilinks, redact context fields, perform the same cached update notice check, and inject the smallest useful context set. Verbose `llm-wiki context` can explain `why selected`, `rankReason`, `matchedFields`, and `evidenceRefs`, but hook context keeps those details compact. Update notice cache is scoped by npm command, and maintenance reminders are shown only for wiki/maintenance prompts, approved items, explicit durable requests, recovered items, or batch review threshold pressure.

Hook-visible language is selected from the current real user prompt first. Korean prompts get Korean guidance, English prompts get English guidance. Neutral prompts can reuse remembered session language or project `preferredLanguage`; then the hook checks Claude Code `settings.json` `language` when it exists, local `CLAUDE.md`/`AGENTS.md` language signals, and finally English. The kit does not require Claude Code to expose a language setting.

`PostToolUse` and `PostToolBatch` record redacted tool summaries in the same turn buffer. `PreCompact` classifies the current turn before compaction: non-durable turns stay in transient runtime state; explicit durable requests, structured durable conclusions with required evidence, and durable wiki/procedure updates write a chunked live Q&A checkpoint; explicit/structured durable candidates write a maintenance queue item only when no durable wiki/procedure update is detected. Queue items carry `signal_level` and may carry safe `evidence_refs` candidates from actual repo files and verification commands. `PreCompact` never opens `transcript_path`; checkpoints are built only from bounded, redacted turn state captured by hook events. Compaction is not blocked; if checkpoint storage fails, the hook records a transient compact recovery packet for the next legal context-injection event. `PostCompact` keeps its summary transient and prepares any pending recovery packet without writing `wiki/context/` or returning model-visible context directly. In the default `answer-first` mode, `SubagentStop` does not create live Q&A, query, decision, or maintenance files. `Stop` and `SessionEnd` append chunked live Q&A only for explicit durable requests, structured durable conclusions with required evidence, or durable wiki/procedure updates and do not auto-create `wiki/queries/` or `wiki/decisions/`. If the captured user question explicitly asked to record durable knowledge, or the turn contains a structured durable conclusion, and no durable wiki/procedure update is detected, `Stop`/`SessionEnd` queues a pending maintenance item for batch review. `wiki/queries/` updates are episodic and do not suppress this queue. The lifecycle keeps candidates pending for batch review, skips stale low-signal items, and archives old reviewed items, but it never creates durable wiki pages automatically or auto-approves promotion. Prompt-time reminders are limited to explicit durable requests, recovered state, maintenance prompts, approved items, or batch thresholds. `Stop` and `SessionEnd` then clear the per-session turn buffer; `SubagentStop` does not.

Provider events without a stable session or conversation identifier fail closed for transient continuity: they do not read or write a shared fallback turn, compact, language, or recovery record.

For handoff or retrieval verification, use `llm-wiki export --workspace <project> --format all` and `llm-wiki eval --workspace <project>`. The generated `llms.txt`/`llms-full.txt`/`llm-wiki.json` files are redacted durable manifests, not raw transcripts.

Managed-template refresh is explicit through `post-update` or `install`; routine hooks only report drift.
Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only while suppressing the cached passive runtime update status.

Set `LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT=off` to suppress pre-compact failure warnings; `limited` and `soft` both keep compaction moving and emit a non-blocking warning when checkpoint/queue preservation fails. Transcript-tail capture is not supported.

After installation or update, run:

```bash
llm-wiki status --workspace /path/to/project
llm-wiki doctor --workspace /path/to/project
```

Confirm `llm-wiki status` reports the Claude skill root as current, then restart Claude Code so it reloads hook settings.
