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 --versionSet 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 windsurfThis 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 reverseRepoFence will:
- Detect your tech stack (frameworks, languages, tools)
- Identify entry points and module structure
- Map core flows and dependencies
- Document existing patterns and conventions
- 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.mdTech stack, architecture, key modules
CORE_FLOWS.mdUser journeys, data flows, API patterns
BOUNDARIES.mdModule isolation, dependency rules
AI_RULES.mdExplicit do's and don'ts for AI agents
IDE_*.mdIDE-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
# 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 changesRecommended Workflow
- Initial setup: Run
initandreverse - Review specs: Fill in UNKNOWN sections, add business context
- Commit to git: Version your spec layer with your code
- Use with AI: Reference specs in your AI tool's context
- Iterate: Update specs after major changes
- 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
- What is Spec-Driven Development? — Understand the methodology behind RepoFence
- RepoFence vs Manual Setup — Compare approaches to AI context
- Changelog — See latest features and updates
- Get Started — Join early access and get your license
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
What is Spec-Driven Development?
Learn how Spec-Driven Development (SDD) transforms AI coding by providing explicit system context, boundaries, and rules before any code generation.
RepoFence vs Manual AI Setup: Why Automation Wins
Compare manual context documentation with automated spec generation. See how RepoFence saves time and improves consistency.
RepoFence Changelog
Track all RepoFence updates, new features, and improvements. Stay current with the latest CLI capabilities.