← Back to list

7 Ways I Use Claude Code to Write Python Faster Every Day

Claude Code does not replace my Python knowledge. It removes the repetitive work that keeps me from using it.

Marcus D in Python in Plain English · 2026-06-06 04:57 · 0 claps · 7.7 min read paywalled
#python #python-programming #claude-code #claude #machine-learning
Open on Medium ↗
Wiki topics: LLM · Large Language Models ML · Machine Learning EDU · Education & Learning 💻 · Programming

7 Ways I Use Claude Code to Write Python Faster Every Day

Claude Code does not replace my Python knowledge. It removes the repetitive work that keeps me from using it.

A few weeks ago, I opened a Python project to fix what looked like a tiny bug.

The application was returning an empty list. Easy fix, right?

Forty minutes later, I had inspected six files, added three print statements, blamed the database, blamed the framework and briefly blamed Python itself. The actual problem was one incorrectly named dictionary key.

Classic software development.

That kind of experience is why I started using Claude Code as part of my daily Python workflow.

Not as an all knowing senior engineer. Not as a magical “build my startup” button.

I use it as a fast pair programmer that can inspect a codebase, run commands, edit files and help me verify changes without constantly copying code between my editor and a browser.

Here are the seven ways it saves me the most time.

Read the full article for free

Created in Canva

Created in Canva

1. I Ask It to Understand the Project Before Writing Code

The fastest way to generate bad code is to request a feature before understanding the existing system.

A vague prompt such as this is dangerous

Add user authentication to this project.

That gives Claude too much freedom. It may introduce a new library, duplicate existing functionality or create an architecture that fights the rest of the project.

I begin with investigation instead

Inspect this Python project.

Explain
1. The application entry point
2. The main modules
3. How data moves through the system
4. Where authentication is currently handled
5. Which files would need to change

Do not modify anything yet.

This gives me a project map before either of us starts swinging a hammer.

Claude Code is designed to work across a codebase rather than only with isolated snippets. That makes it useful for exploring unfamiliar repositories, but I still ask it to show its understanding before approving changes.

AI generated code is only as good as the context surrounding it.

Five minutes spent investigating can prevent an hour of cleaning up confident nonsense.

2. I Turn Rough Requirements into Small Implementation Plans

Developers often start coding while the requirement is still foggy.

Then we act surprised when the implementation becomes messy.

Before building anything substantial, I ask Claude Code to convert my idea into a sequence of small changes.

For example

I need to add CSV export to this reporting application.

Create a small implementation plan that
- Reuses the existing report service
- Avoids changing the database layer
- Adds type hints
- Includes pytest tests
- Handles empty results
- Does not add a new dependency

Do not write code yet.

The important phrase is

Do not write code yet.

Without it, coding assistants sometimes sprint towards implementation while I am still deciding where the finish line should be.

Once the plan looks reasonable, I ask it to implement one stage at a time.

This makes reviews easier. It also reduces the chance of receiving a 500-line “solution” that technically works but somehow creates four new problems.

3. I Use It to Generate the Boring First Draft

I enjoy solving interesting problems.

I do not enjoy writing the seventeenth nearly identical data-validation function of my career.

Claude Code is excellent at producing a first draft for predictable Python work

  • Data classes
  • Pydantic models
  • Command line argument parsing
  • File readers
  • Serialization functions
  • Logging setup
  • Repetitive API wrappers
  • Basic CRUD operations

Suppose I need to transform raw customer data

raw_customer = {
    "name": "  Maya  ",
    "email": "MAYA@EXAMPLE.COM",
    "age": "29"
}

I might prompt Claude like this

Create a typed Customer dataclass and a function that converts the
raw dictionary into a validated Customer object.

Requirements
- Strip surrounding whitespace
- Convert the email to lowercase
- Convert age to an integer
- Raise clear ValueError messages
- Use only the Python standard library
- Add concise docstrings

Could I write this manually? Of course.

I could also wash my clothes by hand. That does not make it the best use of my afternoon.

The generated code is a draft, not a sacred artefact. I inspect it, simplify it and adjust naming before keeping it.

4. I Debug with Evidence Instead of Guessing

One of my favourite Claude Code workflows begins with a failing command.

pytest tests/test_orders.py -q

Instead of pasting the traceback into a chat window, I ask Claude Code to run the test, inspect the related files and explain the failure.

My debugging prompt usually looks like this:

Run the failing order tests.

Identify the root cause before editing anything.

Show me
- The failing behaviour
- The expected behaviour
- The exact code path involved
- Your proposed minimal fix

Do not weaken or delete the test.

That final line matters.

An AI can “fix” a test suite by changing the test until it accepts broken behaviour. Congratulations. Everything is green and nothing is correct.

After reviewing the diagnosis, I ask it to apply the smallest reasonable change and rerun the relevant tests.

Claude Code’s documented workflows include debugging, testing and refactoring existing projects. The value is not that it magically knows the answer. The value is that it can gather evidence from the repository and development commands faster than I can manually jump between files.

My debugging rule

Never ask

Why doesn’t this work?

Ask

Reproduce the failure, trace the execution path and identify the smallest verified cause.

One prompt invites guessing. The other demands evidence.

5. I Make It Write Tests Before Refactoring

Refactoring without tests is not engineering.

It is gambling with better variable names.

Before changing fragile Python code, I ask Claude Code to document the current behaviour with tests.

Review calculate_invoice_total() and its callers.

Before refactoring
1. Add tests for the existing expected behaviour
2. Cover discounts, tax, empty orders and invalid quantities
3. Identify any ambiguous behaviour
4. Run the tests

Do not refactor the production function yet.

Once the tests pass, I request the refactor

