Skip to content

Instantly share code, notes, and snippets.

@will-deines
will-deines / avoiding-subagent-context-overflow.md
Created February 9, 2026 15:31
Claude Code: Avoiding subagent context overflow with file-based result passing

Avoiding Subagent Context Overflow in Claude Code

When Claude Code skills or prompts orchestrate multiple background subagents, a subtle but devastating problem emerges: context overflow from agent transcripts. This guide explains the problem, when it matters, and the battle-tested solution.


The Problem

When you launch a background subagent with the Task tool (run_in_background: true), the natural instinct is to call TaskOutput to collect its results. But TaskOutput doesn't return just the agent's final answer — it returns the entire agent transcript: every web page fetched, every search result, every tool call, every reasoning step.

@will-deines
will-deines / gist:8a60b4d48cd0158f9bd8cb10d5fbf2d9
Last active September 26, 2025 15:43
Modal Snapshot vLLM AsyncEngine
"""
Reproduction script to demonstrate the Modal vLLM engine snapshotting process.
vLLM AsyncEngine in 0.10.2 starts an MP process group with the background loop automatically loaded.
The background loop needs to be killed before snapshotting.
The NCCL group also needs to be destroyed as it will restore the previous RPC which is not actually alive in the restored container.
The MP process group creates a stateless NCCL group that can not be destroyed with the root dist.destroy_process_group.
This causes vLLM snapshots to fail on restore. You need to target the stateless NCCL group and kill it.
@will-deines
will-deines / quantize.py
Created February 24, 2025 18:04
TRT quantize script for use in Modal functions called with kwargs
from typing import Dict, Literal
def quantize_model(
args: Dict, mp_start_method: Literal["fork", "spawn", "forkserver"] = "spawn"
) -> None:
"""
Quantizes a HuggingFace or NeMo model and exports it for TensorRT-LLM.
This function consolidates the functionality of the original script,
@will-deines
will-deines / trt_build_engine.py
Created February 24, 2025 18:03
Functional version of the nvidia build script to use in a Modal container. Call with kwargs.
# SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software