Context Engineering and Tool Design for Background Coding Agents at Scale
spotify · Media & Entertainment · 2025 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)
Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.
Problem
Domain: Large-scale software maintenance with autonomous coding agents
Spotify needed background coding agents to produce reliable, mergeable pull requests across real-world codebases and thousands of repositories. The challenge moved from merely running an agent loop to designing prompts and tools that kept the agent predictable, testable, and context-efficient at migration scale.
Constraints:
- The agent must operate across thousands of repositories with different build configurations.
- Prompts must be reusable enough for migrations but precise enough to avoid impossible tasks.
- Tool access must support verification without introducing too many unpredictable dimensions.
- Context windows can be overwhelmed by broad file selection or multi-change tasks.
- The team lacks fully structured evaluation for prompt/model quality, so operational safeguards matter.
Architecture
Spotify's architecture combines Fleet Management with Claude Code/Anthropic Agent SDK, migration prompts that specify end states, and a constrained tool surface: a verify MCP tool for formatters, linters, and tests; a standardized Git tool; and a strict Bash allowlist. Users or upstream workflow agents condense context into prompts before the coding agent runs.
Diagram confidence: explicit (topology described by the source).
flowchart LR fleet-management-system["Fleet Management system"] --> migration-prompt["Migration prompt"] migration-prompt --> claude-code-agent["Claude Code agent"] workflow-context-agents["Workflow context agents"] --> migration-prompt claude-code-agent --> verify-tool["Verify tool"] verify-tool --> build-and-test-systems["Build and test systems"] claude-code-agent --> git-tool["Git tool"] git-tool --> pull-request-pipeline["Pull request pipeline"] claude-code-agent --> bash-allowlist["Bash allowlist"]
Components
| Component | Role | Interacts with |
|---|---|---|
Fleet Management system |
Spotify system extended by background coding agents to run large-scale code migrations. | Claude Code agent, Migration prompt |
Migration prompt |
Static, version-controllable instruction bundle that defines preconditions, examples, desired end state, and tests. | Claude Code agent, Workflow context agents |
Claude Code agent |
Top-performing background coding agent that interprets goals, edits code, manages tasks, and uses constrained tools. | Migration prompt, Verify tool, Git tool, Bash allowlist, Pull request pipeline |
Verify tool |
MCP tool that runs formatters, linters, tests, and build-system checks while reducing noisy output. | Claude Code agent, Build and test systems |
Git tool |
Standardized Git interface with selective subcommand exposure and protected operations. | Claude Code agent, Pull request pipeline |
Bash allowlist |
Limited shell command surface for safe utility commands such as ripgrep. | Claude Code agent |
Build and test systems |
Repository-specific systems invoked through the verify tool to decide whether the migration is complete. | Verify tool |
Pull request pipeline |
Production path where successful background-agent changes are opened and merged. | Claude Code agent, Git tool, Fleet Management system |
Workflow context agents |
Separate agents or workflows that can produce condensed prompts and relevant context for the coding agent. | Migration prompt |
Data flow
A migration prompt plus scoped context enters the background coding agent. The agent edits code, runs verification through a dedicated tool that summarizes build/test output, uses constrained Git operations, and produces PRs when tests pass or retry/turn limits are reached.
Why this architecture
Spotify moved toward Claude Code plus constrained tools because the homegrown loop required rigid instructions, struggled with multi-step edits, and forced users to hand-pick context. Larger static prompts and a small tool surface made agent behavior easier to reason about and test at migration scale.
Models used: Claude Code · Anthropic Agent SDK · Goose · Aider
Scale
- Spotify applied the Claude Code approach to about 50 migrations.“As of today, Claude Code is our top-performing agent, which we’ve applied for about 50 migrations and the majority of the background agent PRs merged into production.”article, stated
- The system targets thousands of repositories.“writing good prompts — and verifying that the agent did the right thing — becomes significantly more difficult if you want to apply a change over thousands of repos.”article, stated
- The article credits the system with thousands of PRs across hundreds of repositories.“Spotify built a large scale system that used Claude Agent SDK to merge thousands of PRs across hundreds of repositories.”article, stated
- The earlier custom loop had explicit execution limits of 10 turns and three retries.“The task is complete once the tests are passed or limits are exceeded (10 turns per session, three session retries total).”article, stated
Alternatives considered (roads not taken)
Open-source agents such as Goose and Aider
Rejected because: They were impressive on simple exploration but did not reliably produce mergeable PRs at Spotify's migration scale.
Spotify's own rigid agentic loop
Rejected because: It worked for small changes but became unruly for multi-file changes, context selection, and longer operations.
Dynamic MCP tools for fetching more context during the task
Rejected because: More tools can handle ambiguity, but they make the agent less testable and introduce more dimensions of unpredictability.
Patterns
tool-use-orchestration (orchestration)
The coding agent is powerful but intentionally constrained to a verify MCP tool, standardized Git access, and a Bash allowlist rather than a broad tool ecosystem.
eval-driven-development (evaluation)
Prompts define desired end states through tests, and the verify tool runs formatters, linters, and tests so the agent can iterate against objective feedback.
prompt-versioning (prompt-operations)
Spotify favors larger static migration prompts because they can be version-controlled, tested, and evaluated like an artifact.
guardrails-io-filtering (governance)
Git operations are selectively exposed and standardized so the agent can commit safely without pushing or mutating origin unexpectedly.
Tradeoffs
Agent runtime
Chose Claude Code with Anthropic Agent SDK over open-source agents and a homegrown LLM loop.
Rationale: Claude Code handled high-level goals, tasks, and longer operations better than the previous alternatives for Spotify's production migration use case.
Prompt and context strategy
Chose larger static, version-controlled prompts over simpler prompts plus more dynamic MCP context tools.
Rationale: Static prompts were easier to reason about and test, while extra dynamic tools increased unpredictability.
Migration prompt scope
Chose one change at a time over combining several related changes into one elaborate prompt.
Rationale: Combining changes increases the chance of context exhaustion or partial delivery.
Gotchas (what bit them)
Context selection by users did not scale.
Root cause: The homegrown loop required users to choose exact files with git-grep, making broad searches overwhelm context and narrow searches starve the agent.
Resolution: Move to Claude Code's stronger task management and context handling, while condensing relevant context into prompts or workflow-agent outputs.
Multi-file edits exhausted simple agent loops.
Root cause: Cascading changes could run out of turns or lose the original task as the context window filled.
Resolution: Use an agent that can manage high-level goals, task lists, and subagents more dynamically.
Too many tools made the agent less predictable.
Root cause: Dynamic MCP context tools introduce capability but add extra dimensions of behavior that are hard to test.
Resolution: Constrain the tool surface and make prompts carry the relevant context up front.
Evaluation
Operational verification combines prompt-defined end states, test/formatter/linter execution through the verify tool, and production PR merge outcomes; the post admits structured prompt/model evaluation is still immature.
Metrics: tests passed · formatters and linters passed · PRs merged into production · about 50 migrations
Outcomes
- Claude Code became Spotify's top-performing background coding agent.
- Spotify applied it to about 50 migrations and merged most background-agent PRs into production.
- The architecture produced thousands of PRs across hundreds of repositories, according to the cited Anthropic comment.
The case is explicitly enterprise-scale: thousands of repositories, hundreds of repositories with merged PRs, and roughly 50 migrations.