Metadata-Version: 2.4
Name: ctxtree
Version: 0.1.0
Summary: Pick up a Claude Code session from a folded, lossless view of its history, instead of re-caching its whole window
Author: CodeWheel
License-Expression: Apache-2.0
Project-URL: Homepage, https://ctxtree.com
Keywords: claude-code,claude,prompt-cache,context,agents
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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

```sh
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:

```sh
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 `search` and `open`:** 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/projects` and 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)
- **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
