agentsclimarketplace

Context optimization

Skill VersoXBT/claude-initial-setup/skills/memory-management/context-optimization

75 skills, 14 agents, 15 commands for Claude Code. Plug-and-play starter kit covering TypeScript, Python, Go, Rust, React, Next.js, FastAPI, Django, Docker, CI/CD, security, testing, and more. Cross-AI support for Cursor, Copilot, and Codex.

Install
npx -y skills add VersoXBT/claude-initial-setup --skill context-optimization

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Strategies for managing Claude Code's context window efficiently: token budgeting, progressive disclosure, reference files, and using subagents to protect context. Use when conversations are getting long, the user mentions context limits, or tasks involve reading many files.

SKILL.md

5.7 KB, ~1.3k tokens by cl100k_base, as published. Nobody here has run it

Context Optimization

Claude Code's context window is finite. Efficient use of context enables longer sessions, larger refactors, and deeper analysis without hitting limits or losing important earlier information.

When to Use

  • Conversation is approaching context limits (system may compress earlier messages)
  • Task requires reading many large files
  • User mentions running out of context or losing earlier information
  • Planning a large refactoring or multi-file implementation
  • Deciding whether to use subagents vs direct tool calls

Core Patterns

Token Budgeting

Estimate context costs before reading files:

Small file (< 100 lines):   ~500-1000 tokens   -- Read freely
Medium file (100-500 lines): ~1000-5000 tokens  -- Read if needed
Large file (500+ lines):     ~5000+ tokens      -- Use offset/limit or subagent

For large files, read only the relevant section:

Read:
  file_path: "src/services/auth.ts"
  offset: 150    # Start at line 150
  limit: 50      # Read only 50 lines

Progressive Disclosure

Start with structure, then drill into details:

# Step 1: Understand the project structure (cheap)
Glob: "src/**/*.ts"

# Step 2: Find the relevant area (cheap)
Grep: pattern "export function authenticate"

# Step 3: Read only the relevant file (targeted)
Read: "src/middleware/auth.ts"

# Step 4: Read related files only if needed
Read: "src/types/auth.ts"

Do not read all source files upfront. Discover what you need, then read it.

Reference Files Instead of Inline Content

When a file's contents have been read and discussed, refer to it by path and line number instead of quoting large blocks:

# EXPENSIVE: Quoting 30 lines of code in your response
"The function at lines 45-75 does X, here is the full code: ..."

# EFFICIENT: Reference by path and line
"The authenticate function at src/middleware/auth.ts:45 handles
token validation. The error branch at line 62 needs updating."

Subagents as Context Firewalls

Use subagents when exploration would consume too much main context:

# BAD: Reading 15 files directly into main context
Read: "src/db/users.ts"
Read: "src/db/posts.ts"
Read: "src/db/comments.ts"
... (12 more files)

# GOOD: Delegate to subagent, receive summary only
Agent (Explore):
  prompt: "Read all files in src/db/. For each file, report:
           1. Table/model name
           2. Key query functions
           3. Whether it uses parameterized queries
           Return a concise table with these columns."

The subagent reads all 15 files in its own context. The main context receives only the summary table.

Targeted Grep Before Read

Use Grep to locate exactly what you need before reading entire files:

# Step 1: Find where the function is defined
Grep:
  pattern: "export function processPayment"
  output_mode: "content"
  -C: 3

# Step 2: Read only if you need more context around it
Read:
  file_path: "src/services/billing.ts"
  offset: 120
  limit: 40

Context-Sensitive Task Sizing

Match task complexity to remaining context:

High context remaining (early in session):

  • Large refactors across multiple files
  • Feature implementation spanning many components
  • Deep codebase exploration

Low context remaining (late in session):

  • Single-file edits
  • Independent utility creation
  • Simple bug fixes with known location
  • Documentation updates

Avoiding Context Waste

Common context wasters to avoid:

# WASTE: Reading a file you will not modify
Read: "package.json"  # Just to "check" — only read if you need specific info

# WASTE: Reading the same file twice
Read: "src/app.ts"  # Read earlier in session
Read: "src/app.ts"  # Reading again because you forgot — check conversation first

# WASTE: Large verbose tool output
Bash: "npm list --all"  # Produces hundreds of lines
# Better: "npm list --depth=0"  # Top-level only

# WASTE: Reading generated files
Read: "dist/bundle.js"  # Generated, not useful
Read: "node_modules/..."  # Never read node_modules

Anti-Patterns

  • Reading everything upfront: Do not read all project files at the start of a session. Use progressive disclosure — start with structure, drill into specifics.
  • Ignoring offset/limit: For large files, always use offset and limit to read only the relevant section. Reading a 2000-line file when you need lines 500-520 wastes context.
  • Quoting code back to the user: The user can see the file. Reference by path:line instead of copying 30 lines into your response.
  • Repeating tool calls: If you already read a file earlier in the session, do not read it again. Use your conversation history.
  • Using verbose bash output: Commands like npm list --all, find / -name "*.ts", or git log without limits dump large amounts of text. Always constrain output with flags or pipes.

Quick Reference

StrategyWhenHow
Progressive disclosureStarting explorationGlob -> Grep -> Read (targeted)
Offset/limitLarge filesoffset: N, limit: M on Read
Subagent firewallMany files to analyzeAgent (Explore) with summary prompt
Reference by pathDiscussing codefile.ts:line instead of quoting
Targeted grepFinding specific codeGrep with context before Read
Output constraintsBash commandsUse --depth, head, tail, flags

Rule: Read only what you need, when you need it. Summarize, do not quote.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 327,132. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.