Skip to content

sady4850/openChpok

Repository files navigation

openChpok

Release CI Go version License

Local compaction proxy for AI coding agents. Sits between your agent and the API, compacts verbose tool outputs before they reach the LLM. Saves up to ~80% of tokens on grep/ls/git log output — no changes to your agent required.

Works with Claude Code (Anthropic Messages API) and Codex CLI (OpenAI Responses API). Any client that talks one of those two protocols should work.

⚡ Quickstart

First, install the binary — see Install (one tar -xzf + mv).

# Terminal 1 — start the proxy
openchpok --port 8080

# Terminal 2 — point your agent at it, then run claude / codex
eval "$(openchpok env)"
claude "list files in this repo"   # or: codex "..."

✅ Verify it works

  1. Open http://localhost:8080/ui — you should see your request appear, with "chars saved".
  2. Check the JSONL log: tail -f ~/.cache/openchpok/proxy.jsonl.
  3. No requests showing up? → Troubleshooting.

What eval "$(openchpok env)" actually does

$ openchpok env
export ANTHROPIC_BASE_URL=http://127.0.0.1:8080
export OPENAI_BASE_URL=http://127.0.0.1:8080/v1

$ eval "$(openchpok env)"   # runs those two exports in your current shell

$ # now claude / codex go through the proxy — nothing in ~/.codex/config.toml
$ # or your shell rc is changed permanently

✅ Supported agents

  • Claude Code — zero config, uses ANTHROPIC_BASE_URL
  • Codex CLI — zero config, uses OPENAI_BASE_URL (subscription auth via ~/.codex/auth.json is picked up automatically)
  • Any client speaking Anthropic Messages or OpenAI Responses/Chat Completions

🎯 Why openChpok?

Your agent pastes the full output of grep, ls -la, git status, find into the next LLM turn — every time. Most of that is noise the model doesn't need. openChpok trims it on the way out.

  • 💰 Cut token spend — verbose tool results shrink 35–80% before hitting the LLM
  • 🚀 Zero agent changes — just point ANTHROPIC_BASE_URL / OPENAI_BASE_URL at the proxy
  • 🔍 Full visibility — per-request stats at /ui, JSONL log at ~/.cache/openchpok/proxy.jsonl
  • 🔒 Local-only — stdlib-only Go binary, no external deps, no telemetry
  • 🔑 Reuses your auth — Anthropic API key, OpenAI API key, or ChatGPT subscription via codex login

🏗️ How it works

Agent (Claude Code / Codex / ...)
  │
  │  ANTHROPIC_BASE_URL / OPENAI_BASE_URL=http://localhost:8080
  ▼
┌──────────────────────────────┐
│       openChpok              │
│                              │
│  Match tool_use → tool_result│
│  Strip Codex envelope        │
│  Compact verbose output      │
│  Re-attach envelope          │
│  Forward to real API         │
│  Stream SSE back as-is       │
│  Log metrics                 │
└────────────┬─────────────────┘
             ▼
   api.anthropic.com / api.openai.com

Requests are compacted; responses pass through unmodified. For Codex, the proxy also preserves the stdout envelope (Chunk ID, Wall time, Process exited) while compacting only the useful body.

📉 Compactors

