ctxtree
Pick up a Claude Code session from a folded, lossless view of its history, instead of paying to take its whole window in again.
Claude Code's prompt cache lasts an hour on a Claude subscription (five minutes on an API key). Come back to a long session after that, and its whole window is processed again: often hundreds of thousands of tokens. Most of that window is tool output from long ago; the conversation itself is a small part of it.
ctxtree reads the session's log and folds it into a tree: stretches of work, the turns in them, and one line for each tool call. A new session starts from a short opening message (a map of the work, and the current task word for word) and opens the rest when it needs to. Nothing is summarized away: every part opens back to the exact text in the log.
Install
pip install ctxtree # or: pipx install ctxtree
npx ctxtree # the same tool through npm; needs Python 3.8 or newer
Use
In a project folder, type ctxtree. It says what your last Claude Code session there was doing, whether its cache is
still warm, and what each way back costs at list price:
api: your last session here (3f9a1c02) was active Nov 30 14:02, 3 hours ago.
The task: "move the billing webhooks to the new queue"
Its cache has cooled. Going back to it re-caches its whole window: 612k tokens, about $4.90 at list price.
Starting fresh from the folded view instead: about 52k tokens, about $0.42 at list price, with every word still reachable.
ctxtree resume start a new session from the folded view
ctxtree show read the folded view yourself
ctxtree level see or change how much it holds (now auto)
ctxtree resume starts Claude Code there, told to read the folded view first. Every command works on the newest
session in the folder you're in, unless you give a session id (or its first 6 characters).
The rest, mostly for the agent in the new session:
ctxtree search 'webhook' # where a word or regex appears, in what was said and in tool output
ctxtree open t21.3 # e3 a stretch of work, t21 a turn, t21.3 one tool call with its full input and output
ctxtree search --here 'queue' # every session in this folder from the last 30 days
ctxtree status --json # warm or cooled, and what each way back costs, read fast from the end of each log
ctxtree check --all # prove nothing is lost: every tool call and result opens to exactly what the log holds
How much the opening holds works like Claude Code's effort setting. auto, the default, holds the current task
word for word and a map of the rest, about 8k to 24k tokens. low, medium, high, xhigh and max hold about 2k,
8k, 24k, 64k tokens, or every turn; a size such as 30k works too. ctxtree level high saves one; ctxtree levels
shows what each would hold for a session.
Does it work?
In two small blind tests on five real sessions, an agent was asked 50 questions about earlier work.
- Working from the folded view, with
searchandopen: 49 answered right, at a fifth to a tenth of the cost of resuming. - Resuming the old session: 32 answered right. That was all 20 where nothing had been compacted, and 12 of 30 where compaction had dropped the older work.
It's a small sample, so treat it as a sign, not a proof.
What it touches
- It reads Claude Code's session logs in
~/.claude/projectsand prints. It sends nothing anywhere. - It writes three things:
- the level you save, in
~/.config/ctxtree/config - the opening message for
resume, in~/.local/state/ctxtree/, readable by you only - the sizes of fresh starts, in
~/.cache/ctxtree/(numbers only)
- the level you save, in
- It never watches what you type.
- Limits: it knows Claude Code's log format only. It leaves out sub-agents' own steps; each one's result shows as the tool call that started it. Prices are list prices for current Claude models.
License
Apache-2.0
Metadata
Release files for ctxtree 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ctxtree-0.1.0.tar.gz | 21.6 kB | Without provenance | Details for ctxtree-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ctxtree-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ctxtree-0.1.0-py3-none-any.whl |
Total release size: 43.6 kB
Release files / ctxtree-0.1.0.tar.gz
| Download URL | ctxtree-0.1.0.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4646842a8597c09c235470b1c96e29bb36dfb96f3920e8bf1f7024b0c9e3de0f
|
|
BLAKE2b-256 checksum How to use checksums |
02660b2f05c3cbda9c8e40975f69dcf0c91d7c0a45fa845c093aa8ba621542cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / ctxtree-0.1.0-py3-none-any.whl
| Download URL | ctxtree-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
255e9cc282915e21de923265072b0ffb8bb1fab74dfddd402ca7b13e01688f56
|
|
BLAKE2b-256 checksum How to use checksums |
644bf423ee0c4e9dcbdb70488396466f3a73226418788992a14d37934081be1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for ctxtree 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.