Skip to main content

Overview

This playbook teaches you to resolve bugs systematically using an AI coding agent connected to CoreStory’s code intelligence via MCP. Instead of grep-wandering through a codebase, the agent queries CoreStory to understand how the system should work, generates hypotheses about what went wrong, writes a failing test to confirm the bug, and implements a minimal fix — all with architectural context that would normally require senior-engineer-level familiarity with the code. CoreStory serves two roles in this workflow:
  • Expert — answers questions about intended system behavior, invariants, business rules, and design history. This is context you can’t get from code search alone; it synthesizes PRDs, technical specs, user stories, and code history into coherent answers.
  • Navigator — points to specific files, methods, and code paths relevant to a bug. Instead of blind searching, the agent gets directed guidance on where to look.
When to use this: Any bug that benefits from architectural understanding — which is most of them. Especially valuable for unfamiliar codebases, cross-component issues, bugs in complex state management, and onboarding new team members who need to fix things in code they’ve never seen. When to skip this: Trivial typos, documentation-only changes, dependency bumps without behavior changes, or emergency hotfixes where speed matters more than comprehensiveness. (For hotfixes, consider running the full workflow as a retrospective.)

Prerequisites

Required:
  • A CoreStory account with at least one project that has completed ingestion
  • The CoreStory MCP server installed and configured in your AI agent
  • A code repository the agent can read and write to
Recommended:
  • A ticketing system MCP (GitHub Issues, Jira, Azure DevOps, or Linear) so the agent can fetch ticket details and post updates automatically
  • Agent-specific configuration files (skill files, custom instructions, project rules) — covered in the Agent Implementation Guides section below
Verify your setup: Ask your agent to “List my CoreStory projects.” If it returns your projects, the MCP connection is working.

How It Works

The Six-Phase Workflow

The workflow has six phases. The first three gather context; the last three act on it. Phase 1 — Bug Intake. The agent pulls the bug ticket (or accepts a description), selects the relevant CoreStory project, and creates a dedicated investigation conversation. This conversation persists as institutional knowledge. Phase 2 — Expert Phase. The agent queries CoreStory to understand how the system is supposed to work: which files implement the affected feature, what data structures and invariants are involved, and what design history exists. This happens before looking at code. Phase 3 — Navigator Phase. The agent asks CoreStory to map the bug’s symptoms to specific code paths, generate ranked root cause hypotheses, and identify exact files and methods to investigate. Phase 4 — Test-First Investigation. The agent writes a failing test that reproduces the bug before reading any implementation code. It validates the test with CoreStory, then reads the identified code to pinpoint the root cause. Phase 5 — Solution Development. The agent implements a minimal fix, verifies the test passes, validates the fix with CoreStory against architectural constraints, adds edge case tests, and runs the full test suite. Phase 6 — Completion. The agent updates the ticket, commits with a structured message explaining the root cause and fix rationale, renames the CoreStory conversation to mark it resolved, and reports results.

CoreStory MCP Tools Used

Ticketing MCP Integrations (Optional)

The agent can fetch ticket details and post updates automatically if you configure a ticketing MCP server. Each platform now offers an official MCP server — check their documentation for current setup instructions:

Step-by-Step Walkthrough

This section is agent-agnostic. The prompts work with any MCP-connected agent. Agent-specific configuration is in the Implementation Guides below.

Phase 1: Bug Intake & Context Gathering

Goal: Import bug details and prepare the investigation environment. Step 1 — Pull the bug ticket. If you have a ticket ID, ask the agent to fetch it:
If describing the bug directly, provide: symptoms, reproduction steps, expected vs. actual behavior, and the affected component. Step 2 — Select the CoreStory project. The agent lists available projects and picks the one matching your repository:
If there’s only one project, the agent auto-selects. It should verify ingestion status is “completed” before proceeding. Step 3 — Create an investigation conversation. This is the persistent thread where all CoreStory queries for this bug will live:
The agent stores the conversation_id and uses it for all subsequent queries. This conversation becomes searchable institutional knowledge — future engineers investigating similar bugs can reference it.

Phase 2: Understanding System Behavior (Expert Phase)

Goal: Establish ground truth about how the system should work before investigating what’s wrong. This phase is the key differentiator. Without it, you risk fixing symptoms instead of root causes, breaking adjacent functionality, or missing architectural constraints that explain why the code works the way it does. Query 1 — Architecture Discovery:
CoreStory responds with file names, test files, related modules, architectural patterns, and recent PRs. This is your map of the territory. Query 2 — Invariants & Data Structures:
The critical output here is invariants — conditions that must always be true (e.g., “coord_names ⊆ variables.keys()”). These become the assertions in your tests. Query 3 — Historical Context:
CoreStory synthesizes PRD context, PR history, user stories, and known edge cases — the kind of context that normally lives only in the heads of long-tenured engineers.

Phase 3: Hypothesis Generation (Navigator Phase)

Goal: Translate symptoms into specific, actionable investigation targets. Query 1 — Map symptoms to code paths:
Query 2 — Root cause candidates:
Query 3 — Precise navigation:
At this point the agent has a ranked list of hypotheses, specific files and methods to check, and a clear understanding of what “correct” looks like. This replaces hours of code archaeology.

Phase 4: Test-First Investigation

Goal: Write a failing test before reading implementation code. This is non-negotiable. Why test-first for bugs? A failing test proves the bug exists, a passing test proves it’s fixed, and the test prevents the bug from recurring. It also forces the agent to articulate what “correct behavior” means before getting lost in implementation details. Step 1 — Write a reproduction test. Based on the expected behavior (Phase 2) and symptoms (Phase 1):
Step 2 — Verify the test fails. Run it and confirm the failure matches the reported symptom. If the test passes, the bug doesn’t exist in this form — go back to Phase 2 for clarification. Step 3 — Validate the test with CoreStory:
Update the test if CoreStory identifies gaps. Step 4 — Now read the code. Only now does the agent read the implementation files identified in Phase 3. It knows what to look for: state update logic, invariant maintenance, the specific methods CoreStory pointed to. Step 5 — Identify the bug. Compare actual code against expected behavior. Look for missing state updates, incorrect logic, missing validations, or invariant violations. Step 6 — Validate the finding with CoreStory:
Wait for CoreStory’s confirmation before implementing the fix.

Phase 5: Solution Development

Goal: Implement a minimal fix, verify it, and add comprehensive test coverage. Step 1 — Implement the minimal fix. The smallest change that restores the invariant, following architectural patterns CoreStory described. Step 2 — Verify the test passes. Run the reproduction test from Phase 4. If it still fails, the fix is incomplete. Step 3 — Validate with CoreStory:
Step 4 — Add edge case tests. Ask CoreStory for scenarios:
Common edge cases: partial operations, empty inputs, boundary conditions, different parameter combinations, concurrent access. Step 5 — Run the full test suite. Ensure no regressions. If existing tests break, the fix has side effects — revise the approach.

Phase 6: Completion & Knowledge Capture

Goal: Close the loop and preserve knowledge. Step 1 — Update the ticket (if ticketing MCP is configured). Add investigation summary, root cause, fix description, and commit link. Step 2 — Commit with structured context:
Step 3 — Rename the CoreStory conversation to mark it resolved:
This preserved conversation becomes a searchable resource for similar future bugs.

Prompting Patterns Reference

These patterns work with any MCP-connected agent querying CoreStory.

Investigation Patterns

Architecture Discovery:
Invariant Understanding:
Logic Flow Tracing:
Root Cause Hypothesis:

Validation Patterns

Fix Validation:
Test Coverage Check:

Context Patterns

Historical Context:
Requirements Tracing:
Integration Impact:

Efficient Multi-Query Pattern

When you want comprehensive context in one shot:

Advanced Patterns

Security-Sensitive Bugs

When the bug involves authentication, authorization, data handling, or external input, add a security check to Phase 2:
Include security validation assertions in your tests.

Integration Impact Analysis

When the bug is in a shared component, check downstream effects in Phase 3:
Add integration tests for dependent components.

