context-sweet-spot

Analyzes coding-agent session traces in LangWatch to find the context size where costs outrun value.

3.5k|362|Updated Sep 9, 2023
One-click install
npx skills add https://github.com/langwatch/langwatch --skill context-sweet-spot
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: context-sweet-spot
Source: https://github.com/langwatch/langwatch/tree/main/skills/_compiled/native/context-sweet-spot
Command: npx skills add https://github.com/langwatch/langwatch --skill context-sweet-spot

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires langwatch.

What problem does it solve?

Long context in coding-agent sessions is not free: cache rebuilds re-bill the whole context, compactions burn turns, and models degrade before their window ends. This Skill uses your own LangWatch session data to find the context size where your sessions stop being economical.

Core Features & Use Cases

  • Session Collection: Exports coding-agent traces via the langwatch CLI and pulls per-session events including token usage, cache reads/writes, costs, compactions, and rate limits.
  • Economics Computation: Calculates peak context share, cache rebuild counts, compaction timing, and cost per model call across session lifetime, then buckets sessions by context share.
  • Actionable Report: Produces a self-contained HTML report naming the context threshold where sessions degrade, with bucket comparisons, dissected expensive sessions, and concrete habits backed by example session links.
  • Use Case: Your Claude Code sessions feel slower and pricier as they grow. Run this Skill to learn that your sessions stay economical up to about 55% of the context window, and get specific guidance on when to start fresh sessions or offload work to sub-agents.

Quick Start

Ask the assistant to find your context sweet spot by analyzing your recent coding-agent sessions in LangWatch.

Frequently Asked Questions about context-sweet-spot

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find the context sweet spot for my coding agent sessions?

Install the langwatch CLI with npm install -g langwatch, sign in with langwatch login --device, then run this Skill. It exports your coding-agent traces, computes cache rebuilds and cost per call across context-size buckets, and reports the threshold where sessions degrade.

How do I analyze LLM session costs in LangWatch?

Use langwatch trace export with --origin coding_agent to pull session traces, then langwatch session events for per-call token and cost data. This Skill automates that workflow and aggregates the economics into a single report.

Does this work with Claude Code and other AI coding assistants?

Yes, it works with Claude Code and similar AI assistants as long as their sessions are traced into LangWatch. The langwatch CLI is the only interface required, and sessions are identified by metadata.thread_id and the langwatch.source field.

Why do long coding-agent sessions get more expensive per turn?

Cache rebuilds re-bill the entire context at the provider's cache-write rate, and compactions consume turns. The Skill measures rebuild rate and cost per call across session thirds to show exactly where costs start outrunning the value of carried context.

What are the limitations of this context analysis?

Sessions with fewer than 5 model calls are excluded since they carry no lifetime signal, and sessions across different models must be bucketed separately because window sizes and cache pricing differ. Truncated exports also produce sampled rather than complete buckets.