add claude-obsidian
Tests / Hermetic test suite (push) Has been cancelled
Tests / Skill frontmatter validation (push) Has been cancelled

This commit is contained in:
김경종
2026-05-28 10:57:16 +09:00
parent 1b07531a45
commit 72dad72703
205 changed files with 41703 additions and 80 deletions
+26
View File
@@ -0,0 +1,26 @@
# claude-obsidian Hooks
Plugin hooks for the claude-obsidian wiki vault. All hooks are defined in `hooks.json`.
## Events
| Event | Type | Purpose |
|---|---|---|
| `SessionStart` | command + prompt | Loads `wiki/hot.md` into context. Command type runs `[ -f wiki/hot.md ] && cat wiki/hot.md` as the canonical safety check (works for non-vault sessions without erroring). Prompt type complements with semantic context restoration. Matcher: `startup\|resume`. |
| `PostCompact` | prompt | Re-loads `wiki/hot.md` after context compaction. Hook-injected context does NOT survive compaction (only `CLAUDE.md` does), so this hook restores the hot cache mid-session. |
| `PostToolUse` | command | Auto-commits any wiki/ or .raw/ changes after Write or Edit tool calls. Guarded by `[ -d .git ]` so it never errors in non-git directories, and by `git diff --cached --quiet` so it never creates empty commits. |
| `Stop` | prompt | Updates `wiki/hot.md` at the end of every Claude response with a brief summary of what changed. |
## Known Issue: Plugin Hooks STDOUT Bug
`anthropics/claude-code#10875` documents that **plugin hook STDOUT may not be captured** by Claude Code, while identical inline hooks in `settings.json` work correctly.
**Impact**: If this bug is active in your Claude Code version, the prompt-type SessionStart and PostCompact hooks may not inject context as expected.
**Workaround**: The command-type SessionStart hook (`cat wiki/hot.md`) is the canonical safety check. It relies on STDOUT capture for context injection, so test against this issue if hot cache restoration fails. As a fallback, copy the hook config from `hooks.json` into your user-level `~/.claude/settings.json` instead of relying on plugin hooks.
**Test for the bug**: After installing the plugin, open a fresh Claude Code session in a directory containing a populated `wiki/hot.md`. Ask Claude "what's in the hot cache?". If Claude has no idea, the STDOUT bug is active in your version.
## Non-Vault Sessions
The SessionStart command hook uses `[ -f wiki/hot.md ] && cat wiki/hot.md || true` so it always exits 0, even when no vault is present. This makes the plugin safe to install globally without breaking non-vault Claude Code sessions.
+56
View File
@@ -0,0 +1,56 @@
{
"hooks": {
"SessionStart": [
{
"matcher": "startup|resume",
"hooks": [
{
"type": "command",
"command": "[ -f wiki/hot.md ] && cat wiki/hot.md || true"
},
{
"type": "command",
"command": "[ -x scripts/wiki-lock.sh ] && bash scripts/wiki-lock.sh clear-stale --max-age 3600 >/dev/null 2>&1 || true"
},
{
"type": "prompt",
"prompt": "If a vault is configured for this session (check CLAUDE.md for VAULT_PATH or a wiki/ folder in the current directory), silently read wiki/hot.md to restore recent context. If wiki/hot.md does not exist, do nothing. This is a non-vault session. Do not announce this. Do not report what you read. Just have the context available."
}
]
}
],
"PostCompact": [
{
"matcher": "",
"hooks": [
{
"type": "prompt",
"prompt": "Hook-injected context does not survive context compaction. If wiki/hot.md exists in the current directory, silently re-read it now to restore the hot cache. Do not announce this."
}
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "[ -d .git ] || exit 0; [ -f .vault-meta/auto-commit.disabled ] && exit 0; if [ -x scripts/wiki-lock.sh ]; then LOCK_LIST=$(bash scripts/wiki-lock.sh list 2>/dev/null); LOCK_RC=$?; if [ \"$LOCK_RC\" != \"0\" ]; then mkdir -p .vault-meta 2>/dev/null; printf '%s wiki-lock list failed rc=%s; deferred auto-commit\\n' \"$(date '+%Y-%m-%dT%H:%M:%SZ')\" \"$LOCK_RC\" >> .vault-meta/hook.log 2>/dev/null; exit 0; fi; if [ -n \"$LOCK_LIST\" ]; then exit 0; fi; fi; git add -- wiki/ .raw/ .vault-meta/ 2>/dev/null && (git diff --cached --quiet -- wiki/ .raw/ .vault-meta/ || git commit -m \"wiki: auto-commit $(date '+%Y-%m-%d %H:%M')\" -- wiki/ .raw/ .vault-meta/ 2>/dev/null) || true"
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "cd \"$PWD\" && [ -d wiki ] && [ -d .git ] && git diff --name-only HEAD 2>/dev/null | grep -q '^wiki/' && echo 'WIKI_CHANGED: Wiki pages were modified this session. Please update wiki/hot.md with a brief summary of what changed (under 500 words). Use the hot cache format: Last Updated, Key Recent Facts, Recent Changes, Active Threads. Keep it factual. Overwrite the file completely. It is a cache, not a journal.' || true"
}
]
}
]
}
}