Getting Started with Claude Code in the Command Line
- Nishadil
- September 04, 2026
- 0 Comments
- 4 minutes read
- 0 Views
- Save
- Follow Topic
A hands‑on guide to building a FastAPI‑SQLite CRUD app using Claude Code
Step‑by‑step instructions for installing Claude Code, creating a virtual environment, and using its CLI to generate a FastAPI CRUD API with SQLite and automated tests.
First things first – grab Claude Code, install it, and sign in with your Anthropic account. A simple claude /login in any terminal will prompt you for the credentials.
Next, spin up a fresh project folder and a Python virtual environment. Something like:
mkdir books-api && cd books-apipython -m venv .venv && source .venv/bin/activate
Now you’re ready to launch Claude inside that directory. Just type claude and you’ll be dropped into an interactive session where the AI can look around your files, suggest changes, and even run shell commands.
The CLI understands a handful of shortcuts. Typing claude "query" starts a session with an initial prompt, claude -c continues the most recent conversation, and claude -p "query" runs a one‑off query without staying in interactive mode. When you need to update the tool itself, claude update does the job, and claude doctor checks that everything’s wired up correctly.
One of the neat features is the permission mode system. By default Claude will ask before it edits a file or runs a command, but you can shift into acceptEdits, plan, auto, and other modes. Pressing Shift+Tab cycles through them on the fly, or you can start a session with --permission-mode plan to let Claude merely explore and propose a plan before touching any code.
For this walkthrough we fire up Claude in plan mode, give it a clear task, and watch it draft a roadmap:
claude --name books-api --permission-mode plan
Prompt: “Build a CRUD API for a book collection using FastAPI and SQLite. Use SQLAlchemy for the models and Pydantic for validation. Add a pytest suite covering each endpoint. Keep the project to four source files.”
Claude responds with a concise outline – the files it intends to create, the dependencies it will need, and a sketch of the endpoints (list, create, read, update, delete). Once you give a thumbs‑up, the AI proceeds to write the files.
The resulting layout looks like this:
books-api/
├── database.py
├── schemas.py
├── main.py
├── test_main.py
└── requirements.txt
database.py holds the SQLAlchemy engine and a simple Book model. schemas.py defines the Pydantic classes for request and response payloads. main.py wires up FastAPI, injects the dependency that opens a DB session, and declares the CRUD routes. Finally, test_main.py contains a handful of pytest functions that hit each endpoint and verify the expected JSON output.
Here’s a taste of the generated route code:
@app.get("/books", response_model=list[schemas.Book])
def list_books(db: Session = Depends(get_db)):
return db.query(models.Book).all()
@app.post("/books", response_model=schemas.Book, status_code=201)
def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)):
record = models.Book(book.model_dump())
db.add(record)
db.commit()
db.refresh(record)
return record
Running and testing the project is a breeze because Claude lets you execute shell commands right from its prompt. Prefix a command with ! and the output is woven back into the conversation, so Claude can spot errors and suggest fixes.
For example:
!pip install -r requirements.txt!pytest -q
If a test fails, Claude will see the traceback, point out the offending line, and propose a patch. You can accept the change, and Claude will apply it automatically.
Long‑running tasks, like launching the development server, can be sent to the background. While the server runs, press Ctrl+B and Claude returns you to the interactive session. Then you can fire off quick curl calls to verify the API without leaving the CLI:
!curl -s -X POST localhost:8000/books -H "Content-Type: application/json" -d '{"title":"Dune","author":"Frank Herbert","published_year":1965,"isbn":"123456"}'
!curl -s localhost:8000/books
When you’re satisfied with the changes, use /diff inside the Claude session to review a Git diff of everything that happened. You can inspect the whole patch, drill down to a single turn, or look at a specific file. Once the diff looks good, commit and push as you normally would.
In short, Claude Code turns the command line into a collaborative coding partner – it can explore your repository, draft implementations, run tests, and even help you debug, all without you leaving the terminal.
Editorial note: Nishadil may use AI assistance for news drafting and formatting. Readers can report issues from this page, and material corrections are reviewed under our editorial standards.