Aller au contenu

Claude Code

De Banane Atomic

Prompt

Command Description
@ + Path add a specific file into the context
Esc stop Claude, allowing you to redirect or correct it
Esc + Esc rewind the conversation to an earlier point in time (removes context not relevant to the current tasks)
continue resume conversation after a stop
# + message add a memory to the CLAUDE.md file (help it to avoid error in the future)
Shift + Tab, Shift + Tab switch to plan mode
/simplify review the changed code (based on git diff). It fixes the reuse opportunities, the code quality issues and the efficiency improvements
/compact summarize conversation and continue (helps Claude stay focused but remember what it has learned in the current session)
/clear dumps current conversation history
/doctor diagnostic

CLAUDE.md

# scan the codebase, create a summary and write it into CLAUDE.md
# this file is included in every request
/init
File Description
CLAUDE.md
  • generated with /init
  • commit to source control
  • shared with other developers
CLAUDE.local.md
  • do not commit to source control
  • not shared with other developers
  • contains personal instructions and customizations
∼/.claude/CLAUDE.md
  • used with all projects on your machine
  • contains instructions to be used on all projects
∼/.claude/CLAUDE.md
# Global Instructions

## Environment
- Windows 11, PowerShell
- Use Windows paths and PowerShell syntax when giving terminal instructions

## C# Code Style
- Use collection expressions (`[.. x, y]`, `[a, b, c]`) instead of `new[]`, `new List<T>()`, `.ToArray()`, `.ToList()` where applicable (IDE0300). See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0300
- Use collection initializers (`new List<T> { a, b }`) instead of separate `.Add()` calls (IDE0028). See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0028
- Use `record` types for DTOs instead of classes

## Git
- Do NOT add `Co-Authored-By` trailers in commit messages

Configuration

Never edit the ∼/.claude.json file.
∼/.claude/settings.json
{
  "model": "eu.anthropic.claude-opus-4-6-v1",
  "alwaysThinkingEnabled": true,
  "effortLevel": "medium"
}

Permissions

∼/.claude/settings.json
{
  "permissions": {
    "allow": [
      "Read",  // read any file
      "mcp__playwright"
    ],
    "deny": []
  }
}
.claude/settings.local.json
{
  "permissions": {
    "allow": [
      "Bash(dotnet test:*)",
      "Bash(dotnet build:*)",
      "Bash(xargs grep:*)",
      "Bash(cd /c/folder/my-project && git:*)"
    ]
  }
}

Custom commands

.claude/commands/cmd1.md
Description of the cmd1. Use $ARGUMENTS

Do the following:

1. Task 1
2. Task 2
Restart Claude Code to have a newly created command available.
/cmd1

MCP servers

Fichier:Claude.svg
/mcp list

Playwright

Allow claude to use a browser.

claude mcp add playwright npx @playwright/mcp@latest
Fichier:Claude.svg
Open the browser and navigate to localhost:3000

Hooks

You have to restart Claude any time you change a hook.
Hooks
Hook name Description
Notification Runs when Claude Code sends a notification, which occurs when Claude needs permission to use a tool, or after Claude Code has been idle for 60 seconds
Stop Runs when Claude Code has finished responding
SubagentStop Runs when a subagent (these are displayed as a "Task" in the UI) has finished
PreCompact Runs before a compact operation occurs, either manual or automatic
UserPromptSubmit Runs when the user submits a prompt, before Claude processes it
SessionStart Runs when starting or resuming a session
SessionEnd Runs when a session ends
Tool names
Tool name Description
Read Read a file
Edit, MultiEdit Edit an existing file
Write Create a file and write to it
Bash Execute a command
Glob Find files and folders based upon a pattern
Grep Search for content
Task Create a sub-agent to complete a particular task
WebFetch, WebSearch Search or fetch a particular page
.claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Read|Grep",
        "hooks": [
          {
            "type": "command",
            "command": "node ./hooks/read_hook.js"
          }
        ]
      }
    ],
    "PostToolUse": [
      /* ... */
    ]
  }
}
./hooks/read_hook.js
async function main() {
  const chunks = [];
  for await (const chunk of process.stdin) {
    chunks.push(chunk);
  }
  const toolArgs = JSON.parse(Buffer.concat(chunks).toString());

  const readPath = toolArgs.tool_input?.file_path || toolArgs.tool_input?.path || "";

  if (readPath.include('.env')) {
    console.error("You cannot read the .env file");
    process.exit(2);
  }
}

main();
/* PreToolUse Read stdin example  */
{
  "session_id": "xxx-...",
  "transcript_path": "/Users/xxx/...",
  "hook_event_name": "PreToolUse",
  "tool_name": "Read",
  "tool_input": {
    "file_path": "/folder/file.ext"
  }
}

SDK

claude -p "prompt"
import { query, SDKMessage } from "@anthropic-ai/claude-code";

const prompt = "prompt";

for await (const message of query({
    prompt,
    options: {
        allowedTools: ["Edit"] // only Read by default
    }
})) {
    console.log(message);
}
import anyio
from claude_code_sdk import query

async def main():
    prompt = "prompt"
    async for message in query(prompt=prompt)
        print(message)

anyio.run(main)

Install