FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

crizCraig/claude-code-infinite: Maximize Claude's intelligence with MemTree, an advanced context-management engine · GitHub

Latest commit

 

History

100 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Infinite

  • Maximize Claude's intelligence with context-management from MemTree.dev
  • Supports unlimited-length coding sessions
  • Feels fast and fresh with every message
  • Automatically recalls relevant past information
  • Never compact again

Requirements

Setup

Tip

No Anthropic subscription? See Using Without an Anthropic Subscription below.

  1. Install with npm
npm install -g claude-code-infinite
  1. Run Claude Code Infinite with
ccc

This will guide you through setting up your PolyChat key which you can also get here.

Environments

The tool supports multiple environments (this selects the MemTree compression API only — Anthropic traffic always goes directly from your machine to api.anthropic.com):

Each environment maintains its own separate API key.

Privacy & architecture: your Anthropic credentials never leave your machine

ccc runs a small proxy on 127.0.0.1 and launches Claude Code with only ANTHROPIC_BASE_URL pointed at it. Claude Code keeps its native login — token refresh, plan-default model selection, and rate-limit handling behave exactly like vanilla Claude Code, and your OAuth token is sent only to api.anthropic.com from your own machine.

Claude Code ──▶ localhost proxy (ccc)
                  ├──(messages only, MemTree API key)──▶ api.polychat.co /v1/context_memory
                  │◀──(compressed messages)─────────────┘
                  ├──(memory leg A + your local OAuth)──▶ api.anthropic.com
                  ├──(eligible turns: full-history leg B)▶ api.anthropic.com
                  └──(eligible turns: local A/B grader)──▶ api.anthropic.com
  • Only message content is sent to MemTree for indexing/compression — never credentials.
  • Answer legs and the grader go directly from the local proxy to Anthropic using the authentication Claude Code supplied. PolyChat never sees that credential or Anthropic traffic.
  • If MemTree is unreachable, slow, or your MemTree plan needs payment, ccc degrades to a transparent passthrough so your session is never interrupted.

Inline notices

In interactive sessions, ccc reports these MemTree states as display-only lines in Claude Code:

  • ✓ MemTree · conversation optimized in 4.5s · ~330.3k → 94.6k tokens when indexed conversation history was used and the completed memory response was selected. The success line is green when terminal color is available, and plain when NO_COLOR or a monochrome terminal is configured. ccc uses the standard ANSI green foreground sequence and Node's capability detection, so the same path works in ANSI terminals on macOS/Linux and supported Windows consoles. Latency is the client-observed MemTree request time. The before-count uses MemTree's informational usage.raw_prompt_tokens estimate, including visual-token estimates instead of image transport bytes; the after-count is Anthropic's actual full compressed-input usage. Claude's Count Tokens estimate remains a fallback for older MemTree servers. If neither before-count is available, ccc shows latency only.
  • ⚠ MemTree degraded — this turn ran uncompressed when a blocking compression call fails or times out.
  • ⚠ MemTree degraded — memory response was interrupted; recovered from full history when opt-in speculative delivery emitted a compressed-memory prefix before recovering the rest of the turn from the full-history leg.
  • ⚠ MemTree is off — payment required… once when compression and indexing are disabled for payment.

ccc installs a minimal session-only Claude Code plugin using the repeatable --plugin-dir option. Its MessageDisplay hook changes only what the terminal renders and never alters stored assistant content; a Stop hook supplies a fallback for tool-only responses. That fallback may be saved by Claude Code as non-model hook UI metadata, but it is excluded from resumed model and recap requests. Notices are never added to Anthropic responses or model context, and -p/non-TTY output is left unchanged. Legacy marker cleanup remains for transcripts created by older ccc releases. The payment state can also produce a separate terminal warning at startup.

Claude Code currently displays the original assistant text instead of MessageDisplay replacements while verbose mode is enabled. Turn verbose mode off to see the inline MemTree line.

How it works

When you send a message, we retrieve relevant details and summaries from the prior messages in your thread. These details and summaries populate a memory message. Following the memory message, we append a compressed version of your recent message history. The resulting context-window is dramatically smaller, allowing Claude to process your request with much greater efficacy, lower latency, and reduced cost.

Adaptive memory A/B routing

ccc now checks whether memory is still the best context for each large follow-up turn:

  1. It estimates the size of the entire compressed request. Below 50% of the model's measured effective-context prior, it sends only the memory request.
  2. Above that gate, it starts two streaming requests concurrently: A uses compressed memory and B uses the full history. Models without a prior are compared by default.
  3. By default, both semantic prefixes (about 1,000 tokens each) are buffered while a structured Anthropic grader chooses the response to deliver. A and ties keep memory; only a materially better B selects full history. --ab-speculative instead streams A immediately and lets a B verdict visibly correct course in flight by splicing the full-history answer into the message after a short bridge line.
  4. A memory winner remains active through that human turn's tool loop, including matching Count Tokens calls. The original full tool history is still sent to MemTree for background indexing.

Comparison is deliberately fail-safe: grader failure or timeout keeps memory; in speculative mode, a failed grader gets one off-path retry. A memory arm that dies mid-stream is recovered from the healthy full-history arm when doing so is transcript-safe, and client cancellation aborts both arms and the grader. A route and success notice are installed only after a complete successful response. In speculative mode, once the memory answer has finished — or has started a tool call — a late B verdict is recorded for research but never applied.

Qualifying turns cost more: they make two answer requests plus one grader attempt on the user's Anthropic subscription or API account. Speculative mode may make a second grader attempt after a retryable failure, for up to four Anthropic requests on that comparison turn. The gate avoids that overhead for compact contexts, and the losing answer is aborted right after grading.

