claude-code
Claude Code チュートリアル - Anthropic
Claude Code Best Practices \ Anthropic
CLAUDE.md は複数の場所における
~/.claude/CLAUDE.md
カレントディレクトリ
claude コマンドの親ディレクトリ
子ディレクトリから特定のファイルを読む際のディレクトリ
# で指示したことを CLAUDE.md に記述を追加
/allowed-tools から許可するツールの設定
.mcp.json に共有 MCP 設定書ける
.claude/commands においておいたものは / コマンドから呼び出せる
/project:{command}
支持から思考トークンの予算指定できる
think < think hard < think harder < ultrathink
Claude can infer intent, but it can't read minds.
いいね
Shift+Tab で auto-accept モード
Esc 2回で履歴を戻れる
/clear でコンテキスト消す
/compact でコンテキスト圧縮させる、指示して特定のところに注目して残させる
cat foo.txt | claude でデータ渡しつつ呼び出せる
/status で色々確認
MCPの接続状態等も
VS Code から使う (IDE Integrations)
VSCode Terminal から claude 起動することで拡張が入る
https://docs.anthropic.com/ja/docs/claude-code/ide-integrations
/terminal-setup しておくと Shift+Enter で改行できるようになる
これが追加されるだけ
code:keybindings.json
{
"key": "shift+enter",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\\\r\n"
},
"when": "terminalFocus"
}
MCP サーバー追加する
例 DeepWiki MCP を追加する
設定ファイル
ドキュメントにないけど ~/.claude.json のトップレベルに mcpServers 追加すればよい
claude-code はこっちの記法に対応していて mcp-remote 要らないのね
code:~/.claude.json
{
// ...
"mcpServers": {
"deepwiki": {
"type": "sse",
"url": "https://mcp.deepwiki.com/sse"
}
}
}
コマンド
$ claude mcp add -s user -t sse deepwiki https://mcp.deepwiki.com/sse
-s は scope
Claude CodeをMCPサーバーとして使用する - Claude Code チュートリアル - Anthropic
Claude Desktop から呼べる
いつのまにか「Claude CodeをMCPサーバー化」してClaude Desktopから利用できる神機能が生えてた件について
code:setting.json
{
"command": "claude",
"args": "mcp", "serve",
"env": {}
}
VertexAI や Bedrock 経由で呼ぶには env に設定すればよい
Claude Code overview - Anthropic
実装が if (process.env.CLAUDE_CODE_USE_VERTEX) { ... } だから CLAUE_CODE_USE_VERTEX=0 とかしてもダメ、オフにするには空文字列を入れよう
別にコード書かなくても便利
https://gyazo.com/a4e45ae4856f5bdab74c3abfc481d596
Markdown Conversation History Tracking Feature Request · Issue 209 · anthropics/claude-code
これはほしいなあ → claude-code の以前のセッションを復元したい
/terminal-setup が無い・Shift + Enter で改行できない
TERM_PROGRAM 環境変数に tmux とかが入っているとコマンドが見えなくなる、俺は iTerm2 & tmux 下で動かしているので
$ TERM_PROGRAM=iTerm.app claude した状態で /terminal-setup するとできるようになる、1度やれば OK
他にも
Apple_Terminalだと改行が Option+Enter になる
$ cat cli.js | grep -oE 'terminal==="([^"]+)"' で対応入っているターミナルアプリ見れる
vscode や cursor, windsurf も、ghostty や kitty なども
vscode なら workbench.action.terminal.sendSequence が設定に追記される、という風に実現されている
カスタムコマンドの作り方
https://docs.anthropic.com/en/docs/claude-code/tutorials#create-custom-slash-commands
~/.claude/commands/なんとか.md に置く
引数は $ARGUMENTS に展開される
入力: $ARGUMENTS と書いて もし入力がなければそこで中断 など書けばよい
自分の発言ログだけ見たい
$ cat SESSION_ID.jsonl | jq '. | select(.message.role == "user") | select(.isMeta | not) | select(try (.message.content0.type) catch null | . != "tool_result") | .message | { "content": .message.content, timestamp }' | pbcopy
たまに俺がこういうことを言っていることになってるね(isMeta: true)
code:quote
Caveat: The messages below are were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.