# AI Database Silmeye Çalışınca Wrapper Yaptım

[r/ClaudeAI](https://www.reddit.com/r/ClaudeAI/comments/1o1md1r/i_wrapped_psql_command_to_prevent_claue_code_to/) • [r/ClaudeCode](https://www.reddit.com/r/ClaudeCode/comments/1o1mlpd/i_wrapped_psql_command_to_prevent_claue_code_to/)

{% embed url="<https://youtu.be/WNiksw3mYlU>" %}

Claude Code ile çalışıyordum. Database'de DROP komutları çalıştırıp silmeye çalıştı.

İlk düşünce: AI'ya güven Gerçek: Database neredeyse uçuyordu

İkinci düşünce: Manuel yedek al her seferinde Gerçek: Yedek almayı unutmaya devam ettim

Son karar: `psql` komutunun üstüne wrapper yaptım

## Nasıl Yaparsın

1. `~/.zshrc` dosyanı aç
2. Şu kodu yapıştır:

```bash
y() {
	touch /tmp/claude_approved
	echo "\033[32m✓ Approved\033[0m"
}

psql() {
	if [[ -f /tmp/claude_approved ]]; then
		command rm -f /tmp/claude_approved
		command psql "$@"
		return
	fi

	if echo "$*" | grep -qiE "(SELECT|SHOW|EXPLAIN|ANALYZE|\\\\d|\\\\l|\\\\x)"; then
		command psql "$@"
		return
	fi

	echo "⚠️  UNSAFE database operation"
	echo "ACTION: Ask user to type '!y' by telling HOW AWARE YOU ARE, then retry this command"
	return 1
}
```

3. Terminal'de `source ~/.zshrc` çalıştır
4. Artık Claude tehlikeli komut çalıştırmak isterse sana soracak

## Ne Olur

Şimdi Claude tehlikeli bir şey yapmak istediğinde bana soruyor. Ve sadece "soruyor" değil - farkında olduğu şeyi tam olarak açıklıyor. Bak ne diyor: "Tüm veri silinecek. Geri alınamaz. Backup yoksa veri kaybolur."

Manyak database silecek ama en azından bana söylüyor.

Sonra ben `!y` yazıyorum. Ünlem karakteri ile komut çalıştırıyorum, approve ediyorum.

## Nasıl Çalışıyor

* Claude tehlikeli komut çalıştırmak ister → wrapper hata verir
* Claude bana açıklama yapar, ne yapacağını söyler
* Ben `!y` yazarım → tek seferlik approval
* Claude komutu çalıştırır
* Bir sonraki tehlikeli komut için tekrar aynı süreç

Böylece Claude'un kendi wrapper'ının üstüne bir wrapper daha yaptım. Gözden kaçan bir DELETE komutu varsa gözümden kaçmasın. Yapay zeka bana tekrar söylesin: "Her şey silinecek" desin diye.

***

edit: Safe komutlar whitelist'te. SELECT, SHOW, EXPLAIN gibi okuma komutları onay istemiyor. Sadece destructive işlemler için uyarı çıkıyor. Böylece her sorgu için rahatsız etmiyor.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yemreak.com/claude-code/ai-database-silmeye-calisinca-wrapper-yaptim.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
