Configs2026年5月31日·1 分钟阅读

Context Mode — Context Window Optimization for AI Coding Agents

Sandboxes and compresses tool output from AI coding agents, achieving up to 98% context reduction while preserving the information agents need to act.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Context Mode
直接安装命令
npx -y tokrepo@latest install f681e78f-5ca7-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Context Mode is an open-source tool that dramatically reduces context window consumption for AI coding agents. It works by intercepting tool output (file reads, grep results, directory listings) and compressing it into compact, semantically equivalent summaries that preserve the information needed for decision-making while shedding verbose noise.

What Context Mode Does

  • Intercepts tool output from AI coding agents before it enters the context window
  • Compresses file contents, terminal output, and search results by up to 98%
  • Preserves semantic meaning and actionable details while removing boilerplate
  • Tracks context budget and warns before hitting window limits
  • Works transparently with existing agent workflows via output sandboxing

Architecture Overview

Context Mode operates as a middleware layer that wraps agent tool calls. When a tool returns output, the compressor analyzes the content type (source code, logs, JSON, directory listing) and applies type-specific compression strategies. For code, it extracts relevant sections around matches. For logs, it deduplicates repeated patterns. The compressed output replaces the original in the agent's context window.

Self-Hosting & Configuration

  • Install globally via npm or add as a project dependency
  • Run context-mode init to generate a config file with default compression rules
  • Customize compression levels per tool type in context-mode.config.ts
  • Set a context budget cap to trigger warnings or automatic compaction
  • Integrates with Claude Code, Codex, and other agent runtimes via hooks

Key Features

  • Up to 98% reduction in context consumption on large tool outputs
  • Type-aware compression strategies for code, logs, JSON, and plain text
  • Transparent operation requiring no changes to existing agent workflows
  • Real-time context budget tracking with configurable alerts
  • Preserves line numbers and file paths for accurate agent references

Comparison with Similar Tools

  • LLMLingua — prompt compression library; Context Mode targets tool output specifically
  • RTK — CLI proxy for token reduction; Context Mode focuses on context window management
  • Manual truncation — loses information; Context Mode uses semantic compression
  • Summarization APIs — add latency and cost; Context Mode uses fast local heuristics

FAQ

Q: Does compression lose important details? A: The compressor is conservative by default, preserving all lines that match search queries and surrounding context. Compression level is tunable.

Q: Which agents does it support? A: Any agent that uses standard tool calling. It has first-class integrations for Claude Code and Codex.

Q: Does it slow down the agent? A: No. Compression runs locally in milliseconds and typically makes the agent faster by reducing context processing time.

Q: Can I disable compression for specific tools? A: Yes. The config file supports per-tool overrides and bypass rules.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产