[docs] in your commit message, the hook detects the tag and spawns Claude Code in the background to review the diff and update your Knowledge Base.
The commit succeeds immediately — Claude runs in a detached background process and creates a changeset for you to review later.
Prerequisites
@moxn/context-cliinstalled globally (npm install -g @moxn/context-cli)- A git hooks mechanism — Husky is one option, or use
.git/hooks/post-commitdirectly - A Moxn API key set in your environment or
.env.local - An Anthropic API key (
ANTHROPIC_API_KEYenv var) - An integration configured in Moxn for your repository
Setup
1. Install the CLI
2. Set Your API Key
Add your Moxn API key to.env.local in your project root:
.env.local
.env.local automatically. You can also set MOXN_API_KEY as a shell environment variable.
The priority order is:
--api-key flag > environment variable > .env.local > .env. Use .env.local for local dev — it’s gitignored and machine-specific.3. Add the Post-Commit Hook
Create.husky/post-commit in your project:
.husky/post-commit
Usage
Add[docs] anywhere in your commit message to trigger auto-docs:
/tmp/moxn-commit-sync-<hash>-<timestamp>.log.
Commits Without [docs]
Regular commits are unaffected — the hook exits instantly with zero overhead:
Skipping the Hook
Standard git mechanisms work:How It Works
Branch Strategy
The commit workflow maps git branches to KB branches:| Git branch | KB branch | Changeset target | Rationale |
|---|---|---|---|
main or master | staging | main | Docs go to a staging area since main has no PR to merge from |
feature/auth | feature/auth | main | Mirrors the git branch, just like the PR workflow |
fix/rate-limit | fix/rate-limit | main | Same — branch names match 1:1 |
When you’re on
main, docs are created on a staging KB branch. This gives you a review step before they land on main in the KB. Merge the changeset when you’re satisfied.CLI Reference
You can also runcommit-sync directly without the hook:
| Flag | Default | Description |
|---|---|---|
--background | false | Run Claude in a detached process. Logs to /tmp/moxn-commit-sync-<hash>-<ts>.log |
--dry-run | false | Print system and user prompts, do not run Claude |
--repo | auto-detected | Override the repository name (parsed from git remote) |
--max-turns | 50 | Maximum Claude Code turns |
--model | default | Claude model to use (e.g., sonnet, opus) |
Reviewing Changes
After the background process completes, find the changeset in your KB:- Go to Knowledge Base > Changesets in the Moxn web app
- Find the changeset titled “Docs: commit {hash}”
- Review the documents and their content on the branch
- Click Merge All to land the docs on main