Advanced/testing controls:

  • Buffered, grade-before-delivery A/B routing is the default.

  • ccc --ab-speculative opts into commit-A-immediately delivery with SSE splicing; ccc --ab-buffered explicitly selects the default buffered mode. If both flags are supplied before --, the last one wins. The transcript-safety question behind speculative mode — whether Anthropic accepts a spliced assistant message replayed as history — was validated by the S1 replay spike (scripts/spike-s1.mjs) against real Anthropic with Claude Code's own headers, including the tool-use splice shape.

  • CCC_AB_ROUTING=0 disables live A/B routing.

  • CCC_AB_FORCE_VERDICT=A|B|tie replaces the grader with an instant fixed verdict (no grader request). Staging-only: B forces the mid-stream splice/correction path so its UX can be eyeballed; combine with CCC_AB_FORCE_COMPARISON=1 to also bypass the context-size gate.

  • CCC_AB_GRADER_MODEL=<model> pins a fixed grader model; by default, each comparison automatically uses a grader from a different model family than its answer legs.

  • CCC_AB_PREFIX_TOKENS=<n> changes the answer prefix from its 1,000-token default.

  • CCC_AB_GRADER_MEMORY_TOKENS=<n> changes the cap on the memory section of the grader prompt from its 10,000-token default. Oversized memory is excerpted head+tail with an explicit elision marker; Answer A itself always sees the full memory.

  • CCC_AB_PREFIX_TIMEOUT_MS=<ms> and CCC_AB_GRADER_TIMEOUT_MS=<ms> change their 30-second defaults.

  • CCC_AB_SAMPLE_NO_PRIOR=0 skips comparison for models without an effective-context prior.

  • CCC_AB_FORCE_COMPARISON=1 bypasses the size gate for diagnostics.

Routing decisions, both-leg timings and usage, grader diagnostics, fallbacks, and delivery status are recorded in ~/.claude-code-infinite/logs/requests.jsonl.

What this is NOT

This is not a MPC or tool for simply retrieving memories. While we are compatible with all MPC's, tools, and other Anthropic features, these do not prevent your context window from becoming detrimentally large. MCP's and tools are some of the biggest token bloaters and it's exactly these types of messages that we heavily reduce during our compression phase.

Why it works

LLMs get exponentially less intelligent as their input grows.

References:

Furthermore, the above research primarily tests on needle-in-a-haystack tasks, which underestimates the effect for more difficult tasks encountered in coding.

This is why starting sessions from scratch provides such a significant uplift in ability. What we're essentially doing is keeping each session as close to from-scratch as possible by limiting the tokens in Claude's context window to around 30k, or 15% of the standard 200k context-limit, filled precisely with the information relevant to your last message. Read more about how MemTree works here.

Operating System Analogy

It may seem strange that we are advocating for small context windows in a product called Claude Code Infinite. But Infinite is referring to the size of a new memory layer, the MemTree, which is a layer above the context window. This layer is larger and updated more slowly than the LLMs main input, just as disk is larger + slower than RAM.

So you can think of MemTree as an operating system's virtual memory manager. Just as an OS manages RAM by swapping less-used data to disk, MemTree manages the model's context window by intelligently recalling only the most relevant information from past interactions. This ensures that the model always has access to the most pertinent data without being overwhelmed by the entire history of the conversation.

Usage Tips

  • If you want your session to apply to many different tasks, we recommend giving the overall high level goal you want for your session in the first message, e.g. "Refactor this project to remove code smells and bugs". Then followup with lower level tasks in subsequent messages. This as Anthropic models key heavily off the first message. You should also feel free to start new sessions for new tasks. This as the model will continue to have a focused context with your CLAUDE.md and first message always included. Reach out to support@polychat.co if you have any questions or concerns!

  • Add context to your status line to see how MemTree keeps your context small

    /statusline add context % used
  • You want your fresh session context to be 10k tokens or less. If your starting context is more than that, consider reducing the size of your custom MCP's and slash commands to ensure Claude performs at its very best

  • You can resume previous threads with /resume

Troubleshooting

Anthropic auth errors (401s, login prompts)

ccc never touches your Anthropic credentials — Claude Code manages its own login exactly as it does without ccc. If you see auth errors, fix them the vanilla way: run /login inside Claude Code (or claude directly) and re-authenticate.

MemTree degraded / passthrough mode

If you see an inline "⚠ MemTree degraded — this turn ran uncompressed" notice, the compression API is unreachable or your MemTree key is invalid/expired. Your session keeps working uncompressed. Check your key at polychat.co, or delete it from ~/.claude-code-infinite/config.json and re-run ccc to re-enter it.

Using Without an Anthropic Subscription

Claude Code works with an Anthropic API key as well as a subscription — set ANTHROPIC_API_KEY as you would with vanilla Claude Code and run ccc as usual. MemTree compression works the same either way (and saves the most money on API-key billing, since you pay per token).

Note

To use without an Anthropic subscription, choose option 2. "Anthropic Console account", during the Claude Code setup. (Running /logout will also bring you back to this setup.)

You don't need to buy API credits, just login and Claude Code will let you complete setup.

Lastly run /logout within Claude Code and then run ccc

Anthropic API usage will be billed through https://polychat.co.

API Rate limit errors

If you hit your Anthropic subscription's rate limits, you can still continue by running /logout and restarting ccc. This will bill tokens through your PolyChat subscription. Remember that you can use the /resume slash command to resume previous sessions.

About

Maximize Claude's intelligence with MemTree, an advanced context-management engine

Resources

Stars

37 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages


Back | FazBrowse Home | New Git URL