Two Claude Code context efficiency improvement tools are recommended.

182.159.***.***
9

When using Claude Code, you've probably experienced how tool call results or LLM code exploration consume context, degrading the quality of subsequent responses. That symptom where "it worked fine just a moment ago, but suddenly gives strange answers." Industrially, it's been pointed out as a problem with terms like lost-in-the-middle and context rot.

I'm sharing tools that solve this from two angles.

One prevents context pollution after tool calls, and the other saves tokens during prompt input. Since the areas don't overlap, you can use them together.


1) Context Mode (mksglu/context-mode) - Preventing Context Pollution

Link: https://github.com/mksglu/context-mode

Problem it solves:

When you call tools like Bash, Read, Grep, and WebFetch, raw output goes directly into context. A single git log can take tens of thousands of tokens, a Playwright screenshot response 56KB, and MCP tool descriptions alone often consume over 50,000 tokens per session. When this accumulates, the LLM loses focus on the core question the user is actually asking.

How it works:

It intercepts tool calls via PreToolUse hook and sends them to a sandbox subprocess. Raw output stays in the sandbox, while only summaries and searchable indexes (when needed) enter the context. Provides 8 virtualization tools (ctx_execute, ctx_index, ctx_search, etc.).

It also maintains session continuity. It tracks file edits, git operations, errors, and user decisions in SQLite, and when compaction occurs, restores them as priority-tier snapshots (≤2KB). Even when context is compressed, the workflow doesn't break.

Measurements:

Playwright 56KB → 299B (98% reduction), and context remains lightweight after tool calls, allowing you to go deeper in the same session.

3.1k stars, a tool that was also a topic on Hacker News.

Installation:

One npm install + MCP registration. Beta support for 5 platforms (Claude Code, Gemini CLI, VS Code Copilot, etc.). Codex CLI works only 60% due to lack of hooks.

License: ELv2 (redistribution restricted, free to use).


2) tunaCtx (hang-in/tunaCtx, a fork of the original jaytoone/CTX) - Saving Context Tokens

Link: https://github.com/hang-in/tunaCtx

Problem it solves:

When a user enters a prompt, the LLM calls tools like grep, glob, and read haphazardly to find relevant code. In this process, unrelated files enter context, wasting tokens, and the LLM often fails to see the dependency structure of existing code, making incorrect guesses based only on text matching.

How it works:

Upon receiving a user prompt via UserPromptSubmit hook, a trigger classifier categorizes it into 4 types.

- EXPLICIT_SYMBOL: Class/function names specified → direct symbol index lookup

- SEMANTIC_CONCEPT: concept search → BM25 keywords

- IMPLICIT_CONTEXT: dependency search → import graph BFS traversal

- TEMPORAL_HISTORY: recent changes → session tracking

Each trigger is routed to different retrieval methods, and results are injected into context. The LLM doesn't wander searching grep; it already receives relevant files at the prompt stage. The key is IMPLICIT_CONTEXT—code import graphs contain structural information that text RAG can't see, which is why dependency queries show BM25 R@5=0.4 vs CTX R@5=1.0 difference.

Measurements:

1.9x token efficiency vs. BM25 (TES basis), token usage 5.2% (BM25 is 18.7%). No LLM calls, so it's fast. Hook latency 40-270ms (depending on project size).

The original is an academic tool planned for EMNLP 2026 submission. However, it needed some work for production use, so I forked it.

Work done in this fork:

- Decomposed the 1837-line bm25-memory.py god module into a 300-line orchestrator + 11 sub-modules

- Unified BM25 tokenizer/scoring between eval and production (original branched into two paths, so improvements to one didn't automatically propagate to the other)

- 82 unit tests (settings.json patcher, hook fallback, cache invalidation, etc.)

- 26 regression guard fixtures (byte-level comparison of deterministic hook output)

- Safety enhancements (graceful fallback on sqlite_vec import failure, deterministic sort, atomic install with hash-based update). The retrieval algorithm itself remains as the original. Only production readiness was strengthened.

Installation:

git clone + pip install -e . + ctx-install

ctx-install safely handles ~/.claude/hooks/ and settings.json idempotently (no duplicate additions on re-run) + backup (creates timestamped backup_.py).

The original has a weakness in Korean language handling (BM25 tokenizer is English-based), but the fork leaves room for integrating Korean morphological analysis. It's a candidate for the next cycle of work.

License: MIT. Credited with copyright of the original jaytoone/CTX.


Using both together:

- Context Mode: tool calls → isolated to sandbox (prevents pollution)

- tunaCtx: prompt input → automatically inject relevant code (saves tokens)

Hook events barely overlap (Context Mode uses PreToolUse/PostToolUse/PreCompact/SessionStart, tunaCtx uses only UserPromptSubmit/PostToolUse Grep matcher), so they can be registered together. PostToolUse is the only overlapping event, but since tunaCtx is limited to Grep matcher, there's almost no conflict. It's a combination that reduces token waste on the input side and prevents tool call results from polluting context on the output side. The cumulative effect is significant in Sonnet/Opus coding workflows.

로그인한 회원만 댓글 등록이 가능합니다.

개발한당

KR | ID | EN
  • IDR
  • KOR
8.35 -0.01

2026.07.10 KEB 하나은행 고시회차 1087회

다가오는 한인 행사일정

  • 등록 된 일정이 없어요!