Skip to content

LilRedHat/contextforge-cli

Repository files navigation

ContextForge-CLI

Generate structured context files (llms.txt) from your Python codebase — zero API keys, fully offline.

Features

  • AST-Level Parsing — Statically analyses Python source files using the built-in ast module. Extracts classes, functions, and docstrings without executing any code.
  • Recursive File Discovery — Walks project directories automatically, skipping venv, .git, __pycache__, node_modules, and other noise directories.
  • llms.txt Generation — Produces a single, well-structured Markdown file that LLM tooling (Cursor, Copilot, Claude Code, opencode, etc.) can ingest as project context.
  • Zero Dependencies on AI Providers — No API keys, no network calls, no subscription. Runs entirely on your machine.
  • Rich CLI Feedback — Progress spinners and clear terminal output via the rich library.

Installation

# Install from source
cd contextforge-cli
pip install .

# Or install in editable mode for development
pip install -e .

Usage

# Scan the current directory
contextforge generate --target .

# Scan a specific project
contextforge generate --target ./my-project

The command produces an llms.txt file in the target directory. Example output:

## src/parser.py

### Classes

- **ASTParser** — Parses Python source into structured metadata
  - `parse_file()` — Returns classes, functions, and docstrings

### Functions

- `walk_directory()` — Recursively finds all `.py` files

## src/generator.py

Why llms.txt

The llms.txt convention (proposed by the llmstxt community) gives AI coding tools a standard place to look for project-level context. Instead of guessing which files to read or relying on token-wasteful file-tree scanning, tools can read a single llms.txt to understand your codebase's structure, key abstractions, and entry points.

This means:

  • Fewer hallucinations — the model knows exactly which modules exist and what they do.
  • Faster setup — no repetitive "read this file, now read that file" prompting.
  • Offline-first — the context file lives in your repo, not on a remote server.

Project Structure

contextforge-cli/
├── contextforge/
│   ├── __init__.py
│   ├── cli.py          # Click CLI entry point
│   ├── walker.py       # Recursive .py file discovery
│   ├── parser.py       # AST-based code analysis
│   └── generator.py    # llms.txt generation
├── tests/              # Test suite (pytest)
├── setup.py            # Package configuration
├── requirements.txt    # Runtime dependencies
└── dev-requirements.txt# Development dependencies

Contributing

Contributions are welcome. Please open an issue or submit a pull request on GitHub.

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/my-change).
  3. Run the test suite (pytest) to confirm nothing is broken.
  4. Submit a pull request with a clear description of your changes.

License

MIT — see LICENSE.

About

A zero-cost, fully offline CLI tool that uses Python's Abstract Syntax Tree (AST) to parse codebases and auto-generate LLM-optimized context files like llms.txt and ai-context.md.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages