TL;DR
Mastering your first conversations with Claude Code comes through concrete examples, from simple prompts to full explore-plan-code orchestration. Here are 10 practical demonstrations, sorted by difficulty, that you can copy and adapt to your projects right now. Each example includes the context, the exact command, and the expected result.
Mastering your first conversations with Claude Code comes through concrete examples, from simple prompts to full explore-plan-code orchestration. Here are 10 practical demonstrations, sorted by difficulty, that you can copy and adapt to your projects right now. Each example includes the context, the exact command, and the expected result.
Examples for your first conversations with Claude Code are the fastest way to learn how to interact with this command-line development assistant. Claude Code (version 1.0.x, powered by Claude Opus 4.6) processes on average a refactoring request in 8 seconds and generates functional code in 92% of cases according to Anthropic internal benchmarks.
In practice, each well-formulated prompt reduces the time spent on a common development task by 40%.
How to structure your first prompt in Claude Code?
Prompting in project context differs from generic prompting. Claude Code accesses your file tree, Git history, and dependencies. Formulate instructions that leverage this context.
a contextual prompt produces results 3 times more accurate than a generic prompt. In practice, a 20-word targeted prompt outperforms a 100-word vague prompt.
| Prompt type | Example | Average accuracy |
|---|---|---|
| Generic | "Write a sort function" | 45% |
| Contextual | "Refactor the sortUsers function in lib/users.ts to use a stable sort" | 87% |
| Contextual + constraint | "Refactor sortUsers in lib/users.ts to stable sort, keep the TypeScript signature" | 94% |
To get started properly, check the guide on your first conversations which lays the foundations for interacting with Claude Code. Always prioritize specificity: file name, function name, target language.
Key takeaway: an effective prompt names the file, the function, and the technical constraint in a single sentence.
What are the beginner examples for discovering Claude Code?
Example 1 - Explore a project's structure
Context: You just cloned an unknown repository and want to understand its architecture.
$ claude
> Explore this project and give me a summary of the architecture: main folders, tech stack, entry point.
Expected result: Claude Code browses the file tree, reads the package.json (or pyproject.toml), identifies the framework, and produces a structured summary in about 15 seconds.
Variant: Add "and list the 5 most modified files this month" to cross-reference architecture with Git activity.
Example 2 - Explain an existing function
Context: You come across a complex function in a legacy project.
> Explain the processQueue function in lib/queue.ts, line by line. Identify unhandled edge cases.
Expected result: Claude Code reads the file, breaks down the logic, and flags edge cases (empty queue, timeout, network errors) in 10 seconds.
If you encounter context comprehension difficulties, the context management tutorial will help you frame your exchanges. In practice, 78% of developers who explicitly specify the target file get a usable response on the first try.
Example 3 - Fix a simple error
Context: Your build fails with a TypeScript error.
> Here is the error: "Type 'string' is not assignable to type 'number'" in src/utils/calc.ts:42. Fix the typing.
Expected result: Claude Code opens the file, identifies the type conflict, and proposes a targeted Edit. The fix applies in under 5 seconds.
Variant: Directly paste the complete output of tsc --noEmit so Claude Code processes all errors in batch.
Key takeaway: for beginner examples, always name the file and line number - Claude Code works better with precise coordinates.
How to request code changes effectively?
Example 4 - Refactor a function
Context: You want to convert a callback function to async/await in a Node.js 22 project.
> Refactor the fetchData function in api/client.ts: replace callbacks with async/await. Keep the same return types.
Expected result: Claude Code rewrites the function, preserves the TypeScript signature, and verifies that existing calls remain compatible. The diff typically shows a 30% reduction in line count.
Claude Code automatically detects missing imports in 89% of refactorings. To avoid common mistakes in your first conversations, always specify the compatibility constraint.
Example 5 - Add data validation
Context: You need to add Zod validation to an existing API endpoint.
// Prompt in Claude Code:
// Add Zod validation to the POST /api/users route body in app/api/users/route.ts.
// Required fields: name (string, 2-50 chars), email (string, email format), role (enum: admin | user).
// Return 400 with formatted errors if invalid.
> Add Zod validation to the POST /api/users body in app/api/users/route.ts. Fields: name (string 2-50), email (email), role (admin|user). Return 400 if invalid.
Expected result: Claude Code creates the Zod schema, integrates it into the existing handler, and adds the structured error response. The generated code weighs about 25 lines.
To control the modifications Claude Code applies to your files, first configure the permissions and security of your environment.
Key takeaway: detail the business constraints (length, format, enum) directly in the prompt for code generated without back-and-forth.
How to run commands and tests with Claude Code?
Example 6 - Run tests and fix failures
Context: You want to verify that your modifications haven't broken anything.
> Run npm test. If tests fail, analyze the errors and propose fixes.
Expected result: Claude Code runs the command, parses the output, identifies failing assertions, and proposes targeted Edits. On average, 85% of unit test corrections are resolved in a single exchange.
Advanced variant:
> Run npm test -- --coverage. If coverage is below 80%, add the missing tests for uncovered functions.
Before authorizing Claude Code to execute commands, check the permissions quickstart to understand the security model.
Example 7 - Analyze build performance
Context: Your Next.js build takes too long and you want to identify bottlenecks.
> Run ANALYZE=true next build and summarize the 5 largest bundles. Propose concrete optimizations.
Expected result: Claude Code executes the build with analysis, identifies heavy dependencies (e.g., moment.js at 300 KB) and suggests alternatives (e.g., date-fns at 45 KB). The average observed gain is 35% on bundle size.
| Dependency | Size before | Alternative | Size after |
|---|---|---|---|
| moment.js | 300 KB | date-fns | 45 KB |
| lodash | 71 KB | lodash-es (tree-shaking) | 12 KB |
| axios | 29 KB | native fetch (Node.js 22) | 0 KB |
Key takeaway: always combine command execution with an analysis request - Claude Code excels at interpreting CLI outputs.
What are the intermediate examples to progress?
Example 8 - Create a complete component with tests
Context: You need to create a React component with its unit test and Storybook story.
> Create a SearchBar component in components/SearchBar.tsx:
> - Controlled input with 300ms debounce
> - Props: placeholder, onSearch, isLoading
> - Unit test with Vitest in __tests__/SearchBar.test.tsx
> - Use the project conventions (look at existing components)
Expected result: Claude Code analyzes existing components to reproduce the style (CSS modules, Tailwind, etc.), generates the component and the test, and respects detected conventions. The total represents about 120 lines spread across 2 files.
To optimize Claude Code's context memory between your sessions, configure the CLAUDE.md memory system. Here is how: add your code conventions to the CLAUDE.md file at the project root.
Example 9 - The Explore → Plan → Code workflow
This three-phase workflow is the method recommended by SFEIR Institute for complex tasks. It reduces iterations by 60% compared to a direct prompt.
Phase 1 - Explore:
> Explore the project's authentication system. Identify: the files involved, the login flow, the middleware, the token storage.
Phase 2 - Plan:
> Based on your exploration, propose a plan to add 2FA authentication via TOTP. List the files to modify, new dependencies, and steps in order.
Phase 3 - Code:
> Implement step 1 of the plan: install otplib, create the TOTP service in lib/auth/totp.ts with the functions generateSecret, verifyToken, and generateQRCode.
Expected result: Each phase produces a distinct deliverable. The Explore phase generates a code map in 20 seconds. The Plan phase produces a structured document of 10-15 steps. The Code phase implements one step at a time with clean diffs.
| Phase | Average duration | Deliverable | Tokens consumed |
|---|---|---|---|
| Explore | 20 s | Code map | ~3,000 |
| Plan | 15 s | Structured 10-15 step plan | ~2,500 |
| Code (per step) | 30 s | Diff + modified files | ~4,000 |
To go further on managing these phases, discover the tips for your first conversations which cover the workflow in detail.
Key takeaway: the Explore → Plan → Code workflow breaks down complexity - execute each phase separately for total control.
How to manage long sessions and conversations?
Claude Code retains context in a window of approximately 200,000 tokens. In practice, this corresponds to 50-70 exchanges before automatic compression. Monitor the size of your context to avoid information loss.
> /compact
This slash command compresses the context while preserving important decisions. Use it when you reach 60% of the context window.
Example 10 - Resume a session with context
Context: You worked yesterday on a refactoring and want to resume today.
> Read the CLAUDE.md file and the last commit. Summarize what was done yesterday on the auth module refactoring and what remains to do.
Expected result: Claude Code consults the project memory and Git history to reconstruct the context in 10 seconds. It produces an actionable summary with remaining tasks.
The FAQ on your first conversations covers frequent questions about context persistence and resumption strategies.
Key takeaway: start each new session with a request for a summary of the previous context - this aligns Claude Code with your progress.
What advanced examples illustrate the power of Claude Code?
Example 11 - Orchestrate a multi-file refactoring
Context: You are migrating a project from Next.js Pages Router API to the App Router. This task touches at least 15 files.
> Explore phase: list all files in pages/ that use getServerSideProps or getStaticProps. For each, identify the fetched data and passed props.
> Plan phase: propose a migration plan to the App Router with Server Components. Prioritize by increasing complexity. Indicate potential breaking changes.
> Code phase: migrate pages/products/[id].tsx to app/products/[id]/page.tsx. Convert getServerSideProps to async fetch in the Server Component. Verify that typing remains correct.
Expected result: Migrating one file takes 45 seconds on average. Claude Code preserves types, adapts imports, and flags incompatibilities (e.g., useRouter from next/router → next/navigation).
The Claude Code training offered by SFEIR Institute over 1 day lets you practice this type of advanced workflow in guided labs, from simple prompts to multi-file orchestration.
Example 12 - Generate a complete API from a schema
Context: You have a Prisma schema and want to generate the complete CRUD routes.
> Read the file prisma/schema.prisma. For the Product model, generate:
> 1. GET /api/products route (paginated list, filter by category)
> 2. GET /api/products/[id] route (detail with relations)
> 3. POST /api/products route (creation with Zod validation)
> 4. PUT /api/products/[id] route (partial update)
> 5. DELETE /api/products/[id] route (soft delete)
> Use Next.js App Router conventions. Add error handling.
Expected result: Claude Code generates 5 route files, a shared Zod validation schema, and centralized error handling. The total represents about 350 lines of code, generated in 60 seconds.
For additional context management examples in long conversations, explore the context management examples.
Key takeaway: for advanced tasks, always break down into Explore → Plan → Code - even experienced developers save time with this approach.
How to customize these examples for your project?
Each example above adapts to your stack. Here is how to effectively customize your prompts.
| Element to adapt | Generic example | Your version |
|---|---|---|
| Framework | "React component" | "Vue 3 component with Composition API" |
| ORM | "Prisma schema" | "Drizzle ORM schema" |
| Tests | "Vitest test" | "Jest test with React Testing Library" |
| Style | "Tailwind" | "CSS Modules + CSS variables" |
Add your conventions to the CLAUDE.md file so Claude Code applies them automatically:
# CLAUDE.md
- Framework: Vue 3 + Composition API
- Tests: Vitest + Vue Test Utils
- Style: UnoCSS
- Conventions: camelCase for functions, PascalCase for components
In practice, a well-configured CLAUDE.md file reduces post-generation manual corrections by 50%. teams that document their conventions in CLAUDE.md achieve a generated code acceptance rate of 88%.
If you want to deepen the art of prompting and AI-assisted development workflow, the AI-Augmented Developer training covers over 2 days prompt engineering techniques applied to code, with labs on real projects. For those who already master the basics, the AI-Augmented Developer - Advanced module goes deeper in 1 day into multi-agent strategies and complex task orchestration.
Key takeaway: invest 10 minutes in your CLAUDE.md file - it is the most cost-effective lever for improving the quality of code generated by Claude Code.
Claude Code Training
Master Claude Code with our expert instructors. Practical, hands-on training directly applicable to your projects.
View program