Skip to content

Agent and Chat Optimization: Tips 61-75

You open the agent panel, type “add user authentication,” and watch Cursor create a half-baked auth module that ignores your existing middleware, uses a different ORM than your project, and breaks three test files. You spend more time fixing the mess than it would have taken to write it yourself. The problem is not agent mode — it is that agent mode is a power tool, and power tools without technique cause damage. These 15 tips teach you the technique.

  • The test-driven agent workflow that produces code you can actually trust
  • Context management strategies that stop the agent from going off-track mid-conversation
  • Prompt patterns for the most common agent tasks (features, refactors, debugging, migrations)
  • Clear rules for when to babysit the agent versus when to let it run unsupervised

Tip 61: Always Write Tests First with Agent Mode

Section titled “Tip 61: Always Write Tests First with Agent Mode”

The single most impactful change you can make to your agent workflow: tell it to write tests before implementation. This gives the agent a clear definition of “done” that it can verify autonomously.

With Auto-Run enabled (formerly called YOLO mode — see Tip 5), the agent:

  1. Creates the test file with well-defined assertions
  2. Creates the implementation file
  3. Runs vitest
  4. Sees failures, fixes the code
  5. Runs vitest again
  6. Repeats until all tests pass

You did not approve a single command. You did not review intermediate output. And the final code has test coverage by definition.

Tip 62: Use @ References to Ground Every Conversation

Section titled “Tip 62: Use @ References to Ground Every Conversation”

The @ symbol is not optional — it is the difference between the agent guessing at your code structure and knowing it. Always include relevant context:

@src/lib/db/schema.ts @src/lib/db/queries.ts
Add a new "organizations" table with name, slug, and owner_id fields.
Create the Drizzle schema, migration, and CRUD query functions following
the same pattern as the existing user queries in the referenced files.

Without the @ references, the agent might generate raw SQL instead of Drizzle, use a different naming convention, or create files in the wrong directory. With them, it pattern-matches against your existing code and produces consistent output.

Tip 63: Start New Conversations for New Tasks

Section titled “Tip 63: Start New Conversations for New Tasks”

Agent conversations have a limited context window, and long conversations degrade quality. Here are the signs you need a new conversation:

  • The agent starts “forgetting” instructions you gave earlier
  • It repeats mistakes you already corrected
  • It references files that are no longer relevant
  • Its responses are getting slower

Start a new conversation with Cmd+N (or Cmd+R) in the chat. Carry over only the essential context: the files you need, the specific task, and any constraints. Do not try to resume a stale conversation by pasting a summary — it is faster and more reliable to start fresh.

Tip 64: Use Plan Mode to Plan, Agent Mode to Execute

Section titled “Tip 64: Use Plan Mode to Plan, Agent Mode to Execute”

The plan-then-execute workflow produces dramatically better results than a single agent conversation. Cursor ships a dedicated Plan mode for exactly this: it researches your codebase, asks clarifying questions, and produces a reviewable, editable plan before it writes any code. Reach it by pressing Shift+Tab from the chat input to rotate through modes, or pick it from the mode dropdown.

  1. Switch to Plan mode (Shift+Tab): “I need to add Stripe subscription billing. Research @src/api/ and @src/lib/, then produce a plan: the files that need to change, the new files to create, and the order of operations.”
  2. Review and edit the plan: Plan mode generates a structured plan as an editable markdown document and asks clarifying questions. Tighten scope, correct wrong assumptions, and answer its questions before it builds.
  3. Click to build: When the plan looks right, Cursor executes it directly — no copy-paste hand-off required. If the result drifts, revert and refine the plan rather than fighting the in-progress agent.

This keeps the agent from taking on too much at once: the plan is reviewed up front, and the build stays scoped to what you approved.

If you want finer manual control, the older two-step pattern still works: ask in Ask mode (read-only) for a plan, then paste each step into a fresh Agent conversation. Plan mode automates that loop, but Ask mode is handy when you only want to discuss an approach without Cursor offering to build it.

Every file you reference with @ consumes context tokens. Reference too many files and the agent’s reasoning quality drops because it cannot hold everything in working memory. The rules:

  • 1-3 files: Agent can reason about every line in detail
  • 4-8 files: Agent understands overall structure but may miss specifics
  • 8+ files: Agent skims and may hallucinate connections between files

For tasks that require many files, break them into sub-tasks that each reference only the relevant subset:

# Instead of:
@src/api/ @src/lib/ @src/components/ @src/types/ "Refactor auth"
# Do:
# Conversation 1: @src/lib/auth.ts @src/types/user.ts "Refactor the auth service"
# Conversation 2: @src/api/auth/ @src/lib/auth.ts "Update API routes for new auth service"
# Conversation 3: @src/components/AuthProvider.tsx @src/lib/auth.ts "Update the frontend auth provider"

Tip 66: Ask the Agent to Search the Web for Current Docs

Section titled “Tip 66: Ask the Agent to Search the Web for Current Docs”

When working with a library that has been updated since the model’s training data, just ask the agent to check the current docs — it self-gathers web context from a plain-language request. (Older Cursor versions exposed an explicit @Web mention, but Cursor 2.0 removed it from the context menu in favor of the agent searching on its own.)

This is especially valuable for rapidly evolving libraries (Next.js App Router, Drizzle, tRPC) where the model’s built-in knowledge may be a version or two behind.

Have the agent diff your branch itself, then review what changed. Cursor 2.0 removed the explicit @Git mention; you now ask the agent directly to look at your branch (it runs git on its own), which is more flexible — you can scope it to specific commits or files in the same sentence.

