<codefidence/>

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:

  1. Creates the .wiki/ directory and scans the project to discover domains (same as --scan)
  2. Installs Claude Code hooks (PreToolUse for context surfacing, PostToolUse for drift detection)
  3. Patches CLAUDE.md with wiki instructions
  4. Installs slash commands in .claude/commands/
bash
$ 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.

json
# 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.

json
{
  "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:

  1. Run init --scan and generate-candidates
  2. Promote and confirm at least 3-5 items in your most critical domain
  3. Test with context and check-diff manually
  4. Then install hooks: codefidence init --hooks

Uninstalling Hooks

To remove all hooks without deleting your wiki data:

bash
$ 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.