Claude Code を使う時のルール

Claude Code を使う時のルール 生成 AI

①ホームディレクトリでClaude Codeを起動しない。
 ホームディレクトリでClaude Codeを起動せず、
 プロジェクトごとに作業フォルダを作って行う。
 必要な権限以外の権限を与えない。
※私はC:¥ではなく、D:¥など空のドライブにディレクトリを作り、
その中にプロジェクト用の作業ディレクトリを作成している。
PS D:\WSL\Ubuntu> WSL -d Ubuntu-D –USER USER
USER@PC:/mnt/d/WSL/Ubuntu$ claude

②設定ファイルであるsettings.jsonを置く。
 Claude Codeにやって欲しくないことをやらないように設定しておく。
 あるいはやって欲しいことを許可するように設定しておく。
 許可・拒否・確認を決めておく。
 .envを見に行かないように(読ませないように)する。
 settings.jsonのdeny設定(パーミッション設定)を行う。
 読めてしまうと情報漏洩につながることがありうる。

※グローバル(/home/user/.claude/settings.json)
“permissions”: {
“deny”: [
“Read(**/.env)”,
“Grep(**/.env)”,
“Glob(**/.env)”
],
“defaultMode”: “bypassPermissions”
},
“model”: “sonnet”,
“disableClaudeAiConnectors”: true,
“effortLevel”: “medium”,
“skipDangerousModePermissionPrompt”: true
}

※プロジェクト(/mnt/d/WSL/Ubuntu/.claude/settings.json)
– /mnt/c, /mnt/e〜r などの他ドライブへの
Read/Edit/Write/Glob/Grep と cd を拒否
– Dドライブ内でも
$RECYCLE.BIN、Downloads、System Volume
Information、*.pdf を拒否

※用途としては「Dドライブ(ワークスペース)以外に触らせない」ためのガード設定にしています。

③サンドボックスを用いる。
 AIが作業できる範囲を指定し、その範囲内で動かす。

※ターミナルで、「/sandbox」とすると、

Sandbox Dependencies ← 依存関係
ripgrep (rg): found ← 検出済
bubblewrap (bwrap): not installed ←未インストール
· apt install bubblewrap
socat: not installed ←未インストール
· apt install socat
seccomp filter: installed ←インストール済

となった。AIが作業できる範囲を指定していると言えない。

 sudo apt install bubblewrap socat

PS D:\WSL\Ubuntu> WSL -d Ubuntu-D –user user
USER@PC:/mnt/d/WSL/Ubuntu$ sudo apt install bubblewrap socat
[sudo] password for USER:
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
The following additional packages will be installed:
libwrap0
The following NEW packages will be installed:
bubblewrap libwrap0 socat
0 upgraded, 3 newly installed, 0 to remove and 248 not upgraded.
Need to get 443 kB of archives.
After this operation, 1625 kB of additional disk space will be used.
Do you want to continue? [Y/n] y[Enter]

再起動し、ターミナルで、「/sandbox」とすると、
Sandbox Mode Overrides Config

Configure mode

1. Sandbox BashTool, with auto-allow
2. Sandbox BashTool, with regular permissions
3. No Sandbox ✔

Auto-allow mode: Commands will try to run in the sandbox
automatically, and attempts to run outside of the sandbox
fallback to regular permissions. Explicit ask/deny rules are
always respected.

となっていたので、1を選んだ。その後、
~/.claude/settings.json へこれを入れておく
{
“sandbox”: {
“credentials”: {
“files”: [
{ “path”: “~/.aws/credentials”, “mode”: “deny” },
{ “path”: “~/.ssh”, “mode”: “deny” }
],
“envVars”: [
{ “name”: “GITHUB_TOKEN”, “mode”: “deny” }
]
}
}
}

❯ /hooks で反映されているか確認して
Hooks
0 hooks configured

ℹ This menu is read-only. To add or modify hooks, edit
settings.json directly or ask Claude. Learn more

❯ 1. PreToolUse Before tool execution
2. PostToolUse After tool execution
3. PostToolUseFailure After tool execution fails
となっていたので、1を選んだ。

④.envは平文(ひらぶん)で保存しない。暗号化する。
⑤APIキーを無制限で使用しない。使う前に上限を決める。
⑥すべてのコマンドを全承認しない。
➆常にパイパスパーミッションしない。下記のオプションは使わない。
 –dangerously-skip-permissions
⑧コネクタの認証は最小限にする。あらゆるコネクタを認証しない。
⑨コネクタを常時つなぎっぱなしにしない。
⑩ローカルだけで終わらせない。デプロイ(公開)する。
⑪デプロイ先は把握する。
⑫AIが言ったことを疑う。
※APIキーがハードコーディングされていないか、確認して
 結論: APIキーのハードコーディングは検出されませんでした

①~⑫を確認した。

引用サイト:https://www.youtube.com/watch?v=fJ3gQaOMfNc&t=2585s

Views: 1

タイトルとURLをコピーしました