個人的に一番いい構成がClaude Max + Claude code + Termux + Tailscale + tmuxだった。

前提

  • TDDを全力でやる

インストール

Claude Maxを契約していたらClaude Codeを定額で利用できる。元々APIで使っていてMaxを契約しても一旦ログアウトしないと課金されるので注意

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

初期設定

/initをすると既存のREADME、Cursor RulesやCLINE Rulesを読んでくれていい感じにCLAUDE.md生成してくれる。

トークンがいっぱいになると要約して開放するような挙動をするはず。このあたりを読んでホームディレクトリやプロジェクトディレクトリに設定を追加する。

Claude Codeはメモリを再帰的に読み取ります。cwdから始めて、/まで再帰的に読み取り、見つかったCLAUDE.mdまたはCLAUDE.local.mdファイルを読み取ります。これは、Claude Codeを__foo/bar/で実行し、 foo/CLAUDE.md_とfoo/bar/CLAUDE.mdの両方にメモリが存在するような大規模なリポジトリで作業している場合に_特に便利です。Claude は、現在の作業ディレクトリ以下のサブツリーにネストされた CLAUDE.md も検出します。起動時に読み込むのではなく、Claude がサブツリー内のファイルを読み取るときにのみ読み込みます。

Manage Claude’s memory - Anthropic

完了後にベルを鳴らす:

https://docs.anthropic.com/ja/docs/claude-code/settings#%E9%80%9A%E7%9F%A5%E8%A8%AD%E5%AE%9A

claude config set --global preferredNotifChannel terminal_bell

基本操作

  • claude -c: 前回のセッションに戻る
  • claude -r: セッション履歴
  • Ctrl + j で改行
  • Ctrl + v でクリップボードから画像貼り付け
  • @\path/to/file で任意のファイルを指定
    • 直接コピーするか、ファイルをターミナルにドラッグ可能
  • !を先頭につけるとbashコマンドを受け付ける
  • #でメモリーに設定を保存ができる
  • /clearで新しいスレッドを開始する
  • Shift + Tabでplan modeやauto accept edit modeに変える
  • etcで処理を止める

Vimモード:

  • モード切り替えEsc (NORMALモードへ), i/Ia/Ao/O (INSERTモードへ)
  • ナビゲーションh/j/k/l (←/↓/↑/→), w/e/b (単語移動), 0/$ (行頭/行末), ^ (行頭の非空白文字), gg/G (ファイル先頭/末尾)
  • 編集x (一文字削除), dw/de/db/dd/D (削除), cw/ce/cb/cc/C (変更), . (直前の操作を繰り返し)

エイリアス

許可プロンプトをスキップする:

alias yolo="claude --dangerously-skip-permissions"

claude -pで応答を出力するショートカットとして使える。gcautoなどとして設定するといい。

git commit -m "$(claude -p "Look at the staged git changes and create a summarizing git commit title. Only respond with the title and no affirmation.")"

[現代のslコマンドは%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89)なので、Claude Codeを割り当てる

 \$() {
   claude "$*"
 }

利用料金の把握

Claude Maxを使っていてもどのくらいコストを使っているかを可視化できる

# Using npx
npx ccusage@latest
 
# Using bunx
bunx ccusage
 
# Using pnpm
pnpm dlx ccusage
 
# Using Deno with security flags
deno run -E -R=$HOME/.claude/projects/ -S=homedir -N='raw.githubusercontent.com:443' npm:ccusage@latest

リアルタイム監視

npx ccusage@latest blocks --live

MCP

Claude Code自体をMCPサーバー化することもできるし、Claude CodeにもMCPを追加できる

{
  "mcpServers": {
	"claude_code": {
		"command": "/usr/local/bin/claude",
		"args": ["mcp", "serve"],
		"env": {}
	}   
  }
}

