开源 · MIT 许可

bash-agent
极简 AI Agent

bash + awk 的 AI 编码智能体运行时。
零运行时依赖,Go 和 Rust 原生移植版本保持完全相同的语义。

bash-agent — ~/my-project
# 一行安装
$ brew install lloydzhou/tap/bash-agent
==> Downloading bash-agent v3.0.4
==> Installed: bash-agent goagent rustagent
 
# 开始工作
$ bash-agent "扫描这个仓库并总结架构"
🔍 Scanning repository structure...
📁 Found 23 files across 4 directories
📝 Architecture: MVC with event-driven patterns
✅ Done — 3 tools used, 142 tokens cached
 
# 支持多模型(通过 Anthropic 兼容接口)
$ bash-agent -m deepseek-v4-flash "hello"
$ bash-agent --output-format stream-json "stream json 输出"
$ bash-agent -i # 交互模式
0
运行时依赖
4
工具集
13
内置工具
99%+
缓存命中率

为什么选择 bash-agent?

极简哲学,强大功能。从零依赖到智能缓存,每一处设计都在追求极致效率。

零依赖
只需要 bash、awk、curl、rg 四个系统工具。无需 Node.js、Python 或任何运行时。一个脚本文件即可运行。
🔄
三端对齐
Bash、Go、Rust 三个版本保持完全相同的 agent loop、tool 和 session 语义。system prompt、tools.json 完全一致。
🚀
异步子 Agent
内建 SubAgent 工具,支持并行执行独立会话。支持 fork 模式继承上下文、会话隔离和故障传播。
💰
缓存感知压缩
基于经济学的 DP 算法自动决策压缩策略。缓存对齐摘要技术可节省约 90% 的 API 费用。
💾
Session 持久化
按项目隔离存储,支持恢复、续接、compact。中断后可以无缝继续之前的对话。
📡
机器友好输出
stream-json 模式输出结构化事件,可被任何上层客户端消费。支持 Claude 和 OpenAI 兼容接口。

缓存性能实测数据

使用 DeepSeek API 的真实缓存命中率数据,展示了缓存感知压缩的卓越效果(10天实测)。

DeepSeek 缓存命中率趋势 (2026)
5/06 — 5/21
总输入 Tokens 618,598,229
总输出 Tokens 2,129,963
平均缓存命中率 99.21%
测试天数 10 天
日期 命中率 分布 输出 Tokens

多版本 + tcode 包装器

从脚本到原生二进制,再到 tmux UI 包装器,按需选择最适合的组合。

🐚
Bash 版
纯 bash + awk 实现,零依赖的单文件脚本。适合快速部署和轻量使用。
bash-agent
🐹
Go 版
原生编译的 Go 移植版本,性能更优。支持 go:embed 内嵌 tools.json。
goagent
🦀
Rust 版
Rust 移植版本,极致性能和内存安全。异步 HTTP 和协作式中断。
rustagent
🖥️
tcode
TMUX 三栏界面包装器,提供 watch sidebar + agent 对话 + 输入框布局。
tcode

一分钟上手

选择你喜欢的安装方式,立即开始使用。

macOS Homebrew 推荐

# 安装三个版本及 tcode 包装器
brew install lloydzhou/tap/bash-agent
 
# 或从 release 下载 tcode
curl -fsSL https://github.com/lloydzhou/bash-agent/releases/latest/download/tcode -o ~/.local/bin/tcode && chmod +x ~/.local/bin/tcode
 
# 启动 tmux 界面
tcode
 
# 设置 API Key
export DEEPSEEK_API_KEY="sk-xxx..."
 
# 开始使用
bash-agent "hello world"

Arch Linux (AUR) 社区

# 使用 yay 安装
yay -S bash-agent
 
# 或使用 paru
paru -S bash-agent
 
# 查看详情
open aur.archlinux.org/packages/bash-agent

手动安装 (Bash 版) 单文件

# 下载单个脚本文件
curl -fsSL https://github.com/lloydzhou/bash-agent/releases/latest/download/agent.sh -o ~/.local/bin/bash-agent
chmod +x ~/.local/bin/bash-agent
 
# 第三方端点
OPENAI_BASE_URL=http://localhost:11434/v1 bash-agent -p openai -m llama3 "hi"

13 个内置工具

覆盖文件操作、搜索执行、Web 访问、任务管理和扩展能力等场景。

📄
文件操作
Read 读取文件内容,支持偏移和限制行数
Write 创建或覆盖写入文件
Edit 精确查找替换编辑文件
搜索与执行
Bash 执行 Shell 命令
Glob 按模式匹配查找文件
Grep 正则搜索文件内容,支持上下文
🌐
Web 访问
WebSearch 搜索网页获取最新信息
WebFetch 抓取 URL 内容转为 Markdown
📋
任务管理
TodoWrite 创建和管理任务清单
PlanConfirm 确认并锁定计划
PlanClear 清除已完成的计划
🧩
扩展能力
Skill 加载技能文件扩展能力
SubAgent 启动子代理并行处理任务