iTranslated by AI
Standardizing AI Development: Streamlining Setup with init-claude.sh, Hooks, and MEMORY.md

Introduction
When developing with AI, do you find yourself setting everything up from scratch every single time?
"Do I have to rewrite the rules that worked in the previous project?"
"Do I have to manually search for my credentials again?"
"Do I have to go through the same hook configurations again?"
I solved this problem through templating. I created a system where I can set up an AI development environment with a single command, bash init-claude.sh ., whenever I start a new micro-app.
In this article, I will introduce the structure and design philosophy of this system.
Overall Architecture
_templates/
├── claude-hooks/
│ ├── settings.json # Claude Code hooks configuration
│ ├── hooks/
│ │ ├── pre-compact.sh # Save state before context compression
│ │ ├── on-session-start.sh # Restore state after compression
│ │ └── on-stop.sh # Record file changes upon response completion
│ └── state/ # Directory for auto-saved state files
├── CLAUDE.md # Development rule template
└── init-claude.sh # One-shot initialization script
1. init-claude.sh — One-shot Initialization
bash init-claude.sh .
This simple command performs the following:
- Creates the
.claude/directory - Copies
settings.json(hooks configuration) - Copies 3 hook scripts and grants execution permissions
- Creates the
state/directory - Copies
CLAUDE.md
This eliminates the need to manually configure hooks every time you start a new project.
Design Highlights
-
Templates are consolidated in
_templates/. Since they are copied for each project, there are no dependencies between projects. -
Project-specific customization happens after initialization. I assume you will add app-specific rules to
CLAUDE.mdafter running the script.
2. Hooks — Triple Automation
Using Claude Code's hooks feature, I trigger automated processes during three specific events.
PreCompact: Saving State Before Context Compression
Claude Code automatically compresses context when it becomes too long. Once compressed, there is a risk that your current work state may be lost.
The PreCompact hook saves the current work state to .claude/state/current-task.md right before compression.
# pre-compact.sh (summary)
# Writes the current task state to a file
SessionStart: Restoring State After Compression
When a session is resumed after compression, it automatically injects the saved state. This allows the AI to immediately grasp "what it was doing last time."
Stop: Recording Changes After Response Completion
Every time an AI response is completed, a list of changed files is recorded in .claude/state/session-log.md. This allows humans to verify "what changed" after the session ends.
Resolving Hook Paths (A Common Pitfall)
Hooks commands are resolved as relative paths from the current directory. If you cd into a different directory while working, the script will not be found, leading to errors.
As a workaround, move to the git root at the beginning of the command:
{
"type": "command",
"command": "cd \"$(git rev-parse --show-toplevel)\" && bash .claude/hooks/on-stop.sh"
}
This ensures that hooks work correctly regardless of which directory you are in.
3. CLAUDE.md — Development Rules
CLAUDE.md placed in the project root is a definition file for development rules to be followed by the AI. The template includes the following common rules.
Development Philosophy
This project is a "one-week build, serverless, one-time purchase Pro" micro-app.
Do not aim for perfection; just ship it. Do not add features; trim them.
By explicitly stating the nature of the project at the beginning, you prevent the AI from suggesting over-engineering.
Handling Information Requiring Accuracy
Values that must be accurate, such as credentials, API keys, IDs, and URLs,
must never be output from memory.
Always verify them from sources such as files or logs before using them.
AI cannot distinguish between "remembering" and "generating." Without this rule, there is a risk that it might output non-existent authentication IDs when resuming sessions.
Git Operations
- main: Do not commit directly
- dev: Development branch. Work here
- Always obtain human approval before pushing. Do not push on your own
Explicitly limit the AI to prevent it from performing unauthorized git push operations.
4. MEMORY.md — AI Persistent Memory
Claude Code includes a persistent memory feature called MEMORY.md. However, it has a 200-line limit. If you write everything in one file, it will overflow immediately.
Solution: Topic-based Splitting + Indexing
.claude/memory/
├── MEMORY.md # Index (links and summaries only; under 200 lines)
├── credentials.md # Credentials (persistent storage for accurate values)
└── debug-lessons.md # Debugging lessons
MEMORY.md focuses on being an index:
# MEMORY.md
## Credentials
→ Refer to credentials.md
## Debugging Lessons
→ Refer to debug-lessons.md
Details are written in each topic file. This allows you to effectively bypass the 200-line limit.
credentials.md is Particularly Important
Persistently store values where accuracy is absolutely required, such as authentication keys, API IDs, and Issuer IDs. The AI reads values from here.
# credentials.md
## App Store Connect API
- Key ID: XXXXXXXXXX
- Issuer ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
- Key file: ~/.appstoreconnect/private_keys/AuthKey_XXXXXXXXXX.p8
Without this, the AI might "generate" a plausible-looking UUID when resuming a session.
5. Common Documentation (_docs/)
I consolidate knowledge that can be reused across projects into _docs/.
_docs/
├── README.md # List of documentation
├── project-init.md # Project setup guide
├── revenuecat.md # RevenueCat setup procedure
├── firebase-hosting.md # Firebase Hosting setup
├── app-store.md # App Store Connect procedure
├── release-checklist.md # Pre-release checklist
├── flutter-theme.md # Flutter theme guidelines
├── claude-code-ops.md # Claude Code operations guide
├── landing-page.md # LP implementation guide
└── l10n.md # Localization guide
When starting a new project, I have the AI read these documents before starting the setup. By simply instructing it to "Set up RevenueCat," it proceeds according to the patterns in revenuecat.md.
Why Templating is Important
In micro-app development, the goal is to "ship in one week." Spending one day on setup is fatal within that one-week timeframe.
With templates:
| Item | Without Templates | With Templates |
|---|---|---|
| AI Dev Environment Setup | 30 mins – 1 hour | 1 minute via bash init-claude.sh .
|
| Describing Dev Rules | Rewrite every time | Copy + Customize |
| Hook Configuration | Manual every time | Auto-copy |
| Managing Credentials | Search every time | Read from credentials.md
|
| RevenueCat etc. Setup | Research every time | Follow _docs/ guides |
The speed of actual development is 90% determined by preparation before you start.
Conclusion
To make AI development repeatable, you need:
- init script: Initialize the AI development environment with one command
- hooks: Automate context compression, session restoration, and change logging
- CLAUDE.md: Clearly define development rules for the AI (especially rules for "information requiring accuracy")
- Structured MEMORY.md: Bypass the 200-line limit using index + topic files
- Common documentation: Aggregate cross-project knowledge
Once you set these up, development of your second app and beyond will be dramatically faster. By simply stopping the "from scratch every time" habit, your collaborative efficiency with AI will change significantly.
The structure of this article was born from the actual experience of developing "Saisai" in four days.
completed
Discussion