Review the changes on my current branch versus main. Check for:
1. Missing error handling in new code
2. Type safety issues
3. Consistency with existing patterns
4. Missing test coverage for new functionality

This is a fast pre-PR review that catches issues before your teammates see the code.

Tip 68: Use the “Implement and Verify” Pattern

Section titled “Tip 68: Use the “Implement and Verify” Pattern”

For any non-trivial feature, structure your prompt to include a verification step:

The “after implementation” section gives the agent a clear verification checklist. With Auto-Run enabled, it runs these checks automatically.

Tip 69: Reach for Debug Mode on Hard-to-Reproduce Bugs

Section titled “Tip 69: Reach for Debug Mode on Hard-to-Reproduce Bugs”

When a bug resists static analysis — a regression, a race condition, an intermittent failure — use Cursor’s Debug mode instead of guessing. Debug mode generates hypotheses, auto-instruments the relevant code with log statements that stream to a local debug server, asks you to reproduce the bug, then reads the captured runtime data, makes a targeted fix, and removes its own instrumentation afterward. Switch to it with Shift+Tab (it sits alongside Plan in the mode rotation).

If Debug mode is unavailable (older Cursor, or you want full manual control), fall back to the classic instrument-and-paste loop:

  1. Tell the agent: “Add console.log statements at every decision point in @src/services/payment.ts to trace the execution flow. Log function entry/exit, parameter values, and intermediate results.”
  2. Run the failing scenario and copy the log output.
  3. Paste the logs back: “Here is the log output. Analyze the trace and identify where the behavior diverges from expected.” The agent now combines runtime data with static analysis and proposes a targeted fix, then remember to remove the temporary logs.

Either path is dramatically more effective than telling the agent “fix the bug” with no runtime context.

Tip 70: Use the “Incremental Migration” Pattern

Section titled “Tip 70: Use the “Incremental Migration” Pattern”

For large migrations (library upgrades, pattern changes, framework migrations), do not ask the agent to migrate everything at once. Use incremental migration:

After the first file is verified, move to the next: “Now convert @src/api/users.ts following the same pattern established in the health endpoint.” Each step builds on the last, and you verify before proceeding.

End your development sessions by having the agent clean up everything in one pass:

Tip 72: Let the Agent Generate from Error Logs

Section titled “Tip 72: Let the Agent Generate from Error Logs”

Instead of describing a production issue, paste the actual error:

Here is the error from our production logs:
TypeError: Cannot read properties of undefined (reading 'email')
at processWebhook (src/api/webhooks/stripe.ts:47:28)
at handleRequest (src/middleware/router.ts:112:5)
The webhook payload from Stripe sometimes does not include customer details
when it is a subscription update event. Fix the handler in
@src/api/webhooks/stripe.ts to handle missing customer data gracefully.

Real stack traces give the agent exact file paths, line numbers, and error types — far more useful than a description.

Tip 73: Combine Agent Mode with Background Agents

Section titled “Tip 73: Combine Agent Mode with Background Agents”

For long-running tasks, start a background agent and continue working in a regular agent conversation:

  • Background agent: “Generate comprehensive tests for every service in @src/services/. Aim for 90% coverage.”
  • Foreground agent: Continue implementing the feature you are currently working on

The background agent creates a PR when it is done. Review the PR, merge the tests, and your test coverage is improved without blocking your active work.

Save frequently used prompts as .md files in your project and reference them with @:

.cursor/prompts/new-endpoint.md
Create a new API endpoint following these conventions:
- Use the route pattern from @src/api/users/route.ts
- Include zod validation for request body
- Add proper error handling with our AppError class
- Return standardized JSON responses
- Add vitest tests in the adjacent __tests__ directory
- Run tests after implementation

Then in the agent: “@.cursor/prompts/new-endpoint.md — create a POST /api/organizations endpoint that creates a new organization with name and slug fields.”

The agent is not always right, and sometimes it goes down a dead-end path. Signs you should stop, restore a checkpoint, and restart:

  • The agent has made the same mistake three times in a row
  • The agent is generating code that contradicts your instructions
  • The conversation has exceeded 15-20 exchanges without converging on a solution
  • The agent is editing files you explicitly told it not to touch

When you restart, add the failure context to your new prompt: “Previous attempt failed because the agent tried to use raw SQL instead of Drizzle ORM. Ensure all database operations use the Drizzle query builder from @src/lib/db/queries.ts.”

Agent modifies files you did not intend: This usually happens when your prompt is ambiguous about scope. Be explicit: “Only modify files in @src/api/users/. Do not touch any other directories.” If it already happened, use checkpoints to restore.

Agent goes into an infinite fix loop: The agent runs tests, sees a failure, “fixes” it, introduces a new failure, “fixes” that, and loops indefinitely. Stop the agent, review what went wrong, and restart with a more constrained prompt. Often the issue is that the agent is fighting its own previous changes.

Agent produces working code that does not match your conventions: This happens when project rules are missing or incomplete. Invest time in your .cursorrules or .cursor/rules/ (Tips 9-11). The 30 minutes you spend on rules saves hours of rework.

Context overflow in long conversations: If the agent’s responses become increasingly generic or start ignoring your instructions, the context window is saturated. Start a new conversation. There is no way to “trim” context in an existing conversation.

Agent mode handles individual features and focused tasks well. But what happens when your project has 500,000 lines of code and the agent needs to understand architectural boundaries, dependency chains, and module boundaries? Move to Large Codebase Strategies (Tips 76-90) for enterprise-scale techniques.