Using a Local LLM as a Claude Code Subagent to Reduce Context Usage

Claude Code can orchestrate tasks by delegating to a local LLM running on your machine, similar to how it uses Claude subagents. This approach keeps file content out of Claude's context—only the local model's summary and insights are passed back.
How It Works
A small Python script (~120 lines, standard library only) runs an agent loop:
- You pass Claude a task description without file content
- The script sends it to LM Studio's
/v1/chat/completionsendpoint withread_fileandlist_dirtool definitions - The local model calls those tools itself to read the files it needs
- The loop continues until it produces a final answer
- Claude sees only the result
Example command:
python3 agent_lm.py --dir /path/to/project "summarize solar-system.html"
This results in:
- [turn 1] →
read_file({'path': 'solar-system.html'}) - [turn 2] → This HTML file creates an interactive animated solar system...
The file content goes into the local model's context (tested with Qwen's context), not Claude's.
Use Cases and Limitations
Based on testing with Qwen3.5 35B 4-bit via MLX on Apple Silicon, this approach is good for:
- Code summarization and explanation
- Bug finding
- Boilerplate / first-draft generation
- Text transformation and translation (tested with Hebrew)
- Logic tasks and reasoning (use
--thinkflag for harder problems)
It's not good for:
- Tasks that require Claude's full context
- Multi-file understanding where relationships matter
- Tasks needing the current conversation history
- Anything where accuracy is critical
Think of it as a Haiku-tier assistant, not a replacement for Claude.
Setup Requirements
- LM Studio running locally with the API server enabled
- One Python script for the agent loop, one for simple prompt-only queries
- Both wired into a global
~/.claude/CLAUDE.mdso Claude Code knows to offer delegation when relevant - No MCP server, no pip dependencies, no plugin infrastructure needed
Configuration tip: Add {%- set enable_thinking = false %} to the top of the Jinja template. For most tasks, you don't need the local model to reason, and this saves time and tokens while increasing speed with no real degradation in quality for such tasks.
📖 Read the full source: r/ClaudeAI
👀 See Also

Kreuzberg v4.7.0 adds code intelligence for 248 languages and improved markdown extraction
Kreuzberg v4.7.0, a Rust-core document intelligence library, now supports code extraction for 248 formats via tree-sitter and has significantly improved markdown quality with Structural F1 scores over 80% across 23 formats.

Running Google Gemma 4 26B-A4B Locally with LM Studio 0.4.0 Headless CLI
LM Studio 0.4.0 introduces llmster and the lms CLI for headless local model inference. The article details setting up Google's Gemma 4 26B-A4B MoE model on a MacBook Pro M4 Pro, achieving 51 tokens/second with 48GB unified memory.

Files.md: Open-Source Local-First Markdown Note-Taking App with LLM-Friendly Design
Files.md is an open-source, local-first markdown app for notes, tasks, and journals. 886 stars, built in Go, works offline, syncs via iCloud/Dropbox/self-hosted server or hosted beta app.files.md.

Your Fair Share Tool: Calculate Your Equal Share of Company Profits
A developer built a web tool using Claude Code and Vercel that calculates what your equal share of your employer's annual profits would be based on SEC 10-K filings. The tool shows specific numbers like Apple's $747,000 per employee and NVIDIA's $2.8 million per employee.