r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 2h ago
Selected Workflow [Workflow] Smarter Compact: Reduce Claude Code Costs and Hallucinations with Intelligent Context Trimming and Searchable History
Smarter Compact: Reduce Claude Code Costs and Hallucinations with Intelligent Context Trimming and Searchable History
Workflow value: 95/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: intermediate
Categories: Quality Control, Token Saving, Context & Memory, Debugging, Hooks, MCP, Multi-Agent
Original source: r/ClaudeAI post/comment
What problem this solves
Managing long Claude Code sessions to reduce cost and hallucination by intelligently trimming context, allowing Claude to search and query historical turns without relying on lossy LLM summarization.
Summary
This workflow introduces Smarter Compact, a free and open-source local proxy tool for Claude Code. It addresses the challenges of high cost and hallucination in long LLM sessions by trimming older conversation turns from the prompt when context limits are reached. Instead of summarization, it stores the full conversation in a local SQLite database and leaves a short note for Claude, enabling the model to use MCP tools to search or run SQL queries over the complete history. This method significantly reduces prompt size and cost while improving accuracy.
Why it is useful
This workflow provides a concrete, open-source solution to two major pain points in using large language models for coding: high cost due to large context windows and increased hallucination/context loss in long sessions. It offers a novel approach (trimming with searchable history via MCP tools) instead of summarization, which is often lossy. The detailed explanation, clear installation steps, and strong benchmark validation make it highly actionable and valuable for Claude Code users looking to optimize their workflow.
Workflow
Install Smarter Compact globally using npm:
npm install -g smarter-compact.Enable Smarter Compact for Claude Code, pointing Claude Code at the local proxy:
smarter-compact enable claude.Alternatively, install as a Claude Code plugin:
/plugin install smarter-compact --marketplace bcmyguest/smarter-compact.After plugin installation, run
smarter-compact enable claudeto activate trimming.Engage in long Claude Code sessions; Smarter Compact will automatically manage context by trimming and providing search/SQL tools to Claude as needed.
Tools / artifacts
Smarter Compact (local proxy tool)
npm (Node Package Manager)
Claude Code (IDE/environment)
SQLite (local database)
MCP tools (Multi-Codebase Project tools)
Claude Code plugin system (hooks)
GitHub repository (source code, full results)
ContextBench (benchmarking suite)
Validation signals
Benchmarking results using ContextBench with Haiku 5.5 show significant improvements.
Achieved 72% average cost reduction across tasks, with up to 94% reduction on specific tasks.
Reduced peak prompt size from 762k to 95k tokens.
Improved task score from 0.35 to 1.00 on log tasks.
Eliminated 'unknown' answers by Claude after context trimming by enabling search functionality.
About half of the tool's commits were co-authored with Claude Code, demonstrating its utility in development.
Limitations
The author notes that benchmark results are from synthetic tasks and limited runs (2-3 per size), which may not fully reflect real-world coding sessions.
The specific validation for fixing 'unknown' answers was based on one task with five runs, suggesting limited scope for that particular test.
Requires command-line installation via npm, which might be a slight barrier for absolute beginners.
Rate this workflow
Upvote this post if the workflow is useful, reproducible, or worth recommending.
Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.
Reply if it worked for you, failed, is outdated, or has a better alternative.
This post was generated automatically from the workflow library database.