Long coding-agent sessions are a black box. You come back after twenty minutes and the task is done (or not), but you don't really know which files the agent read, which commands it ran, or why that session cost three times more than yesterday's.
I started asking this when I switched between models. The same kind of task cost very different amounts depending on the model, and I couldn't tell where the difference came from. Was the expensive model doing better work, or just more work?
So I built TreeRing, a small local CLI that records every tool call a coding agent makes. Here are the design decisions behind it and what I learned.
1. Hook in, don't proxy
Claude Code (and opencode, Grok Build) expose hooks around tool calls. TreeRing attaches to those instead of sitting in front of the model as a proxy. That means:
- no network interception, nothing leaves your machine
- it sees the actual tool calls, not just tokens
-
treering initattaches it,treering init --removedetaches it
2. Make the log tamper-evident
An audit log the agent can quietly edit isn't worth much. Each entry is hash-chained to the previous one, with optional forward-secure seals and external anchors. If anything is edited or the history is truncated, treering verify shows it.
One rule I settled on: sealing is run by you, not the agent. The thing being audited shouldn't hold the pen.
3. No LLM in the decision
Risky actions (reading .env, credentials or SSH keys, curl | bash, force-push) are flagged by deterministic rules. I didn't want a second model judging the first, because a prompt injection that can steer the agent could also argue with an LLM judge. Rules are boring, but they can't be talked out of anything.
It's log-only by default. --enforce turns flags into blocks.
4. Waste is mostly a few patterns
When I looked at the logs, most wasted tokens came from a few patterns, and simple heuristics catch them:
- Failure loops: 3+ failed calls in a row
- Repeated reads of the same file
- Large outputs: 50KB+ dumped into context
- Slow calls (1 min+) and requests with 40+ tool calls
5. Cheaper models were often enough
The biggest surprise was how much performance varied by model, and how often a cheaper model was good enough. On many tasks the expensive model didn't produce better results. It just made more calls, read more files, and dumped more output into context.
Once I could see where the tokens went, the fix was usually not "use a bigger model" but tuning the setup to the work: giving the agent the right skills for the task, cutting what it didn't need to read, and setting the effort level to match the job. With that, a cheaper model handled a lot of my day-to-day work, and the savings came from the setup, not from compromising on results.
Try it
uv tool install treering && treering init
Or as a Claude Code plugin:
/plugin marketplace add jiwoomap/treering
Then treering insights, treering summary, or treering ui.
Honest limits
- Early prototype (v0.0.10)
- It's an audit tool, not a sandbox: it runs as your user
- Cost numbers are exact for opencode, estimates for Claude Code / Grok Build
- macOS / Linux only for now
What's next
I'd like to add detectors for the waste patterns people actually hit. If your agent burns tokens in a way that isn't listed above, or you've found setups where a cheaper model does the job, tell me in the comments.
Repo (Apache-2.0): Docs: https://jiwoomap.github.io/treering/
jiwoomap
/
treering
Least-knowledge security layer for LLM agents: prompt-injection isolation (privileged planner never sees untrusted data), provenance-tagged values, human-in-the-loop approval, and a tamper-evident hash-chained audit log. Inspired by tree rings.
TreeRing — least-knowledge security layer for LLM agents
TreeRing is an open-source (Apache-2.0) Python security layer for LLM agents that defends against prompt injection by isolation rather than detection: the privileged planner never sees untrusted data, quarantined readers have no tools, values carry provenance tags, and every decision is written to a tamper-evident, hash-chained audit log with human-in-the-loop approval where it matters. The design borrows from dendrochronology — tree rings (나이테) record the conditions of each year without the tree ever being asked.
A tree does not grow in order to keep records. Growing is the record If we can build AI agents the same way, we can cut them open later and read what happened.
Status: early prototype (v0.0.10, 2026-12) · License: Apache-2.0 · Keywords: AI agent security, LLM security, prompt injection defense, information flow control, capability-based security, provenance, audit log, AI safety, MCP



Top comments (1)
把 agent 的黑盒打开这个思路很好,尤其是 hook 而不是 proxy 的做法:不拦截网络、只记录真实 tool call,既看得到实际行为,又不用担心流量被改写。failure loops、重复读同一文件、50KB+ 大输出这几类浪费模式也很贴合日常,我遇到最多的就是 agent 反复读同一个文件。hash 链防篡改加人工 sealing 也合理,被审计对象不该自己握笔。想问一下:treering insights 里有没有按文件或工具聚合的视图?如果能一眼看出哪个文件被反复读,定位会更快。