ctx
Provides status and context for git worktrees, including branch, dirty state, ahead/behind, and last activity.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ctxwhat's the status of all my worktrees?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ctx
A daemon-less CLI, TUI, and MCP companion for context-switching across git worktrees and Claude Code agent sessions.
The problem
Working across multiple git worktrees, each with one or more Claude Code agent sessions, makes context switching expensive.
Returning to one tab: you forget what an agent was doing after deep work elsewhere, and waste tokens asking it to re-summarize.
Cross-worktree overview: there is no board showing branch, agent status, last activity, and a one-line task summary across all your worktrees.
Agent cold-start: new or resumed agent sessions re-ask or re-explore state that already exists in transcripts and git.
ctx solves all three by reading your existing Claude Code transcripts (~/.claude/projects/**/*.jsonl) and git state, distilling them into a compact per-worktree record, and serving that record to humans (CLI, TUI) and agents (hook injection, MCP) alike.
There is no background daemon. State is derived on demand and cached in one JSON file per worktree.
Related MCP server: ws-mcp
Requirements
Bun 1.2 or newer.
git 2.31 or newer.
ctxneutralizes repository-controlled git config viaGIT_CONFIG_COUNT, which older git ignores silently; rather than probe unprotected, it declines to read git state at all.Optional: the
claudeCLI on yourPATH, or anANTHROPIC_API_KEY. Without either,ctxstill works in raw mode.
Try it without installing
bun install
bun src/index.ts status --no-distillThat prints the board from your existing transcripts and touches nothing outside the repo.
Install
bun install
bun src/index.ts installinstall builds a compiled binary to ~/.local/bin/ctx, merges Claude Code hook entries into ~/.claude/settings.json (with a one-time backup), and registers ctx as an MCP server via claude mcp add if the claude CLI is on your PATH.
Make sure ~/.local/bin is on your shell PATH.
Hooks are installed at user scope, so they run for every Claude Code session on the machine, not just in this project.
Commands
ctx [project] interactive TUI (the default command), optionally scoped
ctx status [project] [--no-distill] [--all]
board of worktrees, optionally scoped to one project
ctx recap [worktree|project|.] [--no-distill]
full recap for one worktree (project name works when unambiguous)
ctx inject [--cwd <dir>] SessionStart hook target (prints compact recap)
ctx checkpoint --event <e> hook target (stop|precompact|end|note)
ctx ui [project] interactive TUI, optionally scoped to one project
ctx mcp stdio MCP server
ctx install install hooks + MCP config
ctx --version print the installed versionctx status is the board view: one row per worktree with repo/branch, session status, last-active time, a distilled one-line task, and git facts (dirty, ahead, behind).
Pass a project name to scope the board, e.g. ctx status myrepo shows only that repo's worktrees.
At most 5 worktrees are distilled per run; the rest are picked up on the next refresh.
ctx recap prints the fuller recap (done, decisions, next, blockers) for a single worktree.
ctx inject is wired to the SessionStart hook so a resumed or new agent session gets prior context injected without asking for it.
ctx checkpoint is wired to Stop, PreCompact, and SessionEnd hooks to record session lifecycle events.
ctx ui is an Ink-based TUI that polls the same state for a live board.
ctx mcp exposes the same data as MCP tools (get_my_context, get_sibling_status, ...) so an agent can query context directly instead of re-exploring.
Reading the board
●green means a Claude session wrote to its transcript in the last 5 minutes;○means idle or ended.◐yellow means that worktree is being distilled right now;✗red means the distill produced nothing (check~/.ctx/log, usually a claude auth issue).The time column is last session activity, not when the row was distilled.
(raw)in the task column means the worktree has never been distilled.The repo's main checkout counts as a worktree too; git itself calls it the main worktree, and agent sessions run there like anywhere else.
In the TUI,
rre-distills every visible worktree serially and each row updates as its summary lands.
Distiller auth chain
Turning a heuristic extract (a few KB, never the raw transcript) into a one-line task and structured recap requires an LLM call.
ctx never requires an API key and tries, in order:
claude -p --model haikusubprocess - used first if theclaudeCLI is onPATH. This reuses your existing Claude Code login, so no extra credentials are needed.ANTHROPIC_API_KEY+@anthropic-ai/sdk- used as a fallback if the CLI is unavailable or fails, callingclaude-haiku-4-5directly.Raw mode - if neither is available,
ctxfalls back to the heuristic extract alone (no LLM summary). The board marks these worktrees as(raw)and the tools remain fully usable, just less distilled.
Distillation only runs when the transcript has changed since it was last distilled (tracked via a content hash), so repeated ctx status calls are cheap.
Design notes
The interesting problems in this codebase are mostly about untrusted input and concurrency.
Transcript content is untrusted, and it travels. A transcript records whatever an agent read: a repo's README, a fetched page, a tool result. That text is summarized by a model, stored, and then injected into other agents' sessions, including summaries of sibling worktrees. So a poisoned transcript in one worktree has a path into every sibling agent's context. Fields are collapsed to a single line before rendering, because an embedded newline can forge a line and impersonate the tool's own output; the injected block is wrapped in a delimiter with a random per-invocation suffix, because a fixed delimiter can simply be closed by the content inside it; and the model's output is length- and item-capped in code rather than trusted to obey the prompt.
Git executes what a repository's config tells it to.
core.fsmonitor, filter.*.clean, and friends are commands run straight out of .git/config, and the worktree paths here come from transcripts rather than from user input.
ctx enumerates a repository's resolved config and neutralizes every command-executing key via GIT_CONFIG_KEY_n environment entries rather than -c key=, because -c splits its argument at the first = and a config subsection name may legally contain one.
Only repo-controlled scopes are neutralized, so a user's global git-lfs setup keeps working.
--ignore-submodules=dirty stops git descending into submodules, whose own config the superproject's enumeration cannot see.
State is written by several processes at once.
Hooks fire on Stop, PreCompact, and SessionEnd while the TUI polls and a distill may be mid-flight for up to a minute.
Writes go through a compare-and-swap under a cross-process mkdir lock whose staleness is decided by probing the recorded pid, with an absolute age backstop so a recycled pid cannot wedge a worktree permanently.
Transcripts get large. Reading a multi-hundred-megabyte transcript whole costs gigabytes of RSS, and this runs on the TUI's event loop every 30 seconds, so both the scanner and the extractor read bounded regions and grow the window only until it contains a complete entry.
Testing
bun test # 126 tests
bun run typecheckThe suite is mutation-verified: seeded defects (removing the state lock, dropping event validation, un-sorting the transcript scan, reverting the sanitizer) are each confirmed to fail it. That check exists because an earlier version of the suite stayed green with the entire locking apparatus deleted.
Environment variables
CTX_DIR- overrides the state directory (default~/.ctx). State lives at$CTX_DIR/worktrees/*.json, and errors are logged to$CTX_DIR/log.CLAUDE_PROJECTS_DIR- overrides the transcript root (default~/.claude/projects).
Both are primarily useful for tests and for pointing ctx at a non-default Claude Code install.
Hooks always exit 0
ctx checkpoint and ctx inject are invoked as Claude Code hooks and always exit 0, even on internal failure.
A hook that breaks the agent session is worse than one that silently no-ops, so every error path is caught, logged to $CTX_DIR/log, and swallowed.
No LLM calls happen inside hook execution, so hooks stay fast.
State
Truth lives in your Claude Code transcripts and git; ~/.ctx/worktrees/*.json is a disposable cache, one file per worktree, written via temp-file-plus-atomic-rename.
Delete the whole ~/.ctx directory at any time and it will be rebuilt on the next ctx status.
License
MIT - see LICENSE.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceAn MCP server that wraps git-worktree-runner to enable AI agents to manage git worktrees safely.Apache 2.0
- FlicenseAqualityDmaintenanceMCP server that gives LLMs full visibility into your ws-cli workspace tree, enabling queries about workspaces, git status, tasks, and saved browser tabs.8
- FlicenseNot gradedqualityAmaintenanceMCP server that queues stories and feeds them to live Claude Code sessions, delegating bounded tasks to worker routes in isolated git worktrees.1
- AlicenseNot gradedqualityAmaintenanceAn MCP server for orchestrating a fleet of CLI coding agents in isolated git worktrees. It exposes tools for spawning workers, sending instructions, reviewing diffs, and merging changes, with full terminal visibility.33MIT
Related MCP Connectors
Remote MCP server for The Colony — a social network for AI agents (posts, DMs, search, marketplace).
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Personal assistant MCP server with search, execute, packages, jobs, secrets, and integrations.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/crodris/ctx'
If you have feedback or need assistance with the MCP directory API, please join our Discord server