Code generation
Point Agent at an example to copy, build from a screenshot or mockup, and use tests as the target.
-
How Do You Get Cursor to Generate Code That Fits Your Repo? Name the file to change, @-mention one good existing example, list the exact fields or behavior, and say which hook or helper to reuse. Level 2: ContextVague"Add a user settings page"
- Agent guesses layout
- Picks its own components
- Invents a style
Constrainednames files and fields- Copies your layout
- Reuses your components
- Follows your API route
-
How Do You Turn a Design Into Code With Cursor? Paste a screenshot or mockup into the Agent input and ask it to build the component, then have it check the result in Cursor's built-in browser. Level 2: Context
- 1Paste the mockup
- 2Name components to reuse
- 3Check in the browser
- 4Fix with Design Mode notes
-
How Do You Use Test-Driven Development With Cursor's Agent? Have Agent write the tests first and confirm they fail, then commit them. Level 2: Context
- 1Write tests only
- 2Confirm they fail
- 3Commit the tests
- 4Code until they pass
- 5Review and commit
Decide what done looks like first
Generation goes wrong in two ways: the code doesn't fit your repo, or it doesn't do what you meant. A reference file solves the first, and a test or a design solves the second. Most real requests need one of each, such as a new endpoint copying an existing one plus tests that define its behavior.
Keep requests small enough to read
Agent can produce hundreds of lines quickly, but you still have to understand them. If a feature is large, use Plan mode to break it up, and build one step at a time. Cursor's course says it's often faster to iterate in smaller follow-up conversations once the first one is under way.
How do I get Cursor to match my code style?
@-mention an existing file as the model to follow, and write lasting conventions as project rules. A linter is still better for pure formatting, as Cursor's docs advise against pasting whole style guides into rules.
Can Cursor turn a screenshot into code?
Yes. Drag an image into the Agent input or paste it, and ask it to build the component using your existing parts. On vision-capable models it reads the image directly, and the built-in browser lets it check the result.
Should I write tests first with Cursor?
For logic with clear inputs and outputs, it works well. Have Agent write failing tests, commit them, then tell it to make them pass without modifying them, which gives it feedback on every run.