.claude/skills/cloudflare-workers-subrequest-limit/SKILL.md
Fix "Too many subrequests" error in Cloudflare Workers. Use when: (1) Worker returns 500 with message "Too many subrequests", (2) Making multiple fetch calls in a loop (e.g., creating blobs for each file), (3) Processing batches of items that each require an API call. Covers the 50 subrequest limit and strategies to work around it.
npx skillsauth add Dbochman/dotfiles cloudflare-workers-subrequest-limitInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Cloudflare Workers have a limit of 50 subrequests (fetch calls) per invocation. When processing multiple items that each require an API call (e.g., creating GitHub blobs for multiple files), you'll hit this limit and get a 500 error.
For GitHub Trees API, use inline content instead of creating separate blobs:
// BEFORE: Creates N+1 subrequests (1 per file + 1 for tree)
const blobShas = await Promise.all(
files.map(file => createBlob(file.content, env)) // ❌ Each is a subrequest
);
// AFTER: Creates only 1 subrequest (tree with inline content)
const treeItems = files.map(file => ({
path: file.path,
mode: '100644',
type: 'blob',
content: file.content, // ✅ Inline content, no separate blob
}));
await createTree(baseTreeSha, treeItems, env); // Single subrequest
If you must make individual calls, batch them:
const BATCH_SIZE = 40; // Leave headroom below 50
async function processBatches(items: Item[], env: Env) {
const results = [];
for (let i = 0; i < items.length; i += BATCH_SIZE) {
const batch = items.slice(i, i + BATCH_SIZE);
const batchResults = await Promise.all(
batch.map(item => processItem(item, env))
);
results.push(...batchResults);
// If more batches remain, you need a new Worker invocation
// Consider using Durable Objects or queuing
}
return results;
}
For operations exceeding 50 subrequests, split across multiple Worker invocations or use Durable Objects which have their own subrequest budget per alarm/request.
Have the client send already-aggregated data to reduce server-side API calls.
Atomic multi-file GitHub commit with 60+ files:
// This approach works for any number of files
// because createTree accepts inline content
export async function commitFilesAtomic(
files: Array<{ path: string; content: string }>,
deletions: string[],
message: string,
parentSha: string,
env: Env
): Promise<string> {
const baseTreeSha = await getCommitTree(parentSha, env); // 1 subrequest
// Build tree items with INLINE content (no blob creation)
const treeItems = files.map(file => ({
path: file.path,
mode: '100644' as const,
type: 'blob' as const,
content: file.content, // Inline!
}));
// Add deletions
for (const path of deletions) {
treeItems.push({ path, mode: '100644', type: 'blob', sha: null });
}
const newTreeSha = await createTree(baseTreeSha, treeItems, env); // 1 subrequest
const newCommitSha = await createCommit(newTreeSha, parentSha, message, env); // 1 subrequest
await updateRef(newCommitSha, parentSha, env); // 2 subrequests (get + update)
return newCommitSha; // Total: 5 subrequests for ANY number of files
}
development
Search the web for current information, news, facts, and answers. Use when asked questions about current events, needing to look something up, finding websites, researching topics, or when you need up-to-date information beyond your training data.
development
Summarize any URL, YouTube video, podcast, PDF, or file into concise text. Use when asked to read an article, summarize a link, get the gist of a video or podcast, extract content from a URL, or when you need to understand what a web page or document contains.
development
Play music via Spotify and control Google Home speakers. Use when asked to play music, songs, artists, playlists, podcasts, or control speakers/volume/audio.
testing
Create new OpenClaw skills, modify and improve existing skills, and measure skill performance with evals. Use when users want to create a skill from scratch, update or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. Also use when asked to "make a skill", "turn this into a skill", "improve this skill", or "test this skill".