Claude Code v2.1.86 Fixes /compact Failures, Adds Context Usage Tracking

Claude Code v2.1.86 Fixes /compact Failures, Adds Context Usage Tracking

Latest update fixes critical /compact bug, adds getContextUsage() for token monitoring, and improves Edit reliability with seed_read_state.

GAla Smith & AI Research Desk·3d ago·4 min read·1 views·AI-Generated
Share:
Source: github.comvia gh_claude_sdk, gh_claude_releasesCorroborated
Claude Code v2.1.86 Fixes /compact Failures, Adds Context Usage Tracking

What Changed — Critical Fixes and New Monitoring

The Claude Agent SDK TypeScript just released v0.2.86, bringing Claude Code to version 2.1.86. This isn't just another incremental update—it fixes a critical bug that was breaking workflows and adds essential monitoring tools.

The most important fix: /compact was failing with "context exceeded" errors when conversations grew so large that the compact request itself couldn't fit. This was a frustrating edge case that could derail long sessions. Now it's resolved.

New monitoring capability: Added getContextUsage() control method that returns a breakdown of context window usage by category. This is the first native way to see exactly how your tokens are being allocated.

Edit reliability improvement: The SDK now includes seed_read_state control subtype to seed readFileState with {path, mtime} data. This ensures Edit operations continue working even after the original Read has been removed from context—crucial for maintaining file consistency in long-running sessions.

What It Means For Your Daily Workflow

/compact Now Works in All Scenarios

Previously, if you had a massive conversation and tried to compact it, the compact request itself could exceed context limits, causing the entire operation to fail. This forced manual cleanup or session restarts. Now /compact handles these edge cases gracefully.

When to use it: Continue using /compact regularly to manage token usage, but now you can be confident it won't fail on large sessions. This follows Anthropic's ongoing focus on improving Claude Code's reliability for complex, long-running tasks—a trend we've seen accelerate since their March 2026 Auto Mode release.

Monitor Your Token Allocation

The new getContextUsage() method gives you visibility into how Claude Code is using your context window:

// Example usage in your Claude Code integration
const usage = await claudeAgent.getContextUsage();
console.log(usage);
// Returns breakdown like:
// {
//   totalTokens: 120000,
//   conversationHistory: 45000,
//   fileContents: 35000,
//   systemPrompt: 15000,
//   toolResults: 25000
// }

Why this matters: You can now identify what's consuming your context. Is it file contents? Conversation history? Tool results? This data lets you optimize your workflow—maybe you need more aggressive file pruning, or shorter conversation summaries.

More Reliable File Editing

The seed_read_state fix addresses a subtle but important issue: when Claude reads a file, makes changes elsewhere, then returns to edit that original file, it needs to know the file's state hasn't changed. Previously, if the original Read was compacted out of context, edits could fail or create conflicts.

Practical impact: Your file editing workflows are now more robust, especially when working across multiple files or in sessions that span hours.

Try It Now — Update and Configure

Update the SDK

# Update to the latest version
npm install @anthropic-ai/claude-agent-sdk@0.2.86
# or
pnpm add @anthropic-ai/claude-agent-sdk@0.2.86

Enable Session State Events (Optional)

If you're building integrations that need to track session state changes:

# Set this environment variable to receive session_state_changed events
export CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS=1

Note: These events are now opt-in to reduce overhead for most users.

Other Notable Improvements

  • Terminal fixes: Ctrl+C and Ctrl+D now work correctly after quitting in Ghostty, Kitty, WezTerm, and other terminals supporting the Kitty keyboard protocol
  • Performance: Reduced UI stutter when compaction triggers, improved scroll performance with large transcripts
  • MCP improvements: One headers helper can now serve multiple servers using CLAUDE_CODE_MCP_SERVER_NAME and CLAUDE_CODE_MCP_SERVER_URL environment variables
  • Hook optimization: Added conditional if field for hooks using permission rule syntax (e.g., Bash(git *)) to filter when they run, reducing process spawning overhead

When You'll Notice the Difference

  1. Long refactoring sessions: When you've been working for hours and /compact previously failed
  2. Memory-intensive tasks: When you need to monitor why you're hitting context limits
  3. Multi-file projects: When editing files that were read much earlier in the session
  4. Integration development: When building tools on top of Claude Code that need session state visibility

This update continues Anthropic's pattern of addressing real workflow pain points—not just adding features, but fixing what breaks. The /compact fix alone makes this a must-update for power users.

AI Analysis

**Immediate action:** Update to Claude Code v2.1.86 today. The `/compact` fix alone justifies it—no more worrying about compaction failures during long sessions. **New workflow to adopt:** Start using `getContextUsage()` in your integrations or mental model. Before this, you could only guess what was eating your context. Now you can measure it. If you're building Claude Code tools, add context usage logging to identify optimization opportunities for your users. **Configuration change:** If you disabled `/compact` due to reliability issues, re-enable it. The fix handles the edge case where the conversation was too large to even request compaction. For integration developers, consider whether you need `CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS=1`—most users won't, but if you're building session management tools, this gives you finer control. **Related technique:** This aligns with our March 27 article "How to Monitor Claude Code's Performance Drift Before It Breaks Your Workflow"—now you have native tools to complement those monitoring strategies. Combine `getContextUsage()` with the performance tracking approaches we covered for complete visibility.
Enjoyed this article?
Share:

Related Articles

More in Products & Launches

View all