contextforge-cli-harshal
v0.3.1
Published
Background AI context engine — automatically generates context.md for your repository
Maintainers
Readme
ContextForge
Persistent AI memory for your repository. ContextForge runs in the background, scans your codebase, and generates a live context.md so every AI session starts fully informed—no re-explaining your stack, architecture, or constraints.
Works with ChatGPT, Claude, Cursor, and GitHub Copilot.
How to run locally
See HOW_TO_RUN.md for every command, expected output, and a full copy-paste test script.
Install
npm install -D contextforgeOr globally:
npm install -g contextforgeQuick start
# Initialize and generate first context
npx contextforge init
# Regenerate on demand
npx contextforge generate
# Watch for changes (auto-regenerate)
npx contextforge watchOutput is written to .contextforge/:
.contextforge/
├── config.json
├── context.md ← paste into AI tools / Cursor rules
├── CHANGES.md ← what changed between runs
├── context.json
├── architecture.json
├── git-insights.json
├── bugs-report.json
├── cache/
└── logs/CLI commands
| Command | Description |
|---------|-------------|
| init | Create .contextforge/, config, and initial context |
| generate | Scan repo and regenerate all artifacts |
| watch | Watch files + optional timer; updates on code changes |
| changes | Show file/code change history between runs |
| stop | Stop daemon watcher (watch --daemon) |
| doctor | Health check (Node, keys, timer, context.md) |
| summary | Short stdout summary |
| prompt | Export full or partial context for AI prompts |
Options
npx contextforge generate --cwd /path/to/project
npx contextforge watch --verbose
npx contextforge watch --interval 15 # override .env timer (minutes)
npx contextforge prompt --sections stack,arch,git
npx contextforge watch --daemon # for use with stop
npx contextforge changes --limit 20Auto-update on file/code changes
ContextForge hashes every scanned file. When you edit and save code, watch or generate detects it and updates context.md:
- New, modified, and removed files are tracked
- Terminal:
File/code changes detected — context updated (~N modified) - History:
npx contextforge changesor.contextforge/CHANGES.md
Timer in .env (recommended)
# Regenerate every 15 minutes while watch is running (0 = file saves only)
CONTEXTFORGE_REFRESH_INTERVAL_MINUTES=15npx contextforge watchOn each timer tick, ContextForge only regenerates if files actually changed (no wasted runs).
Other env vars: CONTEXTFORGE_REFRESH_INTERVAL_SECONDS, CONTEXTFORGE_DEBOUNCE_MS
Cursor integration
Add a project rule:
Read
.contextforge/context.mdat the start of each session before answering questions about this codebase.
Or run npx contextforge prompt and paste the output into your chat.
AI enrichment (OpenAI + Groq)
Use OpenAI or Groq to generate a detailed AI-Enhanced Analysis section in context.md.
Setup
# Windows
copy .env.example .env
# macOS / Linux
cp .env.example .envEdit .env and set your keys:
OPENAI_API_KEY=sk-...
GROQ_API_KEY=gsk_...
CONTEXTFORGE_AI_PROVIDER=openaiThen:
npx contextforge init --aiConfig (ai in .contextforge/config.json)
See .contextforge/config.ai.example.json for a full template:
| Field | Description |
|-------|-------------|
| ai.enabled | Turn AI on/off |
| ai.provider | openai or groq |
| ai.fallbackProvider | Backup if primary fails |
| ai.background | true = fast scan first, AI updates context.md when ready |
| ai.openai.model | gpt-4o-mini, gpt-4o, etc. |
| ai.groq.model | llama-3.3-70b-versatile, mixtral-8x7b-32768 |
| ai.promptsDir | Folder for editable prompts (default .contextforge/prompts) |
Customize AI prompts
Edit files in .contextforge/prompts/ after init — see prompts/README.md in the package.
npx contextforge generate --ai
npx contextforge generate --no-aiConfiguration
.contextforge/config.json:
Copy .contextforge/config.example.json or see:
{
"ignore": ["node_modules", "dist", ".next"],
"watch": true,
"autoGenerate": true,
"includeGitHistory": true,
"detectBugs": true,
"debounceMs": 2000,
"refreshIntervalMinutes": 0,
"trackChanges": true,
"ai": {
"enabled": false,
"provider": "openai",
"fallbackProvider": "groq",
"background": true
}
}Priority: .env overrides config.json for timer, debounce, and AI provider. Run npx contextforge init --force to merge new fields into an existing project.
Programmatic API
import { runPipeline, loadConfig } from 'contextforge';
await runPipeline('/path/to/project', { verbose: true });Security
- Static scan runs 100% locally
- AI calls send only aggregated scan metadata (never
.envor source file contents) - API keys stay in your
.env(gitignored) - Respects
ignorepatterns in config
Development
npm install
npm test
node bin/contextforge.js init --cwd .Publish to npm
See PUBLISHING.md for the full guide:
npm loginnpm testnpm pack(inspect tarball)npm publish --access public
Quick publish:
npm test
npm publish --access publicLicense
MIT