Performance Bugs

When investigating slowness, timeouts, or resource issues:
Add performance regression tests with timing assertions. When multiple tickets look related:
Consider a unified fix if appropriate. Create separate CoreStory conversations for each but cross-reference them.

Agent Implementation Guides

The skill file shown below is plain markdown. The workflow it encodes works in any agentic harness — only the install location differs. Common conventions:
Want a single install that works across the most harnesses? Append the content to AGENTS.md at your repository root. The AGENTS.md spec is read by Codex, Aider, Cursor, Factory, Jules, Gemini CLI, Windsurf, GitHub Copilot’s coding agent, JetBrains Junie, Warp, and others — so a single file covers most users without harness-specific setup.
If your harness isn’t listed, the SKILL.md content itself is portable — install it wherever your harness loads workflow context and adapt the activation step (auto-trigger, slash command, explicit invocation) to your harness’s conventions. The sections below walk through end-to-end setup (skill file, slash command, version control) for the four most common harnesses. If you’re on a different harness, copy the SKILL.md content from any section and install it per the conventions above.

Claude Code

Setup

  1. Configure the CoreStory MCP server in your Claude Code settings (see CoreStory MCP Server Setup Guide).
  2. Add the skill file. Claude Code uses skills (.claude/skills/ directory) as its preferred mechanism for teaching Claude specialized workflows. Create the skill:
Create .claude/skills/bug-resolver/SKILL.md with the content from the skill file below.
  1. (Optional) Add the slash command. Slash commands provide a shortcut to invoke the workflow:
Create .claude/commands/fix-bug.md with the content from the command file below.
  1. Commit to version control for team sharing:

Usage

The skill activates automatically when Claude Code detects bug-related requests:
Or invoke explicitly:

Tips

  • Skills auto-load from directories added via --add-dir, so team-shared skills work across machines.
  • Claude Code detects file changes during sessions — you can edit the skill file and it takes effect immediately.
  • Keep the SKILL.md under 500 lines for reliable loading.
  • The skill file includes structured output templates so Claude reports progress at each phase.

Skill File

Save as .claude/skills/bug-resolver/SKILL.md:

Slash Command

Save as .claude/commands/fix-bug.md:

GitHub Copilot

Setup

  1. Configure the CoreStory MCP server in your VS Code settings. Add it to your MCP server configuration (typically in VS Code settings JSON or the MCP configuration UI).
  2. Add custom instructions. Copilot reads project-level instructions from .github/copilot-instructions.md. This is the primary mechanism for teaching Copilot specialized workflows:
Create .github/copilot-instructions.md with the content from the custom instructions file below.
  1. (Optional) Add a reusable prompt file. Prompt files (.github/prompts/fix-bug.prompt.md) provide reusable task templates. See the prompt file below.
  2. Commit to version control:

Usage

In Copilot Chat (agent mode), natural language triggers the workflow:
Or reference the prompt file:

Tips

  • Copilot’s agent mode (available in VS Code) can execute terminal commands and edit files autonomously — this workflow works best in agent mode.
  • You can add path-specific instruction files (e.g., .github/instructions/backend.instructions.md with applyTo: "src/backend/**") for component-specific guidance.
  • On Team/Enterprise plans, organization-level instructions apply across all repositories.
  • Copilot automatically references .github/copilot-instructions.md in chat responses.

Custom Instructions

Save as .github/copilot-instructions.md:

Prompt File (Optional)

Save as .github/prompts/fix-bug.prompt.md:

Cursor

Setup

  1. Configure the CoreStory MCP server in Cursor’s MCP settings (Settings → MCP Servers, or edit the MCP config JSON directly).
  2. Add project rules. Cursor uses rules in .cursor/rules/ directories. Each rule folder contains a RULE.md file:
Create .cursor/rules/bug-resolver/RULE.md with the content from the rule file below.
  1. Commit to version control:

Usage

In Cursor’s Composer or Chat, the rule activates automatically for bug-related requests:

