Back to Knowledge Hub
RepoFence|March 5, 202610 min read

How to Use RepoFence: Complete Setup Guide

Step-by-step guide to installing RepoFence, reverse-engineering your codebase, and maintaining a living spec layer for AI agents.

This guide walks you through installing RepoFence, generating your first spec layer, and integrating it into your AI-assisted development workflow.

Overview

RepoFence is a local-first CLI that reverse-engineers your codebase and generates a structured spec layer for AI coding agents. It creates:

  • System documentation that AI tools can reference
  • Explicit rules and boundaries for code generation
  • IDE-specific configuration files

Local-First

RepoFence runs entirely on your machine. Your code never leaves your system — only minimal context is sent to your LLM provider for analysis.

Prerequisites

  • Node.js 18 or later
  • A GitHub repository (local clone)
  • An OpenAI or Anthropic API key
  • RepoFence license token (from early access)

Installation

Install RepoFence globally or use npx:

# Install globally
npm install -g repofence

# Or use npx (no install needed)
npx repofence --version

Set your API key and license token:

# Set your LLM API key
export OPENAI_API_KEY="sk-..."
# or
export ANTHROPIC_API_KEY="sk-ant-..."

# Set your RepoFence license token
export REPOFENCE_TOKEN="rf_..."

Initialize Your Repo

Navigate to your repository root and run the init command. Choose your IDE pack:

cd your-repo

# For Cursor users
npx repofence init cursor

# For VS Code with Copilot
npx repofence init vscode

# For Windsurf
npx repofence init windsurf

This creates the initial /spec folder structure with template files.

Reverse Engineer Your Codebase

The reverse command analyzes your codebase and populates the spec files with detected patterns:

npx repofence reverse

RepoFence will:

  1. Detect your tech stack (frameworks, languages, tools)
  2. Identify entry points and module structure
  3. Map core flows and dependencies
  4. Document existing patterns and conventions
  5. Generate AI rules based on detected practices

Review Required

Generated specs are starting points. Review and refine them before relying on them for AI-assisted development. Mark any UNKNOWN sections with your actual knowledge.

Generated Files

After running reverse, your /spec folder contains:

SYSTEM_OVERVIEW.md

Tech stack, architecture, key modules

CORE_FLOWS.md

User journeys, data flows, API patterns

BOUNDARIES.md

Module isolation, dependency rules

AI_RULES.md

Explicit do's and don'ts for AI agents

IDE_*.md

IDE-specific configuration guide

Customization

Edit the generated files to add context RepoFence couldn't detect:

  • Business logic explanations
  • Historical context for decisions
  • Team conventions and preferences
  • Sensitive areas that need extra care
spec/AI_RULES.md
# Custom rules you might add

## Business Logic
- Prices are always stored in cents, not dollars
- User IDs are UUIDs, never sequential integers

## Team Conventions
- We use barrel exports in /components
- All hooks go in /hooks, not alongside components

## Sensitive Areas
- DO NOT modify /lib/billing without explicit approval
- Auth logic requires security review before changes

Recommended Workflow

  1. Initial setup: Run init and reverse
  2. Review specs: Fill in UNKNOWN sections, add business context
  3. Commit to git: Version your spec layer with your code
  4. Use with AI: Reference specs in your AI tool's context
  5. Iterate: Update specs after major changes
  6. Re-run reverse: Periodically refresh detected patterns

Pro Tip

Create a repofence pr command alias to generate a PR with spec updates. This makes spec maintenance part of your normal review process.

Next Steps

Ready to make your repo agent-ready?

RepoFence generates structured specs and AI rules from your codebase in minutes. Local-first, privacy by design.

Related Articles