# Project Initialization

> Initializes a project from the standard dual-runtime template, preserves existing files, configures Git hooks, and creates or connects a private GitHub repository with main and dev branches. Use when: "инициализируй проект", "создай новый проект", "init project", "initialize project"

- Skill: `pavel-molyanov/project-initialization-2` (Agent Skill, multi-file: 17 files)
- Install (CLI): `npx skillmds@latest add pavel-molyanov/project-initialization-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/pavel-molyanov/project-initialization-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: pavel-molyanov (https://skillmd.com/u/pavel-molyanov)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/pavel-molyanov/project-initialization-2

---

<!-- Generated by sync-to-codex v1. Do not edit directly. -->

# Project Initialization

Initialize the project in the current working directory. Existing project files are preserved in
an `old*` directory for later review; do not merge them into the new scaffold during this workflow.

## Dual-Runtime Project Generation

The bundled template contains Claude project sources under `.claude/**`. Its pre-commit hook runs
the installed `~/.claude/scripts/sync-to-codex.sh` converter after those sources are staged. This
generates and stages the matching `AGENTS.md` and `.codex/**` runtime before the commit while
`.gitignore` excludes host-local `.codex/.sync/**`. A reported conflict or validation error stops
the commit.

## 1. Check the Current Directory

Work only in the current directory. If it is already a Git repository with uncommitted changes,
ask whether to commit them first, continue while preserving them in `old*`, or stop. Do not proceed
until the user chooses.

Resolve the directory of this loaded `project-initialization` skill and set `INIT_SKILL_DIR` to that
absolute path. Verify that its `assets/new-project/` directory exists before moving project files.

## 2. Preserve Existing Files and Apply the Template

If the current directory contains anything other than `.git`, move all such entries into the first
available directory named `old`, `old2`, `old3`, and so on. Do not move `.git`.

```bash
OLD_DIR=""
if find . -mindepth 1 -maxdepth 1 ! -name '.git' -print -quit | grep -q .; then
  OLD_DIR="old"
  N=2
  while [ -e "$OLD_DIR" ]; do OLD_DIR="old${N}"; ((N++)); done
  mkdir "$OLD_DIR"
  find . -mindepth 1 -maxdepth 1 ! -name '.git' ! -name "$OLD_DIR" -exec mv -- {} "$OLD_DIR/" \;
fi

cp -rp "$INIT_SKILL_DIR/assets/new-project/." .
```

If `OLD_DIR` is non-empty, inspect it for `.env*`, `*.key`, `*.pem`, `credentials.json`, and
`secrets/`. Ensure every sensitive path is covered by the new `.gitignore` before staging files.
Never print secret contents.

## 3. Initialize Git and Hooks

Initialize Git with `main` as the primary branch when needed. For an existing repository, preserve
its history and make the current primary branch `main`. Then:

1. Make `.githooks/pre-commit` executable.
2. Set `git config core.hooksPath .githooks`.
3. Stage the scaffold and preserved `old*` directory, subject to the secret check above.
4. Create the first initialization commit. The pre-commit hook generates and stages `AGENTS.md`
   and `.codex/**` while `.gitignore` excludes `.codex/.sync/**`. If generation reports a conflict
   or validation error, the commit stops. If the repository already has history, create a normal
   initialization commit instead of rewriting existing commits.

## 4. Connect GitHub and Create Branches

GitHub is required for this workflow. Verify that `gh` is installed and authenticated.

- If `origin` already exists, show its URL and ask whether it is the intended repository. Stop on
  a mismatch rather than replacing the remote. Confirm through `gh` that the repository is private;
  if it is public, stop and ask whether to make it private or use another repository.
- If `origin` does not exist, ask for the GitHub repository name unless already supplied. The
  supplied name authorizes creating the private repository. Create it with
  `gh repo create {name} --private --source=. --remote=origin`.

Before any push, inspect whether a local or remote `dev` branch already exists. If neither exists,
create `dev` from `main`. If either exists, show its relationship to `main` and ask whether to reuse
it; never reset or recreate an existing `dev`, and stop if local and remote histories conflict.

Ask explicitly before pushing `main`. After approval, push `main`, push the created or approved
`dev`, leave `dev` checked out, and read the canonical repository URL through `gh`.

## 5. Report the Result

Report:

- the GitHub URL;
- the created or reused `main` and `dev` branches;
- the preserved `old*` directory, or that the directory was initially empty;
- that `dev` is the active branch;
- the next step: create the initial Project Knowledge with `documentation-writing`.

Do not review or merge files from `old*` during initialization.

