Clarity
Claude Code context and token management — official-docs-first, self-contained.
Status: v0.0.6 · public alpha — ships across four surfaces (CLI · MCP server · Claude Code plugin · slash-command skill), validated against the latest official specs (MCP 2025-11-25, Claude Code 2.1.114).
Honest coverage (per the blog that motivates this project): Clarity v0.0.6 addresses ~30% of the branch-point decisions the blog names. Statusline covers continue / /clear / /compact reasoning via ctx% and cache-age. /rewind, subagent suggestions, and task-switch detection are NOT yet implemented — see Roadmap and the gap table below.
The problem
Anthropic's own session-management blog identifies five decisions you face at every turn (continue, /rewind, /clear, /compact, subagents) and two main failure modes: context rot past ~300-400k tokens, and bad /compact when the model summarizes without knowing your next step.
Most Claude Code users pay these taxes silently. Claude Code doesn't warn you before a bad /compact. It doesn't tell you your cache just expired. It doesn't flag a check X prompt about to balloon into a 800M-token session.
And the real driver — poor .claude/ project structure — forces every session to re-explore the same codebase, burning tokens on work the structure should have prevented.
The approach
Clarity does three things today, all built from Anthropic's own official guidance:
- Doctor — read your session logs, your
~/.claude/ and project .claude/ config, your plugins and rules. Report where the tokens actually go. Recommend fixes only from official docs.
- Install — set up Clarity itself in Claude Code through the plugin, CLI, MCP, and statusline surfaces. Project-specific
.claude/ scaffolding is planned, but it is not shipped in v0.0.6.
- Run with you — sit quietly in the statusline. Warn before cache expires, before bad
/compact, before a known trap prompt. One suggestion, one keystroke to accept.
What Clarity will never do
- Run your prompts through its own servers
- Obfuscate or minify its source
- Require an external account
- Invent rules not in Anthropic's official docs
Installation
Clarity ships in four interchangeable forms. Install one or all — they share the same analyzer under the hood.
1. Claude Code plugin (recommended for Claude Code users)
bash -lc '
set -euo pipefail
dir="$HOME/.claude/clarity"
repo="https://github.com/agent-next/clarity.git"
ref="v0.0.6"
if [ -d "$dir/.git" ]; then
git -C "$dir" fetch --tags origin
elif [ ! -e "$dir" ]; then
git -c advice.detachedHead=false clone --depth 1 --branch "$ref" "$repo" "$dir"
else
echo "$dir exists but is not a git checkout" >&2
exit 1
fi
CLARITY_REPO_REF="$ref" "$dir/install.sh"
'
This installs Clarity into ~/.claude/clarity, validates the plugin, registers the local marketplace, and installs clarity@clarity so Claude Code can use /clarity-doctor. The install flow is git-based instead of depending on a raw-content endpoint, so it works with the same repo access you already use for git clone.
Manual fallback:
git -c advice.detachedHead=false clone --depth 1 --branch v0.0.6 https://github.com/agent-next/clarity.git ~/.claude/clarity
CLARITY_REPO_REF=v0.0.6 ~/.claude/clarity/install.sh
The plugin ships:
/clarity-doctor [days] slash command
- Skill frontmatter with
when_to_use and effort: low so Claude invokes it at the right moment
- Plugin cache path:
~/.claude/plugins/cache/clarity/clarity/0.0.6/
Verify:
claude plugin list | grep clarity
2. Standalone CLI
The CLI works with or without the plugin — useful for scripting, CI, or cron jobs. If you used the recommended install above, the repo checkout already lives at ~/.claude/clarity.
# Symlink once for a short PATH entry
ln -s ~/.claude/clarity/bin/clarity /usr/local/bin/clarity
clarity doctor --since-days 30
clarity doctor --since-days 7 --json
clarity version
clarity help
3. MCP server
Expose clarity_doctor as an MCP tool to any compliant client (Claude Code, Claude Desktop, other agents).
Add to your project's .mcp.json:
{
"mcpServers": {
"clarity": {
"command": "python3",
"args": ["/Users/you/.claude/clarity/mcp/server.py"]
}
}
}
Protocol: JSON-RPC 2.0 over stdio, MCP spec 2025-11-25. Exposes one tool (clarity_doctor) with a single since_days parameter and returns the same Markdown doctor report as the CLI. No external account, no telemetry.
4. Statusline integration
Append to your ~/.claude/statusline-command.sh:
# your existing statusline output first ...
clarity=$(printf '%s' "$input" | sh "$HOME/.claude/clarity/scripts/clarity-status.sh" 2>/dev/null)
[ -n "$clarity" ] && printf ' · %b' "$clarity"