私は知り合いが作ったurl html2mdライブラリの[MCPサーバー](https://github.com/yutakobayashidev/webforai-mcp-server)入れてる。プロジェクトルートの .mcp.json が自動で認識されます。

{
  "mcpServers": {
    "webforai": {
      "command": "npx",
      "args": ["mcp-remote","https://webforai-mcp-server.yutakobayashi.workers.dev/sse"]
    }
  }
}
$ claude --mcp-config=.claude/mcp.json

リモートMCPも対応した:

# Basic syntax
claude mcp add --transport http <name> <url>
 
# Example: Adding a streamable HTTP server
claude mcp add --transport http http-server https://example.com/mcp
 
# Example: Adding an HTTP server with authentication header
claude mcp add --transport http secure-server https://api.example.com/mcp -e Authorization="Bearer your-token"

CI / CD・リンター

リンターとして使う:

// package.json
{
    ...
    "scripts": {
        ...
        "lint:claude": "claude -p 'あなたはリンターです。mainブランチとの変更を確認し、タイポに関する問題を報告してください。ファイル名と行番号を1行目に、問題の説明を2行目に報告してください。他のテキストは返さないでください。'"
    }
}

Github Actions:

若干evilなのでチームで使う場合やTOSが変わる場合は注視したほうがよさそう。また、Actionsのリポジトリオーナー以外がイシュー作ったりしても発火しないように調整が必要かも。

Is this allowed by Anthropic? · Issue #6 · grll/claude-code-action

name: Claude PR Assistant
 
on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]
  pull_request_review:
    types: [submitted]
 
jobs:
  claude-code-action:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
      (github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
 
      - name: Run Claude PR Action
        uses: grll/claude-code-action@beta
        with:
          use_oauth: true
          claude_access_token: ${{ secrets.CLAUDE_ACCESS_TOKEN }}
          claude_refresh_token: ${{ secrets.CLAUDE_REFRESH_TOKEN }}
          claude_expires_at: ${{ secrets.CLAUDE_EXPIRES_AT }}
          
          timeout_minutes: "60"
          # Optional: add custom trigger phrase (default: @claude)
          # trigger_phrase: "/claude"
          # Optional: add assignee trigger for issues
          # assignee_trigger: "claude"
          # Optional: add custom environment variables (YAML format)
          # claude_env: |
          #   NODE_ENV: test
          #   DEBUG: true
          #   API_URL: https://api.example.com

並列化・リモート化

git worktree

git worktreeで開発したいなら以下のコマンドが良さそう:

$ git worktree add .git/works/new-feature 
$ code .git/works/new-feature 
# ここでAIに実装させておく 
 
# 採用して削除 
$ git rebase new-feature && git worktree remove .git/works/new-feature

参考: git worktreeを扱うfish functionを作成した - hiroppy’s site

Termux + Tailscale + Tmux + copilot.vim

トイレや外出中にもClaude Codeのセッションをスムーズに維持したままデバイス間で行き来したいため、この組み合わせが最高。スマホだけで作業を進められる。画面分割やgit worktreeと組み合わせてパネル複数の並列化も出いる

TermuxとTailscaleをインストールする:

TermuxはAndroidデバイスでLinuxのターミナル環境を動かすことができるOSS。ここからTailscaleでSSHする

Tmux:

screenでも多分いけると思う。ターミナルを永続化するような役割

$ tmux new-session -s mysession

この間にClaude Codeを動かしておいて、Ctrl+bを押してからdを押して、セッションをデタッチして、バックグラウンドに送る。あとは他のクライアントでセッションに再接続できる。

$ tmux attach-session -t mysession

この辺りはキーバインドを工夫すれば簡素化できると思う

copilot.vim:

スマホだと編集がつらいのでcopilot.vim入れとく

git clone --depth=1 https://github.com/github/copilot.vim.git \
  ~/.config/nvim/pack/github/start/copilot.vim

隠しコマンド

ultrathinkとかいうとめちゃくちゃ考えてくれる

カスタムコマンド

TODO

  • これやりたい