Deep Agents/Agentic Coding
Intermediate13 min

Prompt Engineering for Code Generation

Agentic tools handle most repetitive coding automatically via context files — manual prompting skill pays off for novel patterns, ambiguous requirements, and custom agent system prompts. This article covers when to invest, which techniques consistently move the needle, how to measure whether your prompts actually work, and the failure modes that waste the most engineer time.

Quick Reference

  • Agentic tools handle repetitive patterns automatically — manual prompting pays off for novel code, ambiguous refactors, and custom agent system prompts
  • Negative constraints outperform positive descriptions: 'DO NOT use raw SQL' eliminates model defaults faster than 'use parameterized queries'
  • Include the exact function signature in every generation prompt — vague descriptions produce wrong interfaces
  • Request tests alongside implementation: the model must reason through edge cases to write them, which improves the implementation quality
  • Edit prompts need: exact file path, exact function name, numbered changes, and a 'do NOT change' list
  • Multi-turn refinement: steer before you restart — explain exactly what failed and how to fix it rather than starting fresh
  • Measure prompt quality with automated gates: test pass rate, type-check, lint clean — track per-prompt, not per-session
  • System prompts for custom coding agents need: preferred tools, error handling style, and explicit stop conditions

When Prompt Engineering Matters (and When the Tool Handles It)

In 2026, most code generation is handled by agentic tools — Claude Code, Cursor, GitHub Copilot — that assemble context automatically from your codebase, CLAUDE.md / AGENTS.md files, and tool definitions. For the majority of tasks, you do not need to engineer prompts: you need to configure context files well. The prompt engineering skill that remains genuinely valuable is for the cases those tools cannot handle out of the box.

When does manual prompting pay off?Zero EffortOne-off tasksor exploration→ Prompt it directlyno setup needed~0 minLow EffortPatterns repeatingwithin a project→ Write CLAUDE.mdor AGENTS.md once~30 min setupHigh EffortCustom agents ornovel patterns→ Design systemprompt + eval loop2-4 hrs

Most sessions only need context files — reserve system prompt design for custom agents

  • Novel patterns: the first time you introduce a new abstraction or architectural pattern that your context files don't cover yet
  • Ambiguous multi-file refactors: changes where the scope isn't obvious from the codebase structure alone
  • Custom agent system prompts: when you're building or configuring a coding agent, the system prompt you write shapes all its downstream behavior
  • A/B testing prompt strategies: when you want to measure which framing produces higher first-attempt pass rates
  • Breaking deadlocks in multi-turn sessions: when an agent has gotten stuck in a wrong direction and needs precise steering
Set up context files first

Before crafting individual prompts, write CLAUDE.md or AGENTS.md with your build commands, coding conventions, and common patterns. Context files solve the repetition problem once. Individual prompt engineering solves edge cases. See the context engineering article for how to structure them.