Tips

  • Rules with alwaysApply: true load in every session. Set this if your team regularly fixes bugs. Otherwise, use alwaysApply: false with a good description so Cursor loads it intelligently when relevant.
  • The legacy .cursorrules file still works but the .cursor/rules/ directory structure is the current recommended approach.
  • Rules apply to Composer and Chat but do not affect Cursor Tab or inline edits (Cmd/Ctrl+K).
  • On Team/Enterprise plans, team rules apply across all members.

Project Rule

Save as .cursor/rules/bug-resolver/RULE.md:

Factory.ai

Setup

  1. Configure the CoreStory MCP server in your Factory.ai environment. Verify with the /mcp command that CoreStory tools are accessible.
  2. Add the custom droid. Factory.ai uses droids stored in .factory/droids/ (project-level) or ~/.factory/droids/ (personal):
Create .factory/droids/bug-resolver.md with the content from the droid file below.
  1. Commit to version control (for project-level droids):

Usage

Invoke the droid via the Task tool:
Or describe the bug and Factory.ai routes to the droid based on its activation triggers.

Tips

  • Use model: inherit in the YAML frontmatter to use whatever model the session is configured with.
  • The tools field in frontmatter can explicitly list required MCP tools if you want to restrict the droid’s capabilities.
  • The Task tool that invokes droids requires experimental features to be enabled.
  • For complex bugs, the droid’s CoreStory queries may produce long streaming responses — this is expected.

Custom Droid

Save as .factory/droids/bug-resolver.md:

Tips & Best Practices

Ask specific questions. “Tell me everything about reset_index” gets a sprawling response. “What is the relationship between _coord_names and _variables during reset_index with drop=True?” gets a precise, useful answer. Paste code in your CoreStory queries. When validating a hypothesis or fix, include the actual code snippet. CoreStory gives much better answers when it can see what you’re looking at. Trust the test-first discipline. It’s tempting to skip straight to reading code, especially when you think you know where the bug is. The failing test is worth the five minutes — it catches false assumptions, documents the bug, and prevents regressions. Use the CoreStory conversation as a review artifact. Before your fix goes through code review, share the CoreStory conversation link. Reviewers can see the full investigation context: what invariants were identified, what hypotheses were considered, and why this fix was chosen. Name conversations descriptively. “Bug Investigation: #6992 - reset_index coord_names cleanup” is searchable and useful six months later. “Bug fix” is not. Don’t fight the phases. If you’re tempted to jump from Phase 1 to Phase 5, you’re optimizing for speed on this bug at the cost of quality. The Expert Phase in particular catches architectural constraints that would otherwise become failed code reviews or production regressions. Let the agent complete the workflow. Interrupting mid-workflow loses accumulated context. If you need to redirect, explain why rather than just changing the subject.

Troubleshooting

CoreStory returns generic answers. Your queries are too broad. Instead of “Tell me about the auth system,” try “What files handle JWT token validation? What invariants must the token payload satisfy?” Include specific variable names, method names, or code snippets. Project not found or ingestion incomplete. Run CoreStory:get_project_stats to check status. If ingestion is still running, wait for it to complete — queries against partially-ingested projects give incomplete answers. Verify the project name matches exactly. The reproduction test passes (bug not reproduced). Three possibilities: the bug was already fixed, the reproduction steps are wrong, or the test isn’t testing what you think it is. Ask CoreStory to verify your understanding of expected behavior. Check if the bug is environment-specific or version-specific. Fix causes regressions. Don’t commit. Run CoreStory:send_message asking about integration impacts: “What other components depend on [feature]? What downstream effects could my change to [behavior] have?” Revise the fix to be more targeted, or add compatibility handling for dependent components. CoreStory response is too long or gets cut off. Break your query into smaller, more specific questions. Instead of one query covering architecture + invariants + history, send them separately. Agent doesn’t follow the workflow. If you’re using the agent configuration files (skill/instructions/rules/droid) and the agent still doesn’t follow the six-phase workflow, check that the configuration file is in the correct location and format for your agent. See the Agent Implementation Guides above for exact paths.