Skip to content

About

No description, website, or topics provided.

Resources

Stars

119 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

mightyCode

Run Claude Code on a local MLX model (DeepSeek-V4-Pro-Qwen3.5-9B-UNCENSORED-heretic). No API key needed, fully local (Apple Silicon only).

claude  --/v1/messages-->  anthropic_proxy.py  --/v1/chat/completions-->  mlx_lm.server (4-bit model)
File Purpose
claude-local Launcher. Starts the backend as a persistent service and opens claude
anthropic_proxy.py Anthropic Messages API → OpenAI-compatible API proxy (streaming and tool calls supported) + EoCC compaction + Guard hook
guard.py Tool-call inspection (exfiltration, credential access, persistence, destructive commands)
convert_model.py HF → MLX 4-bit conversion (quantizes on CPU)
setup.sh Creates the venv, downloads and converts the model, registers the command on PATH

Requirements

  • Apple Silicon Mac (macOS), 16 GB RAM or more recommended
  • Free disk space: about 25 GB during conversion (19 GB source + 4.7 GB output). About 5 GB once the source is deleted
  • uv (brew install uv)

Installation

1. Claude Code itself (not included in this repository)

Claude Code cannot be redistributed, so install it yourself by following the official instructions.

# Official installer (macOS / Linux)
curl -fsSL https://claude.ai/install.sh | bash
# or via npm (Node.js 18+)
npm install -g @anthropic-ai/claude-code

claude --version   # verify

See https://code.claude.com/docs for the latest instructions. You do not need to log in with an Anthropic account to use it with a local model.

2. This repository

A pre-converted model is available at https://huggingface.co/shi3z/DeepSeek-V4-Pro-Qwen3.5-9B-UNCENSORED-heretic-MLX-4bit (skip the 19 GB download and conversion: hf download shi3z/DeepSeek-V4-Pro-Qwen3.5-9B-UNCENSORED-heretic-MLX-4bit --local-dir models/heretic-9b-mlx-4bit, then run ./setup.sh).

git clone https://github.com/shi3z/mightyCode.git
cd mightyCode
./setup.sh

If you are short on disk space, put the conversion source on an external drive: SRC_DIR=/Volumes/big/src ./setup.sh (If ~/.local/bin is not on your PATH, add export PATH="$HOME/.local/bin:$PATH".)

Usage

claude-local          # start (first run takes a few tens of seconds to load the model). Arguments are passed through to claude
claude-local -p "..." # non-interactive run
claude-local status   # backend status
claude-local logs     # tail the logs
claude-local stop     # stop the backend (it keeps running after claude exits, so stop it when you no longer need it)

Environment variables:

Variable Default Description
MODEL_DIR models/heretic-9b-mlx-4bit MLX model to use
MLX_PORT / PROXY_PORT 8080 / 8082 Ports
THINKING 0 Set to 1 to enable Qwen's thinking mode (slower)
COMPACT_THRESHOLD 48000 Estimated token count that triggers EoCC compaction (0 disables it)
MAX_TOKENS_CAP 8192 Maximum output tokens per response
PROXY_CONCURRENCY 3 Max simultaneous generations (parallel subagents queue in the proxy)
PING_SECS 5 Keep-alive ping interval on the SSE stream while the model is thinking/prefilling
API_TIMEOUT_MS 3600000 Claude Code's per-request timeout (set by claude-local; Claude Code's own default is 10 min)

Guard (exfiltration / misbehavior tripwire)

The model is uncensored and small, so every tool call it produces is inspected by the proxy (guard.py) before Claude Code sees it. If a call looks dangerous it is dropped, nothing is executed, and Claude Code shows an error message (🛑 mightyCode Guard blocked this step) with the tool, the reason and the input. The attempt is logged to .state/guard.log.

Blocked by default:

  • Network access (curl, wget, nc, ssh, scp, git push, /dev/tcp, Python/Node HTTP libraries, WebFetch, MCP tool arguments, …) to hosts that are not allowlisted
  • Secrets together with network access: SSH keys, cloud/git credentials, .env, keychain, environment variables, API-key-looking strings, long encoded blobs
  • Reading credential files, DNS exfiltration (nslookup $(...)), curl | sh, base64 -d | sh
  • Writing to persistence locations (~/.zshrc, authorized_keys, LaunchAgents, .git/hooks, Claude settings), crontab, launchctl
  • Destructive/privileged commands: rm -rf / or ~, sudo, mkfs, dd of=/dev/…
  • Scripts (python x.py, …) are opened and checked too, and file contents written with Write/Edit are scanned
claude-local guardlog                              # what was blocked
GUARD_ALLOW_HOSTS=example.com claude-local         # extra allowed hosts (default list: localhost, github.com, huggingface.co, pypi.org, npmjs.org, …)
GUARD=warn claude-local                            # log only, do not block
GUARD=off claude-local                             # disable (restart the backend first: claude-local stop)
python3 -I tests/test_guard.py                     # unit tests

Note: the backend (proxy) is persistent, so after changing GUARD* variables run claude-local stop first.

This is a heuristic tripwire, not a sandbox. A determined model can evade pattern matching (e.g. by obfuscation). Do not run Claude Code with --permission-mode bypassPermissions against this model, keep the normal permission prompts on, and for hard guarantees add an OS-level egress filter (pf, Little Snitch / LuLu) or run it in a container/VM.

EoCC (End-of-Conversation Compaction)

Based on arXiv:2611.05306 "You don't need long context". When the context exceeds a threshold, the model itself writes a recap for resuming (objective, established facts, changes made, dead ends, next step). From then on only "original task + recap + later turns" is sent, which keeps the history short (less KV-cache memory and lower decode latency). Claude Code's own system prompt and tool definitions take about 15–20K tokens, so the threshold is set high (48K). The paper's results were measured on API models; the effect on a local 9B model is untested.

Timeouts / slow subagents

A 9B local model needs tens of seconds to prefill a 15–30K-token Claude Code prompt and ~30 tok/s to generate, and parallel subagents share one GPU. claude-local therefore raises API_TIMEOUT_MS, the proxy sends keep-alive pings, queues generations beyond PROXY_CONCURRENCY, and aborts the backend generation when the client disconnects. Every request is logged with timings: claude-local logs → [REQ …] ok dur=… queue_wait=… first_token=….

Known caveats

  • Image input is not supported (images are omitted)
  • A warning like Claude Code doesn't recognize the model "heretic-9b-local" appears; it does not affect operation
  • Converting on the GPU hit a Metal GPU Timeout Error on some setups, so conversion runs on the CPU
  • With the system mlx-lm 0.31.1 and mlx 0.32, mlx_lm.server crashed, so a dedicated venv with the latest mlx-lm is installed
  • This is a 9B model; quality on complex agentic work is far below the real Claude
  • This model is an uncensored variant. Use it at your own risk

About

No description, website, or topics provided.

Resources

Stars

119 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages