claude-code - 💡(How to fix) Fix Subagent-driven development produces code that doesn't integrate with existing codebase [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46797Fetched 2026-04-12 13:32:49
View on GitHub
Comments
2
Participants
3
Timeline
6
Reactions
0
Author
Timeline (top)
commented ×2cross-referenced ×2labeled ×2

Root Cause

The subagent prompt template says "follow existing patterns" but this is too vague. The agent doesn't know WHICH files to read, so it invents based on general knowledge. The controller (orchestrating agent) also doesn't verify the subagent's output against prior art before marking tasks complete.

Fix Action

Fix / Workaround

When using subagent-driven development (dispatching fresh agents per task from a plan), agents consistently invent new patterns instead of copying existing prior art, producing code that compiles but fails at integration boundaries.

Building a feature ("My school isn't here" — school request flow) across 4 services in a monorepo. Dispatched subagents for each task. Every subagent reported "DONE" with passing builds. The actual result was 8+ integration bugs:

RAW_BUFFERClick to expand / collapse

Problem

When using subagent-driven development (dispatching fresh agents per task from a plan), agents consistently invent new patterns instead of copying existing prior art, producing code that compiles but fails at integration boundaries.

What happened

Building a feature ("My school isn't here" — school request flow) across 4 services in a monorepo. Dispatched subagents for each task. Every subagent reported "DONE" with passing builds. The actual result was 8+ integration bugs:

  1. Admin routes mounted wrong — existing admin routes mount inside admin-routes.ts with roleCheckMiddleware. Subagent mounted separately in index.ts with authMiddleware (wrong middleware, wrong location). Result: 403 on every admin request.
  2. Admin page used wrong API pattern — every existing admin page uses apiClient.get("/api/admin/..."). Subagent used Refine's useCustom with wrong URL prefix. Result: empty page.
  3. Proxy route missing — existing mobile/campus endpoints have dedicated proxy route files. Subagent relied on catch-all proxy. Result: 404.
  4. Field name mismatches — form sent websiteUrl, API expected url. Form sent college_university, DB constraint expected college.
  5. Clerk ID vs account UUID — route assumed x-user-id is always a UUID. Clerk sends user_xxx format when backend_user_id isn't in session claims.
  6. React state race condition — called onNext() synchronously after onUpdate(), reading stale memoized formData.
  7. Missing middleware bypass cookie — middleware had an onboardingJustCompleted cookie bypass but the onboarding page never set it.

Each bug had a working example within 10 lines of where the subagent wrote code.

Root cause

The subagent prompt template says "follow existing patterns" but this is too vague. The agent doesn't know WHICH files to read, so it invents based on general knowledge. The controller (orchestrating agent) also doesn't verify the subagent's output against prior art before marking tasks complete.

Suggested improvements

  1. Subagent prompts should require specific prior art files — not "follow existing patterns" but "read admin-routes.ts:70-80 and copy the mounting pattern exactly"
  2. The spec/code review steps should not be optional — they're the only gate that catches integration issues before the user hits them
  3. Subagents should report which existing file they copied from — forces them to actually read prior art
  4. The orchestrator should verify integration points — when code crosses service boundaries (frontend → proxy → API → DB), trace the full path before marking done

Environment

  • Claude Code CLI
  • Claude Opus 4.6 (1M context)
  • superpowers plugin v5.0.7, subagent-driven-development skill
  • Monorepo with 4+ services (Next.js, Express, shared library, React admin)

Impact

What should have been a 2-hour feature took 5+ hours of debugging integration bugs that were all caused by not reading existing code. The user (founder, shipping under time pressure) was rightfully furious.

extent analysis

TL;DR

  • Update subagent prompts to require specific prior art files and implement verification steps to ensure subagents copy existing patterns correctly.

Guidance

  • Modify subagent prompt templates to include specific file references, such as "read admin-routes.ts:70-80 and copy the mounting pattern exactly", to guide the subagent's code generation.
  • Make spec/code review steps mandatory to catch integration issues before they reach the user.
  • Implement a reporting mechanism for subagents to specify which existing file they copied from, ensuring they actually read prior art.
  • Enhance the orchestrator to verify integration points, tracing the full path of code across service boundaries before marking tasks as complete.

Example

// Example of updated subagent prompt template
const prompt = {
  type: 'code-generation',
  prompt: 'Read admin-routes.ts:70-80 and copy the mounting pattern exactly',
  filesToRead: ['admin-routes.ts'],
  outputFile: 'new-admin-route.ts'
};

Notes

  • The effectiveness of these changes relies on the subagent's ability to understand and follow the updated prompts.
  • Additional testing and validation may be necessary to ensure the subagent is correctly implementing the desired patterns.

Recommendation

  • Apply workaround: Update subagent prompts and implement verification steps to improve the accuracy of subagent-generated code, as the current approach is causing significant integration issues and delays.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING