Shell Hook
95+ 命令模式。
透明压缩。
Shell hook 在 AI 看到之前拦截 CLI 输出。Git diff、npm install、cargo build、docker log--全部压缩为其核心信息。无配置,无需学习别名。
34+ 个命令类别 95+ 个特定模式 60–90% 输出减少
流程
工作 原理。
Shell hook 透明包装你的命令。AI 看到压缩后的输出--你看到的没有任何不同。
1
命令
AI 运行 git status
2
Hook
lean-ctx 拦截输出
3
压缩
模式匹配精简
4
结果
AI 看到紧凑输出
34+ 类别
你已经 在用的每个工具。
lean-ctx 识别所有主要开发工具的输出模式,并用专门构建的规则压缩每一个。
版本控制
git status git diff git log git branch git stash git remote
JavaScript / Node
npm install npm run npm test yarn pnpm tsc
Rust
cargo build cargo test cargo clippy cargo check cargo run
容器与编排
docker ps docker build docker logs kubectl get kubectl describe
Python
pip install pytest python -m poetry uv
系统与工具
ls / find ps / top curl make env cat / head
前后对比
看看 区别。
不使用 shell hook ~580 tokens
git status
On branch feature/auth
Your branch is ahead of 'origin/feature/auth'
by 3 commits.
(use "git push" to publish your local
commits)
Changes to be committed:
(use "git restore --staged <file>..."
to unstage)
new file: src/session.ts
modified: src/login.ts
modified: src/api.ts
Changes not staged for commit:
(use "git add <file>..." to update
what will be committed)
(use "git restore <file>..." to
discard changes in working directory)
modified: src/session.ts
Untracked files:
(use "git add <file>..." to include
in what will be committed)
src/session.test.ts 使用 shell hook ~75 tokens
git status (compressed)
feature/auth ↑3 staged: +session.ts ~login.ts ~api.ts unstaged: ~session.ts untracked: session.test.ts [534 tok saved (87%)]
更多示例
每条命令, 都被压缩。
npm install - 原始 ~420 tokens
npm install
npm warn deprecated inflight@1.0.6: This module is not supported... npm warn deprecated glob@7.2.3: Glob versions prior to v9... npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4... added 847 packages, and audited 848 packages in 12s 127 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
npm install - 压缩后 ~35 tokens
npm install (compressed)
✓ 847 packages 12s ⚠ 3 deprecated (inflight, glob, rimraf) 0 vulnerabilities [385 tok saved (92%)]
cargo build - 原始 ~310 tokens
cargo build
Compiling proc-macro2 v1.0.86
Compiling unicode-ident v1.0.12
Compiling syn v2.0.72
Compiling serde_derive v1.0.204
Compiling serde v1.0.204
Compiling tokio v1.39.2
Compiling lean-ctx v2.1.0
Finished `dev` profile [unoptimized
+ debuginfo] target(s) in 24.3s cargo build - 压缩后 ~30 tokens
cargo build (compressed)
✓ build dev 24.3s 7 crates compiled [280 tok saved (90%)]
独立工作
Shell hook 独立于上下文服务器运行。尚未配置的 AI 工具仍受益于压缩的 shell 输出。Hook 在 shell 层面拦截,因此每个运行命令的工具都获得节省。
Cursor Claude Code GitHub Copilot Aider Any shell-based AI
覆盖率
模式覆盖率 一览。
34+
命令类别
95+
特定模式
87%
平均 git 压缩率
0
需要的配置
Docker & Container Environments
In containers, non-interactive shells skip ~/.bashrc. Set BASH_ENV to point at lean-ctx's dedicated env.sh file, which has no interactive-mode guard. For Claude Code, also set CLAUDE_ENV_FILE.
# In your Dockerfile:
ENV BASH_ENV="/root/.lean-ctx/env.sh"
ENV CLAUDE_ENV_FILE="/root/.lean-ctx/env.sh" lean-ctx includes self-healing: if the env.sh file is removed (e.g., by a container rebuild), lean-ctx init --global re-creates it automatically.
需要完整输出? 使用原始模式。
当你需要未压缩的输出时,用一个标志绕过压缩。不再有静默数据丢失--截断始终透明。
# CLI flag - skip compression for one command
lean-ctx -c --raw kubectl get pods -o yaml
# Shell function - quick bypass
lean-ctx-raw gh pr view 42
# Kill-switch - disable ALL compression
LEAN_CTX_DISABLED=1 lean-ctx -c git log
# MCP parameter - for AI agents
ctx_shell(command="cat config.json", raw=true)