Claude Code Integration
codefidence was built with Claude Code in mind. The integration hooks ensure that your AI assistant gets the right context before every edit and catches drift after every write.
What init --full Does
The --full flag is the all-in-one setup.
It performs four steps in sequence:
- Creates the
.wiki/directory and scans the project to discover domains (same as--scan) - Installs Claude Code hooks (PreToolUse for context surfacing, PostToolUse for drift detection)
- Patches CLAUDE.md with wiki instructions
- Installs slash commands in
.claude/commands/
$ codefidence init --full
✔ Created .wiki/ directory
✔ Scanned project structure
✔ Discovered 4 domains
✔ Installed PreToolUse hook (context --hook)
✔ Installed PostToolUse hook (detect-drift --hook)
✔ Patched CLAUDE.md with wiki instructions
✔ Installed slash commands PreToolUse Hook
The PreToolUse hook runs codefidence context --hook before
Claude Code performs file edits. It intercepts tool calls like Edit,
Write, and MultiEdit, extracts the target file path,
and returns relevant memory items as structured context.
This means Claude Code sees warnings like "never call processPayment twice" right before it edits the payment service, without the developer needing to prompt for it.
# Hook configuration in .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"command": "codefidence context --hook"
}
]
}
} PostToolUse Hook
The PostToolUse hook runs codefidence detect-drift --hook
after file writes. It compares the changes against active memory items and flags potential drift.
If a write violates a known exception or contradicts a business rule, the hook returns a warning that Claude Code surfaces in the conversation.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"command": "codefidence detect-drift --hook"
}
]
}
} CLAUDE.md Patching
The init process appends a section to your project's CLAUDE.md
that instructs Claude Code about the wiki's existence and how to use it. This includes:
- A pointer to the
.wiki/directory - Instructions to check context before editing domain-sensitive files
- The golden rule: if the wiki contradicts the code, the code wins
- How to use slash commands for quick wiki lookups
When to Install Hooks
Install hooks after you have useful memory items in the wiki. Hooks with an empty wiki add overhead with no benefit. The recommended sequence:
- Run
init --scanandgenerate-candidates - Promote and confirm at least 3-5 items in your most critical domain
- Test with
contextandcheck-diffmanually - Then install hooks:
codefidence init --hooks
Uninstalling Hooks
To remove all hooks without deleting your wiki data:
$ codefidence uninstall-hooks
✔ Removed PreToolUse hook
✔ Removed PostToolUse hook
✔ Cleaned CLAUDE.md patch
✔ Wiki data in .wiki/ preserved
Your memory items and domain notes remain intact. You can reinstall hooks at any time with
init --hooks.