Skip to main content
The commit workflow runs locally on your machine as a post-commit hook. When you include [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-cli installed globally (npm install -g @moxn/context-cli)
  • A git hooks mechanism — Husky is one option, or use .git/hooks/post-commit directly
  • A Moxn API key set in your environment or .env.local
  • An Anthropic API key (ANTHROPIC_API_KEY env 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
The CLI loads .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
Make it executable:
If you’re not using Husky, add the same script to .git/hooks/post-commit directly. The logic is the same — it just won’t be version-controlled.

Usage

Add [docs] anywhere in your commit message to trigger auto-docs:
You’ll see:
Your terminal returns immediately. Claude runs in the background and writes output to a log file at /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:
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 run commit-sync directly without the hook:

Reviewing Changes

After the background process completes, find the changeset in your KB:
  1. Go to Knowledge Base > Changesets in the Moxn web app
  2. Find the changeset titled “Docs: commit {hash}”
  3. Review the documents and their content on the branch
  4. Click Merge All to land the docs on main
Run context commit-sync --dry-run first to see what prompts Claude would receive. This is useful for tuning your integration’s prompt template.