Skip to main content

Claude Code: A Guide With Practical Examples

Learn how to use Anthropic's Claude Code to improve software development workflows through a practical example using the Supabase Python library.
Feb 28, 2025  · 12 min read

Claude Code is an agentic coding tool developed by Anthropic that operates directly in the terminal, assisting developers in refactoring, documenting, and debugging code efficiently. By understanding the entire codebase, Claude Code helps simplify workflows, making it a powerful tool for software development.

In this tutorial, I’ll explain how to use Claude Code to improve software development workflows by refactoring, documenting, and debugging code. Specifically, we will:

  • Refactor a file from the supabase-py repository to improve code readability and maintainability.
  • Add documentation and inline comments to improve understanding of the existing codebase.
  • Identify and resolve errors using Claude Code’s debugging capabilities.

You will learn how to integrate Claude Code into your development process for a more efficient and automated experience. Before we start, make sure to also check our short video coverage of Claude 3.7 Sonnet and Claude Code:

What Is Claude Code?

Claude Code is a tool that operates directly in your terminal, understanding your codebase and assisting with development tasks using natural language commands. By integrating with your development environment, Claude Code eliminates the need for additional servers or complex setups, allowing developers to focus on writing and improving code. 

claude code features

Here are a few key capabilities of Claude Code:

  • Editing and refactoring: Modify, optimize, and enhance your codebase with AI-powered suggestions.
  • Bug fixing: Identify and resolve errors, missing dependencies, and performance bottlenecks.
  • Code understanding: Ask questions about your code’s architecture, logic, and dependencies.
  • Automated testing & linting: Execute and fix failing tests, run linting commands, and improve code quality.
  • Git integration: Search through git history, resolve merge conflicts, create commits, and generate pull requests effortlessly.

Whether working on an open-source project or managing enterprise-level codebases, Claude Code can help you with intelligent automation that adapts to your coding style and project requirements. Here are some ideal users for this service:

  • Software Developers: Improving code quality and maintainability.
  • Open Source Contributors: Understanding and enhancing unfamiliar codebases.
  • DevOps Engineers: Automating code review and linting tasks.

For now, Claude Code is only available as a preview, and developers are encouraged to test it and provide feedback—if you haven’t signed up yet, you can join the waitlist here.

Let’s get started with our hands-on project.

Step 1: Setting Up Claude Code

Once you are off the waitlist, the Anthropic team provides you with a link to authenticate and run Claude Code locally. 

Access Claude Code in beta

This redirects you to connect your Anthropic account to Claude Code. Authorize the connection, and you’re done. Ensure that your account has an active billing setup.

Claude Code Authorize page

Next, simply run the following command on your terminal.

npm install -g @anthropic-ai/claude-code

This command installs Claude Code on your machine. Once installed, navigate to your project directory and start Claude by running:

cd your-project-directory
claude

Claude Initialized on terminal

Now, Claude Code is ready to use.

Step 2: Set Up Development Environment

For this demo, I’ll use the Supabase Python library supabase-py, an open-source Python client for interacting with Supabase, a backend-as-a-service built on PostgreSQL. Supabase provides a suite of tools, including authentication, real-time subscriptions, storage, and auto-generated APIs.

Let’s begin by cloning the repository and setting up our development environment.

1. Open your terminal, navigate to the directory where you want to clone the Supabase-py repository (e.g cd Desktop), and run the following command:

git clone https://github.com/supabase/supabase-py.git
cd  supabase-py

2. Next, create a virtual environment and install the required dependencies by running the following commands in your terminal one at a time

python3 -m venv env
source env/bin/activate  # On Windows, use ./env/Scripts/activate
pip install -e .

Your Python environment is now set up with all the necessary dependencies to run the Supabase library, and your repository is ready to be explored. 

Step 3: Identify Areas for Contribution

A great way to contribute is by exploring the Issues tab on GitHub. In the Supabase repository, I identified an issue in client.py related to code readability, structure, and lack of meaningful comments.

Here is what we are going to do with Claude Code:

  • We’ll refactor the code to enhance readability, maintainability, and structure.
  • Add meaningful docstrings and inline comments to clarify the purpose of different components.
  • Identify and fix bugs by analyzing issues and other potential errors.

Step 4: Experimenting With Claude Code

Since we are already in the supabase-py folder, navigate to the supabase directory containing the client.py file and run Claude Code:

cd supabase
claude

Claude Code in terminal

Claude Code now has access to every file and folder within the Supabase-py folder. Now, let’s experiment.

Refactoring code

As part of improving the Supabase Python SDK, let's refactor the client.py file to enhance readability, maintainability, and organization. Simply enter the following prompt in the command line:

Prompt: Refactor the code in the client.py file located in the Supabase folder.

Claude will ask for confirmation before proceeding. Press Enter to approve the changes. Once complete, Claude Code will update the file, display the modifications in the terminal, and provide a summary of the changes made.

Using Claude Code, we applied the following improvements to client.py:

  • Organized imports:  Claude Code grouped related imports into logical sections (auth errors, API types, function errors), renamed imports for clarity, and removed redundant aliases for consistency.
  • Enhanced readability: It added section comments to classify imports and removed duplication in the __all__ list for cleaner organization.
  • Simplified client options: It also reduced multiple lines by combining similar imports into a single statement.

Here is a side-by-side comparison of original and refactored code.

comparison of original and refactored code

