# How to Install Graphify Git Hooks: Complete Setup Guide

> Install Graphify Git hooks with a single command to automatically update your knowledge graph after every commit. Follow our easy setup guide for Graphify-Labs graphify.

- Repository: [Graphify Labs/graphify](https://github.com/Graphify-Labs/graphify)
- Tags: how-to-guide
- Published: 2026-07-16

---

**Run `graphify hook install` from your repository root to create a post-commit hook that automatically rebuilds your knowledge graph after every commit.**

The Graphify-Labs/graphify repository provides a lightweight Git hook system that keeps your knowledge graph synchronized without requiring a background daemon. Installing Graphify Git hooks enables automatic AST extraction and graph rebuilding immediately after each commit, ensuring your [`graph.json`](https://github.com/Graphify-Labs/graphify/blob/main/graph.json) and [`GRAPH_REPORT.md`](https://github.com/Graphify-Labs/graphify/blob/main/GRAPH_REPORT.md) always reflect the latest code changes.

## What Are Graphify Git Hooks?

Graphify implements a **post-commit** hook that triggers after every `git commit` command. Unlike traditional background services, this hook operates synchronously using standard Git mechanics. When activated, it executes `git diff HEAD~1` to identify changed source files, then re-runs AST extraction on those specific files before rebuilding the graph artifacts.

The hook system is designed to ignore documentation files such as images and markdown docs, focusing exclusively on code changes. For documentation updates, you can manually trigger refreshes using `graphify --update`.

## Prerequisites

Before installing Graphify Git hooks, ensure you have:

- A Git repository initialized at your project root
- Graphify CLI installed and accessible in your PATH
- Write permissions to the `.git/hooks/` directory

## Installing the Graphify Git Hook

### Basic Installation

To install the hook, navigate to your repository root and execute:

```bash
graphify hook install

```

This command creates or modifies `.git/hooks/post-commit` to include the Graphify update logic. According to the source code in [`tools/skillgen/fragments/references/shared/hooks.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/shared/hooks.md), the installation process appends Graphify commands to any existing hook script rather than overwriting it.

Upon successful installation, you will see:

```bash
✔ Hook installed to .git/hooks/post-commit

```

### Verifying the Installation

Confirm the hook is active using the status command:

```bash
graphify hook status

```

Expected output:

```bash
✔ Hook is active in .git/hooks/post-commit

```

## How the Hook Works

The installed hook executes the following sequence after each commit:

1. Runs `git diff HEAD~1 --name-only` to detect changed files
2. Filters for source code extensions (`.py`, `.js`, `.ts`, etc.)
3. Executes `graphify extract` on the modified files
4. Rebuilds [`graph.json`](https://github.com/Graphify-Labs/graphify/blob/main/graph.json) and [`GRAPH_REPORT.md`](https://github.com/Graphify-Labs/graphify/blob/main/GRAPH_REPORT.md) via `graphify build`

The actual implementation references [`graphify/skill.md`](https://github.com/Graphify-Labs/graphify/blob/main/graphify/skill.md), which defines the CLI sub-commands that manage this workflow. The hook script is rendered from reference templates located in [`tools/skillgen/fragments/references/shared/hooks.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/shared/hooks.md) and [`tools/skillgen/fragments/references/host/hooks-agents-md.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/host/hooks-agents-md.md) for AGENTS.md integrations.

## Managing the Hook

### Checking Status

To verify whether the Graphify hook is currently installed and active:

```bash
graphify hook status

```

This command checks `.git/hooks/post-commit` for the presence of Graphify-specific markers and reports the hook's location.

### Uninstalling the Hook

When you want to remove automatic graph updates:

```bash
graphify hook uninstall

```

This command removes only the Graphify section from your post-commit script, preserving any other custom hooks you may have added. The output confirms:

```bash
✔ Hook removed from .git/hooks/post-commit

```

## Hook Implementation Details

### Appending to Existing Hooks

A critical feature of the Graphify hook system is its **non-destructive** installation. If your repository already contains a `post-commit` hook, `graphify hook install` automatically appends its commands to the existing script. This behavior ensures you retain custom logic while adding Graphify's automatic rebuild functionality.

### Core Logic

The generated hook script performs approximately this sequence:

```bash

# Graphify post-commit hook (generated)

git diff HEAD~1 --name-only | grep -E '\.py$|\.js$|\.ts$' | xargs -r graphify extract
graphify build

```

This logic is extracted from the reference documentation in [`tools/skillgen/fragments/references/shared/hooks.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/shared/hooks.md), which serves as the primary documentation for the generic post-commit hook installation.

## Summary

- **Install** Graphify Git hooks using `graphify hook install` to enable automatic post-commit graph rebuilding
- **Verify** installation status anytime with `graphify hook status`
- **Remove** the hook cleanly using `graphify hook uninstall` without affecting existing custom hooks
- The hook references [`graphify/skill.md`](https://github.com/Graphify-Labs/graphify/blob/main/graphify/skill.md) for CLI definitions and uses templates from [`tools/skillgen/fragments/references/shared/hooks.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/shared/hooks.md)
- Only source code changes trigger automatic updates; documentation requires manual `graphify --update`

## Frequently Asked Questions

### Does Graphify overwrite existing post-commit hooks?

No. According to the implementation in [`tools/skillgen/fragments/references/shared/hooks.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/shared/hooks.md), Graphify **appends** its commands to existing `.git/hooks/post-commit` scripts rather than overwriting them. This preserves any custom logic you've already configured while adding the automatic graph rebuild functionality.

### What files trigger the knowledge graph rebuild?

The hook specifically targets source code files. It runs `git diff HEAD~1 --name-only` and filters for code extensions like `.py`, `.js`, and `.ts`. Documentation files, images, and other assets are ignored during automatic updates, though you can manually refresh them using `graphify --update`.

### Can I use Graphify hooks with AGENTS.md integration?

Yes. The hook system supports both standard integrations and AGENTS.md-specific workflows. The host-specific reference at [`tools/skillgen/fragments/references/host/hooks-agents-md.md`](https://github.com/Graphify-Labs/graphify/blob/main/tools/skillgen/fragments/references/host/hooks-agents-md.md) provides documentation tailored for projects using the AGENTS.md integration pattern.

### How do I manually update the graph if the hook misses files?

If the hook fails to capture certain changes or if you've modified documentation files (which the hook ignores), run `graphify --update` from your repository root. This command forces a full refresh of the knowledge graph regardless of Git status.