Savings measured on internal/compact/testdata/*.txt (go test -run TestCompressionBaseline -v ./internal/compact/...). Real-world savings vary by command and repo size.

Compactor Trigger What it does Saving on fixture
git_status git status keeps section headers + per-file prefixes; drops advisory hints and ahead/behind noise 35–61%
git_log git log --oneline caps at 20 most recent lines, adds overflow marker ~78%
ls ls -la, ls -R -la: drops perms/owner/group/hardlinks/total, keeps raw byte sizes; -R: indent+dash tree ~78% on -la
grep grep, rg (Bash) top-of-output TOC (files by match count), per-file grouping, long-line truncation, hidden (N): footer ~80%
find find indent+dash directory tree, collapses large siblings into ... +K more, hidden (N): footer ~15%
More compactors & safety rules

Never compacted: Read/cat file content, Edit/Write tool results, Glob, errors. If a compactor produces output larger than its input, the raw output passes through unchanged.

Additional compactors in internal/compact/: git_diff, git_show, git_branch, git_reflog, git_stash, tree.

🔍 Examples

Snippets come from real fixtures in internal/compact/testdata/.

git status — 838 → 511 bytes (39% saved)

# git status (verbose)                          # openchpok git status (compact)
Your branch is ahead by 3 commits              On branch feature/refactor
(use "git push" to publish)                    Changes to be committed:
Changes not staged for commit:                 modified: internal/compact/compact_find.go
...                                            ...

ls -la — 2237 → 487 bytes (78% saved)

# ls -la (full metadata)                        # openchpok ls -la (compact)
drwxr-xr-x  33 user staff 1056 ... .           .claude/
-rw-r--r--   1 user staff  503 ... .gitignore  .gitignore 503
-rw-r--r--   1 user staff 20488 ... README.md  README.md 20488
...                                            20 files, 10 dirs

grep -rn foo . — 40000 → 8017 bytes (80% saved)

# grep -rn foo . (flat stream)                 # openchpok grep -rn foo . (grouped)
src/a.rs:19: ...                               547 matches in 15 files:
src/a.rs:79: ...                                 src/a.rs: 25
src/b.rs:9: ...                                  src/b.rs: 6
...                                            ...

📦 Install

GitHub Releases (recommended)

Download openchpok_<version>_<OS>_<arch>.tar.gz (or .zip on Windows) from the releases page, extract, and place the openchpok binary on your $PATH.

# Linux/macOS
tar -xzf openchpok_*.tar.gz
chmod +x openchpok
sudo mv openchpok /usr/local/bin/

From source

git clone https://github.com/sady4850/openChpok.git
cd openChpok
go build -o ./bin/openchpok ./cmd/openchpok

🔧 Configuration

Settings come from (in order of precedence): CLI flags → JSON config file → built-in defaults. The default config path is $XDG_CONFIG_HOME/openchpok/config.json (falls back to ~/.config/openchpok/config.json). Missing file is fine — defaults apply.

{
  "upstream": "https://api.anthropic.com",
  "port": 8080,
  "verbose": false,
  "dump_dir": ""
}
  • CLI flags: openchpok --help
  • Env exports helper: openchpok env --help
  • Debug dumps: --dump-compacted <dir> writes .orig.txt, .comp.txt, .meta.json per tool call

📊 Dashboard

openChpok dashboard

Open http://localhost:8080/ui — server-side rendered, auto-refreshes every 10s. Shows total requests, tool calls, chars saved, per-compactor savings, per-tool breakdown, and recent sessions. Same numbers as JSON at /api/stats:

curl -s http://localhost:8080/api/stats | jq '.requests, .tool_results, .total_saving_pct'

🛠️ Troubleshooting

  • openchpok: command not found — ensure the install location is on your $PATH.
  • Port 8080 is busy — run with a different port, e.g. openchpok --port 18080, and use http://localhost:18080/ui.
  • Dashboard shows zero requests (Codex) — you may have hit openai/codex#16719: some codex CLI releases silently ignore OPENAI_BASE_URL and openai_base_url in config.toml. Fix: upgrade codex.
  • Dashboard shows zero requests (Claude) — confirm the agent terminal has ANTHROPIC_BASE_URL pointing at the proxy.
  • Auth errors (401/403):
    • Codex subscription: run codex login to populate ~/.codex/auth.json
    • Codex API-key: ensure OPENAI_API_KEY is set in the agent's terminal
    • Claude: ensure your Anthropic credentials are set for claude
  • Telemetry/log file — local-only JSONL at ~/.cache/openchpok/proxy.jsonl; reset with rm ~/.cache/openchpok/proxy.jsonl.

📋 Requirements

  • Go 1.25+
  • Zero external dependencies — stdlib only

📝 License

Apache License 2.0 — see LICENSE and NOTICE.

About

CLI proxy that reduces LLM token consumption on common dev commands by compacting verbose tool output. Fully local, single Go binary, zero runtime dependencies

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors