# How to Configure Egonex AI Auto-Update on Every Commit Using Post-Commit Hooks

> Automatically update your Egonex AI knowledge graph on every commit. Learn how to configure post-commit hooks to keep your data synchronized effortlessly.

- Repository: [Egonex/Understand-Anything](https://github.com/Egonex-AI/Understand-Anything)
- Tags: how-to-guide
- Published: 2026-06-20

---

**Enable the `understand --auto-update` flag once per repository, then create an executable `.git/hooks/post-commit` script that invokes this command to keep your knowledge graph synchronized with every commit.**

The Egonex-AI/Understand-Anything plugin maintains a living knowledge graph of your codebase that can grow stale as you iterate. By configuring Egonex AI auto-update on every commit using post-commit hooks, you ensure the graph receives incremental updates immediately after each Git commit, leveraging deterministic fingerprint checks to avoid unnecessary LLM token costs for cosmetic changes.

## Prerequisites and Installation

Before setting up the hook, initialize the auto-update configuration in your repository root.

### Enable the Auto-Update Flag

Run the following command once to write the configuration files under `.understand-anything/`:

```bash
understand --auto-update

```

*This creates the necessary metadata structure and notifies the plugin to check for updates after each commit, as documented in the repository's [`README.md`](https://github.com/Egonex-AI/Understand-Anything/blob/main/README.md).*

## Setting Up the Git Post-Commit Hook

The hook triggers the incremental update workflow defined in [`understand-anything-plugin/hooks/auto-update-prompt.md`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/hooks/auto-update-prompt.md) immediately after Git records a commit.

### Creating the Hook Script

Create a file at `.git/hooks/post-commit` with the following content:

```sh
#!/usr/bin/env sh

# Post-commit hook: trigger Egonex AI incremental graph update

cd "$(git rev-parse --show-toplevel)" || exit 1

understand --auto-update

```

*This script ensures the command runs from the repository root, where the plugin expects to find [`.understand-anything/meta.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/meta.json) and the knowledge graph.*

### Making the Hook Executable

Git ignores hooks without execute permissions. Run:

```bash
chmod +x .git/hooks/post-commit

```

## How the Auto-Update Pipeline Works

When the hook executes, it invokes a zero-token-cost pre-flight sequence before deciding whether to engage LLM agents.

### Commit Detection and Change Collection

The workflow first compares the current `HEAD` commit hash against the value stored in [`.understand-anything/meta.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/meta.json). If they match, the process exits early. Otherwise, it collects changed files using:

```bash
git diff <lastHash>..HEAD --name-only

```

It then filters this list against patterns defined in `.understandignore`, excluding non-source files and build artifacts.

### Fingerprint-Based Change Classification

The `fingerprint-check.mjs` script computes SHA-256 hashes of the affected files and compares them against entries in [`.understand-anything/fingerprints.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/fingerprints.json). This deterministic check classifies changes as **cosmetic** or **structural** without consuming LLM tokens. Cosmetic updates—such as comment changes or whitespace—result only in an updated hash entry in [`meta.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/meta.json).

### Incremental Graph Analysis and Merging

For structural changes, the hook launches the `file-analyzer` agent (and optionally the `architecture-analyzer` agent) defined in [`understand-anything-plugin/agents/file-analyzer.md`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/agents/file-analyzer.md). These agents process only the modified files, then merge the new nodes and edges into the existing [`.understand-anything/knowledge-graph.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/knowledge-graph.json) while preserving all untouched graph data.

## Customizing Ignore Patterns

Create a `.understandignore` file in your repository root to exclude directories like `node_modules` or `dist` from the diff collection. The `ignore-filter.mjs` script applies these rules during the change collection phase, ensuring the auto-update processes only relevant source files.

## Summary

- **Enable the feature** by running `understand --auto-update` once per repository to initialize the configuration.
- **Install the hook** by creating an executable `.git/hooks/post-commit` script that invokes the auto-update command.
- **Leverage fingerprints** stored in [`.understand-anything/fingerprints.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/fingerprints.json) to avoid LLM costs for cosmetic changes.
- **Process only structural changes** using the `file-analyzer` agent, merging updates into the existing knowledge graph.
- **Filter noise** via `.understandignore` to prevent build artifacts from triggering unnecessary analysis.

## Frequently Asked Questions

### What triggers an actual LLM analysis versus a zero-token update?

The fingerprint check in `fingerprint-check.mjs` computes SHA-256 hashes of changed files and compares them to [`.understand-anything/fingerprints.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/fingerprints.json). If the structural signature matches the previous state, the hook updates [`.understand-anything/meta.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/.understand-anything/meta.json) with the new commit hash and exits without invoking LLM agents. Only structural changes—such as modified AST signatures—trigger the `file-analyzer` agent.

### Where does the auto-update logic store its state between commits?

The plugin maintains state in two JSON files under `.understand-anything/`: [`meta.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/meta.json) stores the last analyzed commit hash, while [`fingerprints.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/fingerprints.json) maps file paths to their structural SHA-256 signatures. These files allow the hook to determine exactly which changes occurred since the last update.

### Can I use auto-update in CI/CD pipelines or just locally?

While designed for local development workflows using Git hooks, the `understand --auto-update` command is environment-agnostic. You can invoke it in CI pipelines after checkout to ensure the knowledge graph reflects the exact commit being built, though you must manually manage the `.understand-anything/` directory persistence between CI runs.

### How do I disable auto-update if it slows down my commits?

Remove the `.git/hooks/post-commit` file or rename it to `post-commit.disabled`. Additionally, delete the `.understand-anything/` directory if you wish to remove all cached fingerprints and metadata. The plugin will no longer attempt automatic updates until you re-run `understand --auto-update` and reinstall the hook.