comparison of original and refactored code

Documenting code

In addition to refactoring, Claude Code is a powerful tool for generating, enhancing, and standardizing code documentation. It can identify undocumented sections, generate structured docstrings or comments, and ensure compliance with project documentation standards.

We used Claude Code to improve the documentation in client.py, resulting in:

  • Clear module-level docstrings explaining the purpose of the file.
  • Detailed section comments categorizing imports (error types, client implementations, storage services).
  • Inline comments to describe error types, client functions, and important components.

Here is a side-by-side comparison of refactored and documented code.

Prompt: Document the client.py code by adding comments to improve understanding.

comparison of refactored code and documented code.

Once the documentation is added, you can verify its compliance with your project standards by prompting Claude:

Prompt: Check if the documentation follows our project standards.

Fixing bugs

Debugging can be time-consuming, but Claude Code makes it easier by analyzing error messages, identifying root causes, and suggesting fixes. Whether you're dealing with missing imports, runtime errors, or logic issues, it helps streamline the process by providing actionable solutions.

Here is how to use Claude Code for debugging:

  1. Identify the issue:  Share the error message with Claude.
  2. Get fix recommendations: Ask Claude for possible solutions.
  3. Apply and verify the fix:  Implement Claude’s suggestions and check if the issue is resolved.

Claude Code made the following arrangements to resolve import-related issues within the client.py file: 

  • Type ignore comments: Added # type: ignore comment to suppress IDE and type-checking warnings for unresolved imports.
  • Consistent error categorization: Claude Code ensured that error imports from authentication, database, storage, and functions are clearly grouped.
  • Maintained code readability: Comments were added to indicate why certain imports were ignored rather than removing them.

Here is a side-by-side comparison of the original code and the fixed code.

Prompt: I see some bugs, such as 'Import gotrue.errors' could not be resolved. Help me fix all errors in client.py.

comparison of the original code and bug fixed code.

Note: Claude Code is still in preview, so instead of suggesting an import command to resolve the issue, it added an ignore comment to suppress the error. As it continues to improve, it will provide more precise solutions.

Claude Code Commands

Here are a few commands for you to try with Claude.

Commands

Action

/clear

Clear conversation history and free up context  

/compact

Clear conversation history but keep a summary in context  

/cost

Show the total cost and duration of the current session

/doctor

Checks the health of your Claude Code installation

/help

Show help and available commands

/init

Initialize a new CLAUDE.md file with codebase documentation

/bug  

Submit feedback about Claude Code

/review

Review a pull request

I also recommend checking the tutorials Antrophic posted here.

Conclusion

In this tutorial, we used Claude Code to refactor, document, and debug a file in Supabase Python SDK. We improved code readability, added structured documentation, and resolved import issues. By integrating Claude Code into your workflow, you can streamline development and enhance code quality. As it evolves, it will offer even more precise solutions—try it on your own projects and see the impact!

To be up to date on the latest AI news, I recommend these blogs:


Aashi Dutt's photo
Author
Aashi Dutt
LinkedIn
Twitter

I am a Google Developers Expert in ML(Gen AI), a Kaggle 3x Expert, and a Women Techmakers Ambassador with 3+ years of experience in tech. I co-founded a health-tech startup in 2020 and am pursuing a master's in computer science at Georgia Tech, specializing in machine learning.

Topics

Learn AI with these courses!

course

Implementing AI Solutions in Business

2 hr
27.1K
Discover how to extract business value from AI. Learn to scope opportunities for AI, create POCs, implement solutions, and develop an AI strategy.
See DetailsRight Arrow
Start Course
See MoreRight Arrow
Related

blog

Anthropic Computer Use: Automate Your Desktop With Claude 3.5

Discover Anthropic’s new computer use feature and let Claude manage your workspace and automate your tasks. Simply type the prompt, and Claude will handle the rest.
Abid Ali Awan's photo

Abid Ali Awan

9 min

blog

Claude Artifacts 101: Types, Use Cases, Sharing, and Remixing

Explore Claude Artifacts, a new way to work with AI-generated content. Create, edit, and share interactive documents, code snippets, and website designs directly in Claude.
Ryan Ong's photo

Ryan Ong

8 min

tutorial

Getting Started with the Claude 2 and the Claude 2 API

The Python SDK provides convenient access to Anthropic's powerful conversational AI assistant Claude 2, enabling developers to easily integrate its advanced natural language capabilities into a wide range of applications.
Abid Ali Awan's photo

Abid Ali Awan

12 min

tutorial

Claude 3.7 Sonnet API: A Guide With Demo Project

Learn how to use Claude 3.7 Sonnet's API by building a Gradio-based Research Paper Analyzer to extract insights from uploaded PDFs.
Aashi Dutt's photo

Aashi Dutt

12 min

tutorial

Claude Sonnet 3.5 API Tutorial: Getting Started With Anthropic's API

To connect through the Claude 3.5 Sonnet API, obtain your API key from Anthropic, install the anthropic Python library, and use it to send requests and receive responses from Claude 3.5 Sonnet.
Ryan Ong's photo

Ryan Ong

8 min

code-along

Introduction to Claude

Aimée, a Learning Solutions Architect at DataCamp, takes you through how to use Claude. You'll get prompt engineering tips, see a data analysis workflow, and learn how to generate Python and SQL code with Claude.
Aimée Gott's photo

Aimée Gott

See MoreSee More