Navigating the Claude Code REPL: Prompts and Slash Commands
Once Claude Code is running, everything happens inside a single interactive REPL session.
That session has two kinds of input: natural-language requests, and built-in slash commands.
Knowing the difference, and knowing how to end a session properly, is the last piece of basic REPL fluency before you start relying on it for real work.
Summary
The REPL prompt is where you type a request in plain English and Claude Code turns it into a plan of action.
A leading slash marks a different kind of input: a built-in command that triggers specific REPL behavior rather than a task for the agent to plan.
Slash commands cover things like building initial project context, clearing the conversation, or compacting a long session's history.
The session persists across many requests, so you rarely need to relaunch claude in the middle of a work session.
Exiting cleanly matters because it signals you are done, rather than leaving the session hanging in a half-finished state.
Recipe
Quick-reference recipe card - copy-paste ready.
# A natural-language request - plain English, no special syntax
> Add input validation to the signup form
# A slash command - built-in REPL behavior, not a task for the agent
> /init
# Clear the current conversation context
> /clear
# Exit the session cleanly
> /exitWhen to reach for this:
- Any time you are inside an active Claude Code session and need to give it a new task.
- Starting a new project session, where
/inithelps it build context up front. - A session has grown long and slow, where
/compactor/clearcan help. - Wrapping up work for the day, where
/exitcloses things out properly.
Working Example
cd ~/projects/my-app
claude
# Build initial context about the project
> /init
# A normal natural-language request
> Explain how authentication currently works in this codebase
# A follow-up request in the same session, building on the same context
> Now add rate limiting to the login endpoint
# Free up context if the session is getting long
> /compact
# End the session when you're done
> /exitWhat this demonstrates:
/initand ordinary requests can be mixed freely in the same session.- Follow-up requests build on the context Claude Code already gathered earlier in the session.
/compactis available mid-session without needing to exit and relaunch./exitis the deliberate, clean way to end the session rather than closing the terminal window.
Deep Dive
How It Works
- Every line you type at the
>prompt is either routed to the agent as a task, or intercepted by the REPL as a slash command if it starts with/. - Natural-language requests accumulate as part of the session's working context, which is why follow-up requests can refer back to earlier ones.
- Slash commands act on the session itself: building context, clearing it, compacting it, or ending it, rather than acting on your project files directly.
- Because the session is stateful, you generally don't need to repeat context you already gave it earlier in the same session.
Common Slash Commands
| Command | What it does |
|---|---|
/init | Has Claude Code build up initial context about the current project |
/clear | Clears the current conversation context, starting fresh within the same session |
/compact | Compacts a long session's history to free up context while keeping the gist |
/exit | Ends the session cleanly |
Prompt Syntax Notes
# Natural language: describe the outcome, not the exact steps
> Fix the failing test in checkout.test.ts
# Slash command: always starts with a leading slash, no natural-language mixed in
> /clearGotchas
- Typing a slash command as part of a sentence - starting a natural-language request with a word that happens to begin with
/can be misread as a command attempt. Fix: keep slash commands as the very first character of the line, with nothing else on that line. - Assuming
/clearand/exitdo the same thing -/clearresets context but keeps the session open;/exitends the session entirely. Fix: use/clearto start fresh mid-session, and/exitonly when you are actually done. - Closing the terminal window instead of exiting - this skips the clean shutdown the REPL performs on
/exit. Fix: type/exitbefore closing the terminal, especially if any background command was still running. - Not using
/initon a new project - skipping it means the first real request has to build context from scratch, which can slow down or weaken the first plan. Fix: run/initas your first action in a brand-new project session. - Letting a session run too long without compacting - a very long conversation history can slow down responses or dilute context. Fix: run
/compactperiodically in long sessions, or/clearwhen switching to an unrelated task.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| Natural-language request | You want the agent to plan and act on a task | You want to control a REPL-level behavior like clearing context |
| Slash command | You want built-in REPL behavior (init, clear, compact, exit) | You want Claude Code to plan a multi-step task |
Exiting and relaunching claude | You switched to a completely different project | You are just switching tasks within the same project |
FAQs
How do I know whether to type a natural-language request or a slash command?
If you want Claude Code to plan and act on a task, describe it in plain English. If you want a built-in REPL behavior like clearing context or exiting, use a leading slash command instead.
What does `/init` actually do?
- It has Claude Code build up initial context about the current project.
- It is typically the first command run in a brand-new project session.
- It makes the first real request afterward more accurate, since the agent already has orientation.
What's the difference between `/clear` and `/compact`?
/clear wipes the current conversation context and starts fresh within the same session. /compact condenses a long history down to keep it manageable without fully discarding it.
Do I need to `/exit` and relaunch for every new task?
No. The session is stateful and persists across many requests. You only need to relaunch when switching to a different project directory.
What happens if I just close the terminal without exiting?
The session ends abruptly rather than shutting down cleanly. It's better to type /exit first, especially if a shell command was still running.
Can I mix slash commands and natural-language requests in the same session?
Yes. They are commonly mixed, for example running /init first, then a series of natural-language requests, then /compact partway through a long session.
Does a slash command ever modify my project files directly?
No. The slash commands covered here act on the session itself, context, history, and session lifecycle, not directly on your files. Real file edits come from natural-language requests routed through the agent.
Why would I use `/compact` instead of just `/clear`?
/compact keeps a condensed version of the session's history, so the agent retains some memory of earlier context. /clear discards it entirely, which is better when you're moving to a genuinely unrelated task.
Is there a difference between how the REPL treats a request and how a chat interface would?
The REPL request goes through the full agent loop: reading files, planning, acting, and verifying, not just producing a text reply. That distinction is the core difference from a typical chat interface.
What should my first command be in a brand-new project?
/init is a strong default, since it lets Claude Code build context about the project before you hand it a real task.
Related
- Claude Code 101 Basics - a broader set of first-session examples including install and launch.
- The Claude Code Mental Model: Agent, Not Autocomplete - what happens behind the scenes when a natural-language request is submitted.
- Installing Claude Code and Connecting Your First Project - how to get a session open in the first place.
- Permission Modes Explained: Auto-Accept vs Ask-Every-Time - how the REPL behaves differently depending on your permission mode.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5. Model names, pricing, and product features move quickly - verify current specifics at platform.claude.com/docs before relying on them.