Now refactor calculate_invoice_total() to reduce nesting and improve
readability.

Preserve the tested behaviour.
Do not change the public function signature.
Run the relevant tests after editing.

This is one of the most useful habits I have developed.

Tests become the fence around the behaviour. Claude can rearrange the garden, but it should not quietly move the property line.

For Python projects, I usually ask for

  • pytest tests
  • Clear test names
  • Edge cases
  • Minimal mocking
  • Behaviour-focused assertions
  • No unnecessary test classes

AI loves abstraction almost as much as enterprise architects love meetings. Explicit constraints help keep the test suite readable.

6. I Use It for Focused Code Reviews

“Review my code” is far too broad.

Review it for what?

Correctness? Security? Performance? Readability? Type safety? Naming? Architecture? Emotional damage?

I give Claude Code a specific review role.

For example

Review the current git diff as a strict Python maintainer.

Focus only on
- Incorrect behaviour
- Missing error handling
- Security risks
- Backward compatibility
- Tests that should be added

Do not comment on formatting unless it affects correctness.
Rank findings by severity.
Do not edit files.

For data-heavy code, I change the checklist

Review this change for
- Unnecessary repeated database queries
- Loading excessive data into memory
- Incorrect handling of null values
- Time-zone assumptions
- Missing transaction boundaries

A focused review produces better feedback because the model knows what “good” means for that task.

I also ask it to separate verified problems from suggestions:

Label every finding as
- Confirmed bug
- Likely risk
- Optional improvement

That simple instruction reduces the number of stylistic opinions presented as emergencies.

7. I Store Project Rules So I Stop Repeating Myself

Every codebase has its own personality.

One project uses ruff. Another uses black and flake8. One team loves Pydantic. Another avoids dependencies unless the building is actively on fire.

Claude Code supports project-level instructions through files such as CLAUDE.md, allowing teams to provide recurring context for future sessions. Anthropic explains this in its documentation on project memory.

A simplified project file might contain

# Project Instructions

## Python
- Use Python 3.12 features
- Add type hints to public functions
- Prefer pathlib over os.path
- Use pytest for testing
- Use ruff for linting and formatting
- Do not add dependencies without explaining why

## Architecture
- Keep business logic out of route handlers
- Database access belongs in repository modules
- Do not change public API responses without approval

## Verification
After modifying Python files, run
1. ruff check .
2. pytest -q

This prevents me from repeating the same instructions in every session.

For repetitive automation, Claude Code also supports hooks, which can run defined actions at specific points in its workflow. That can be useful for deterministic checks such as formatting, linting or blocking unwanted commands.

But I do not automate everything.

Automation should enforce clear rules. It should not turn the repository into a haunted house where mysterious scripts activate whenever someone touches a file.

Created in Canva

Created in Canva

The Prompt Pattern That Gives Me Better Python

Most of my successful prompts contain five ingredients:

1. Context

This is a FastAPI service using SQLAlchemy and PostgreSQL.

2. The exact task

Add pagination to the customer list endpoint.

3. Constraints

Do not change the response schema or add dependencies.

4. Verification

Add tests and run the relevant test file.

5. Boundaries

Do not modify unrelated files.

Put together

This is a FastAPI service using SQLAlchemy and PostgreSQL.
Add pagination to the customer list endpoint.

Requirements
- Keep the existing response schema
- Default to page 1 and 20 items
- Reject invalid page values
- Do not add dependencies
- Add pytest coverage
- Modify only the necessary files
- Run the relevant tests and summarize the results

That prompt is not clever.

It is clear.

Clear beats clever almost every time.

What I Never Let Claude Code Do Blindly

Claude Code makes me faster, but speed without review is simply a quicker route to production incidents.

I do not blindly accept

  • Authentication or authorization changes
  • Database migrations
  • Destructive shell commands
  • Cryptographic implementations
  • Dependency upgrades
  • Large architectural rewrites
  • Code that handles payments or sensitive information

I review diffs. I run tests. I inspect commands. I question assumptions.

Claude Code can help write code, navigate repositories, execute development commands and automate parts of a workflow. It cannot take responsibility for the software I ship.

That responsibility remains inconveniently human.

The Real Productivity Gain

The biggest benefit is not that Claude Code types Python faster than I do.

Typing was never the bottleneck.

The bottleneck was repeatedly locating files, tracing call paths, creating boilerplate, reproducing failures, writing predictable tests and checking whether a small change broke something elsewhere.

Claude Code compresses those loops.

Used carelessly, it produces larger quantities of questionable code.

Used deliberately, it gives me more time to think about architecture, behaviour and the actual problem.

That is the difference between using AI as an autocomplete machine and using it as an engineering tool.

Try one workflow from this article rather than adopting everything at once. Start with codebase exploration or test-assisted debugging. Keep the prompts specific. Review every change.

And never confuse a passing test suite with proof that the code is good.

Sometimes it only means you wrote equally confused tests.

What is your most useful Claude Code workflow and which one has created the biggest mess?

Share your experience in the comments.

Disagreement is welcome; vague “AI will replace everyone” speeches may be charged a processing fee.

Clap if this saved you a few debugging hours,

save it for your next Python project and send it to the teammate who still pastes an entire repository into a chat window.


메타데이터
post_id
2343a06083e8
slug
7-ways-i-use-claude-code-to-write-python-faster-every-day-2343a06083e8
url
https://medium.com/@dmarcus12/7-ways-i-use-claude-code-to-write-python-faster-every-day-2343a06083e8
canonical_url
https://medium.com/@dmarcus12/7-ways-i-use-claude-code-to-write-python-faster-every-day-2343a06083e8
author_url
https://medium.com/@dmarcus12
status
ok
fetched_at
2026-06-09 15:37:30