Skip to main content

The AI coding agent you can read in an afternoon. ~2000 lines of Python, fully hackable.

Project description

mini-cognit-cli

The AI coding agent you can read in an afternoon.

Stars PyPI Downloads License Python 3.12+

pip install mini-cognit-cli

Why mini-cognit-cli?

Every AI coding agent (Claude Code, aider, Kimi CLI, Codex) is a black box with tens of thousands of lines of code. mini-cognit-cli takes the opposite approach:

  • ~2000 lines of Python — read the entire codebase, understand every decision
  • Add a custom tool in ~30 lines — no plugin system, no abstractions, just a function
  • Any OpenAI-compatible API — OpenAI, Anthropic (via proxy), Ollama, LM Studio, anything
  • Fork and make it yours — designed to be the starting point for your agent
Claude Code aider Kimi CLI mini-cognit-cli
Codebase ~100k+ lines ~50k+ lines ~30k+ lines ~2k lines
Time to understand Weeks Days Days An afternoon
Add a custom tool Plugin system Moderate Plugin / MCP ~30 lines
Provider lock-in Anthropic Any Multi-provider Any OpenAI-compatible
Language TypeScript Python Python Python

Quickstart

# Install
pip install "mini-cognit-cli[cli]"

# Configure (pick one)
export OPENAI_API_KEY="sk-..."                    # env var
# OR: create cognit.toml with provider config     # config file

# Go
cognit chat

That's it. The agent can read/write files, run shell commands, search code, browse the web, and more.

Features

Tools — file read/write/edit, shell execution, grep, glob, web search, URL fetch, image reading

Session management — auto-save, --continue to resume, --session <id> to pick a specific session

Image support/paste-image from clipboard, /img <path> to attach, vision models analyze images

@ file references — type @filename with Tab autocomplete to reference files in your message

Agent Skills — drop a SKILL.md in .cognit/skills/ to teach the agent new workflows (compatible with Claude/Codex skill format)

Context compaction — auto-summarizes when approaching token limits, or /compact to manually compress

Extended thinking--thinking flag for reasoning models

Tool approval — shell commands need confirmation; --yolo to auto-approve everything

Usage

# Basic
cognit chat

# Specify model
cognit chat -m gpt-4o

# Resume last session
cognit chat --continue

# YOLO mode (auto-approve all tools)
cognit chat --yolo

# Extended thinking
cognit chat --thinking

# List saved sessions
cognit sessions

In-session commands

Command Description
/help Show all commands
/clear Clear conversation and start new session
/compact Manually compress context
/sessions List saved sessions
/paste-image Paste image from clipboard
/img <path> Attach an image file
@path/to/file Reference a file (Tab to autocomplete)
/exit Quit (auto-saves session)

Configuration

Create cognit.toml in your project directory or ~/.config/cognit/:

[providers.my_provider]
type = "openai"
base_url = "https://api.openai.com/v1"
api_key = "sk-..."

[models.default]
provider = "my_provider"
model = "gpt-4o"
max_context_size = 128000

Priority: CLI flags > cognit.toml > environment variables.

SDK usage

from cognit import CognitAgent

agent = CognitAgent(model="gpt-4o", api_key="sk-...")

# Add custom tools
@agent.tool(name="my_tool", description="Does something")
async def my_tool(query: str) -> str:
    return f"result for {query}"

# Chat (context preserved between calls)
result = await agent.chat("What files are here?")
result = await agent.chat("Read the first one.")

# With image
result = await agent.chat("Describe this", images=["data:image/png;base64,..."])

Architecture

src/cognit/          (~2000 lines total)
├── cli.py              ← CLI entry point (Typer)
├── app.py              ← REPL orchestrator
├── config.py           ← TOML config loading
├── sdk.py              ← Programmatic SDK interface
├── llm/
│   ├── provider.py     ← Abstract LLM interface
│   ├── openai_provider.py  ← OpenAI-compatible implementation
│   ├── generate.py     ← LLM call + streaming assembly
│   └── message.py      ← Message model (text, images, tool calls)
├── soul/
│   ├── agent.py        ← Core agent loop (the brain)
│   ├── context.py      ← Conversation history
│   ├── compaction.py   ← Context summarization
│   ├── session.py      ← Session persistence
│   ├── skills.py       ← Agent Skills (SKILL.md) loading
│   └── toolset.py      ← Tool registry + dispatch
├── tools/
│   ├── file_read.py    ← Read files
│   ├── file_write.py   ← Write/edit files
│   ├── glob_tool.py    ← File pattern matching
│   ├── grep.py         ← Search file contents
│   ├── shell.py        ← Shell execution
│   ├── web_search.py   ← Web search (DuckDuckGo)
│   ├── fetch_url.py    ← Fetch web pages
│   └── media_read.py   ← Read images for vision
└── ui/
    └── terminal.py     ← Terminal I/O (prompt-toolkit + rich)

Each module has a clear responsibility. The entire flow:

User input → Agent.run() → LLM call → Tool execution → Loop until done → Response

Adding a custom tool

# src/cognit/tools/my_tool.py
from cognit.soul.toolset import Toolset

def register(toolset: Toolset) -> None:
    @toolset.tool(name="my_tool", description="Does something useful.")
    async def my_tool(query: str, limit: int = 10) -> str:
        return f"Result: {query} (limit={limit})"

Register in sdk.py's _register_builtin_tools():

from cognit.tools import my_tool
my_tool.register(toolset)

That's it. The decorator auto-infers JSON Schema from type hints.

Agent Skills

Drop a SKILL.md file in .cognit/skills/your-skill/SKILL.md:

---
name: code-review
---
When asked to review code, follow these steps:
1. Read the changed files
2. Check for bugs, security issues, and style problems
3. Suggest improvements with code examples

Skills are auto-discovered from .cognit/skills/, ~/.cognit/skills/, and compatible with .claude/skills/ and .codex/skills/.

Requirements

  • Python >= 3.12
  • Works with any OpenAI-compatible API (OpenAI, Anthropic via proxy, Ollama, LM Studio, etc.)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_cognit_cli-0.2.1.tar.gz (309.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mini_cognit_cli-0.2.1-py3-none-any.whl (43.2 kB view details)

Uploaded Python 3

File details

Details for the file mini_cognit_cli-0.2.1.tar.gz.

File metadata

  • Download URL: mini_cognit_cli-0.2.1.tar.gz
  • Upload date:
  • Size: 309.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for mini_cognit_cli-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9392eddbea0835845224eba4aa96aef2f2bebb7608543190d3cd6b1b1cd94871
MD5 cd8abf0a0d32f0676e5f011ce10875d7
BLAKE2b-256 a278d06d9fe214d31c50002e435cf1d3963757fc35dcf14da5a75f11976734c0

See more details on using hashes here.

File details

Details for the file mini_cognit_cli-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mini_cognit_cli-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 327c8498558498beab4d07def4d83fe9b6a229943e6f976c561634f5e04158cf
MD5 f62b8fc659894ca12a592c78a8c81817
BLAKE2b-256 2f837a6670c96dcf53bee33ef9ca830852c88fca4838529059fa470734462d57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page