Metadata-Version: 2.4
Name: cohrint-agent
Version: 0.4.2
Summary: AI coding agent with per-tool permissions, cost tracking, and token optimization
Author-email: Aman Jain <aman@cohrint.com>
License: MIT
Project-URL: Homepage, https://cohrint.com
Project-URL: Documentation, https://cohrint.com/docs
Project-URL: Repository, https://github.com/amanjain/cohrint
Project-URL: Bug Tracker, https://github.com/amanjain/cohrint/issues
Keywords: ai,agent,cost-tracking,claude,codex,gemini,llm
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: anthropic<1.0,>=0.40.0
Requires-Dist: rich<15.0,>=13.0.0
Requires-Dist: httpx<1.0,>=0.24.0
Requires-Dist: questionary<3.0,>=2.0
Requires-Dist: tomli>=2.0; python_version < "3.11"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"

# Cohrint Agent

AI coding agent with per-tool permissions, cost tracking, prompt optimization, and anomaly detection. Works across Claude (API), Claude Code, Codex CLI, and Gemini CLI.

## Install

```bash
pip install cohrint-agent
```

Requires Python 3.9+.

## Quick Start

### Interactive REPL

```bash
# Set your API key, then launch
export ANTHROPIC_API_KEY=sk-...
cohrint-agent
```

### One-shot prompt

```bash
cohrint-agent "explain the main function in cli.py"
```

### Pipe mode

```bash
echo "summarize this file" | cohrint-agent
```

## Backends

Cohrint auto-detects the best backend. You can override with `--backend`:

| Backend | Description | Requires |
|---------|-------------|---------|
| `api` | Direct Anthropic API (exact token counts) | `ANTHROPIC_API_KEY` |
| `claude` | Claude Code subprocess (free tier / subscription) | `claude` binary |
| `codex` | OpenAI Codex CLI subprocess | `codex` binary |
| `gemini` | Gemini CLI subprocess | `gemini` binary |

```bash
cohrint-agent --backend claude "refactor this function"
cohrint-agent --backend codex "write unit tests for auth.py"
```

Auto-detect priority: `COHRINT_BACKEND` env → `ANTHROPIC_API_KEY` → `claude` binary → `codex` binary → `gemini` binary.

## Session Management

Sessions are persisted to `~/.cohrint/sessions/`. Resume any previous session:

```bash
# List sessions and costs
cohrint-agent summary

# Resume by session ID
cohrint-agent --resume abc12345
```

## REPL Commands

| Command | Description |
|---------|-------------|
| `/help` | Show all commands |
| `/tools` | Show tool approval status |
| `/allow Bash,Write` | Approve specific tools |
| `/allow all` | Approve all tools for this session |
| `/cost` | Show current session cost |
| `/optimize on\|off` | Toggle prompt optimization |
| `/model claude-opus-4-6` | Switch model mid-session |
| `/reset` | Clear history, permissions, cost |
| `/quit` | Exit (shows final cost summary) |

## Cost Tracking

Every turn shows token usage and cost. Exit shows a full session summary:

```
  +----- Cost Summary -----+
  Model:             claude-sonnet-4-6
  Input tokens:      1,234
  Output tokens:     456
  Cost:              $0.0123
  Session total:     $0.0456
  Prompts:           3
  +-------------------------+
```

For Claude Code / Codex / Gemini (subscription or free tier), costs are labeled `~$0.00 (free tier)` or `~$0.0123 (estimated)`.

## Cohrint Dashboard

Send telemetry to your Cohrint dashboard for cross-session cost analysis:

```bash
export COHRINT_API_KEY=crt_...
cohrint-agent
```

Or pass inline: `cohrint-agent --cohrint-key crt_...`

## All Flags

```
cohrint-agent [OPTIONS] [PROMPT]

  PROMPT              One-shot prompt (omit for interactive REPL)

  --backend           api | claude | codex | gemini (auto-detected)
  --model             Model ID (default: claude-sonnet-4-6)
  --max-tokens        Max output tokens (default: 16384)
  --resume SESSION_ID Resume a previous session
  --api-key           Anthropic API key (or ANTHROPIC_API_KEY env)
  --cohrint-key       Cohrint dashboard API key (or COHRINT_API_KEY env)
  --system            Custom system prompt
  --no-optimize       Disable prompt optimization
  --cwd               Set working directory
  --debug             Enable debug output
```

## Environment Variables

| Variable | Description |
|----------|-------------|
| `ANTHROPIC_API_KEY` | Anthropic API key |
| `COHRINT_API_KEY` | Cohrint dashboard key |
| `COHRINT_BACKEND` | Force backend (api/claude/codex/gemini) |
| `COHRINT_MODEL` | Default model override |

## License

MIT
