0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL環境にClaude Codeをインストールして簡単なpythonファイルを生成させた

Last updated at Posted at 2025-07-30

初めに

Claudeは、Anthropicが開発した最先端の大規模言語モデルファミリーです。
その中で、Claude Codeとは「Anthropicのエージェント型コーディングツール」で、ターミナル内で動作し、アイデアをこれまで以上に素早くコードに変換するのを支援できるツールです。

言葉の簡単なおさらい

  • エージェント型:人間の代理として自律的に動くソフトの構造
  • AIエージェント:LLMなどのAIを使って、自分で考えて複数ステップの行動を取る代理人
  • Claude Code:ターミナル内で動く「AIエージェント型のペアプログラマー」

Claude Codeのインストール

早速、インストールしてみていきましょう。私はWindowsのWSL環境で実施してきます。

下記のようにCloude Codeをインストール

@DESKTOP-C0A2DE7:claude $ sudo npm install -g @anthropic-ai/claude-code

npm は Node.js のパッケージマネージャですが、Claude Codeのインストールに使う理由は次の通りです。

  1. Claude Codeの配布形態
    Claude Code は CLIツール(コマンドラインツール) ですが、
    その本体が JavaScript/TypeScript で書かれている ため、Node.js環境で動きます。
    開発者はこのツールを npmパッケージとして配布しているため、ユーザーは npm install -g でインストールします。

下記のコマンドで実行可能である。

claude

Cloude Codeをブラウザで見てみると、コンソールかAPI実行を確認できるようだ。
image.png

最初の状態は下記。$5分の使い切りを買ってみたので、一旦このような表示になっている。
image.png

Claude Codeの動作確認

試しにWSL上から実行してみるとAPI発行されて、返答が返ってくる。

(base) user@DESKTOP-C0A2DE7:claude$ claude
╭───────────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code!                                     │
│                                                               │
│   /help for help, /status for your current setup              │
│                                                               │
│   cwd: /mnt/d/iCloudDrive/MyJob/aboutTech/Github_repo/claude  │
╰───────────────────────────────────────────────────────────────╯

 Tips for getting started:

 1. Ask Claude to create a new app or clone a repository
 2. Use Claude to help with file analysis, editing, bash commands and git
 3. Be as specific as you would with another engineer for the best results

> 日本語はできる?

● はい、日本語ができます。何かお手伝いできることはありますか?

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ >    

image.png

言語のモデルもCLIでできるらしい。
image.png

CLIでやってみる。
image.png
怒られた(笑)

image.png

グルーバル変数でもダメだった。
image.png

色々、setting.jsonを修正するなど実施してもダメだった。下記のサイトより、モデルを変更できそうである。

AIエージェントにコード作成を依頼してみる

それで本題で、claudeCodeに聞いてみます。
claudeのコンソールにてFibonacci数列を100まで計算するスクリプトを作ってと聞いてみます。


> Create a Python script that calculates Fibonacci numbers up to 100

image.png

こんな感じでフィボナッチ数列を作成するpythonファイルができました。
image.png

確かにカレントディレクトリにfibonacci.pyが生成されていることわかります。

● The script generates Fibonacci numbers up to 100 using an efficient iterative approach. Run it with python fibonacci.py.

> python fibonacci.py

● Bash(python fibonacci.py)
  ⎿  Fibonacci numbers up to 100:
     [
       0,
     … +14 lines (ctrl+r to expand)

● The script successfully calculated all Fibonacci numbers up to 100. There are 12 Fibonacci numbers in this range, from 0 to 89.

> /exit
  ⎿  (no content)

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ >                                                                                                                                                                                                             │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ? for shortcuts



Total cost:            $0.0295
Total duration (API):  27.2s
Total duration (wall): 7m 4.1s
Total code changes:    18 lines added, 0 lines removed
Usage by model:
    claude-3-5-haiku:  1.4k input, 106 output, 0 cache read, 0 cache write
       claude-sonnet:  18 input, 420 output, 58.6k cache read, 1.1k cache write
(base) user@DESKTOP-C0A2DE7:claude$ ls
fibonacci.py
(base) user@DESKTOP-C0A2DE7:claude$

試しにpythonを実行してみましょう。

(base) user@DESKTOP-C0A2DE7:claude$ python fibonacci.py
Fibonacci numbers up to 100:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]

Total count: 12
(base) user@DESKTOP-C0A2DE7:claude$

結構ポチポチしょうもないコマンドをたたきましたが、使用したコストはこれくらいでした。30円くらい。
image.png

最後に

Anthropicのエージェント型コーディングツールであるclaude CodeのインストールとAPI発行して、少しのCLIでの対話とAPI経由でスクリプトファイルの生成を実施してみました。
普段はVScodeでGithub Copilotを使用していますが、Claude Codeの活用もスキルとして身に着けていきたいですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?