# Portfolio idea capture
<!-- Add this to ~/.claude/CLAUDE.md (your global Claude Code instructions).
     Replace YOUR-OWNER/YOUR-PORTFOLIO-REPO with your central repository.
     Replace YOUR-GITHUB-USER with the GitHub account that should own the Issues.
     The session-start check also needs the hook in session-start-hook.json. -->
When a message starts with `Capture idea:`, or says "Add to backlog", "Save this idea" or equivalent, create a GitHub Issue using `gh`. Do not write scripts or files.
- **Destination (mandatory):** ALWAYS create the Issue in `YOUR-OWNER/YOUR-PORTFOLIO-REPO`, regardless of the current working repository. Always pass `-R YOUR-OWNER/YOUR-PORTFOLIO-REPO` explicitly. NEVER create a captured idea in the current development repository, and never modify it. The current repository is used ONLY to identify the project association.
- **Project:** work out the current project from the repository context (git remote, folder name, README) and use its friendly name from `PROJECTS.md` (read it with `gh api repos/YOUR-OWNER/YOUR-PORTFOLIO-REPO/contents/PROJECTS.md --jq .content | base64 -d`), not the repo slug. If the idea is for a project that does not exist yet (the user says "new project", or the notes describe a new product not tied to the current repository), the project is `New project`, whatever folder you are in. Otherwise, if the project cannot be confidently identified, use `Unassigned`.
- **Title:** `[Project] — [Short description]` (no brackets in the real title), a concise description written by you.
- **Body:** the user's notes exactly as written, verbatim. Add nothing to the body: no requirements, implementation detail or approval metadata. Pass it through a quoted here-doc so quotes, backticks and `$` survive:
  `gh issue create -R YOUR-OWNER/YOUR-PORTFOLIO-REPO --title "Project — Short description" --label idea --label "Project" --body-file - <<'IDEA'` … notes … `IDEA`
- **Labels:** always two: `idea` (marks it as an unapproved idea) and the project's friendly name exactly as used in the title (e.g. `My App`, `New project` or `Unassigned`). Pass both: `--label idea --label "My App"`. If the project label does not exist (`gh label list -R YOUR-OWNER/YOUR-PORTFOLIO-REPO`), create it first with `gh label create`. No other labels: do not guess types such as bug or enhancement.
- Every captured idea is unapproved. Do not begin work on it.
- Before creating, run `gh auth status` and stop if the active account is not `YOUR-GITHUB-USER`.
- **Verify before reporting (mandatory):** the URL returned by `gh issue create` must begin with `https://github.com/YOUR-OWNER/YOUR-PORTFOLIO-REPO/issues/`. If it does not, report the incorrect destination and do NOT claim a successful Portfolio Control capture.
- On success, reply with the central Issue number and URL only.

# Portfolio review scope
- "What's next?" inside a development repository: review only that repository and its associated Issues, outstanding work and blockers.
- "What's next?" inside the portfolio repository: review the entire portfolio.
- An explicitly named project (e.g. "What's next for My App?"): review only that project, whatever the current workspace.
- An explicit request for a portfolio-wide review: review all projects.
- Use current repository evidence rather than assuming documented work is complete.
- Reviews are read-only unless the user explicitly authorises changes.

# Portfolio session check
Standing authority, so the user never has to remember: keep the backlog in `YOUR-OWNER/YOUR-PORTFOLIO-REPO` in step with the work done in a session. This authorises only creating, commenting on and closing Issues in that repository. It never authorises changing a development repository, deploying, or deleting anything.
- **When:** before your final reply after any real unit of work (a merge, a deploy, a fix, a decision), and whenever the user signals wrapping up ("that's all", "done", "ship"). Skip it for pure Q&A with no work and no new ideas.
- **At session start (crash recovery):** a session that crashed or was closed abruptly never ran its end-check, so treat every new session start in a git repository as that missing check. A SessionStart hook injects the repo state. If it shows uncommitted, unpushed or unmerged work, mention it as possibly interrupted and do not resume it without asking. Then run the close and capture steps below for the project's open Issues, and report in one line before the user's task (say nothing if nothing changed). Without the hook, do the same on the first turn.
- **Close what is done:** `gh issue list -R YOUR-OWNER/YOUR-PORTFOLIO-REPO --state open --label "<Project>"`. For each open Issue whose subject was completed this session, or is verifiably done from current evidence (merged PR, commit, passing check, live URL), close it: `gh issue close N -R YOUR-OWNER/YOUR-PORTFOLIO-REPO --reason completed --comment "Done: <one line of evidence with link or commit>"`. If it is only partly done, or you are unsure, add a comment and leave it open. Never close an Issue on a guess, and never delete one.
- **Capture what came up:** if a genuinely new idea, follow-up, blocker or forgotten deliverable surfaced this session and nobody is doing it now, file it using the idea-capture rules above (same repository, title format, labels `idea` and the project name, URL check). The user did not write it, so the body is one or two factual sentences starting "Auto-captured during a session (not the user's own notes):" with the evidence. Do not invent requirements or scope.
- **Avoid noise:** before filing, list all open and closed Issues (`gh issue list -R YOUR-OWNER/YOUR-PORTFOLIO-REPO --state all --limit 200 --json number,title,state`; do NOT use `--search`, it can return other repositories) and skip anything already logged. Do not file trivia, things already done, things the user rejected, or more than five Issues in one session.
- **Report:** end with one short line listing what was closed and what was captured (numbers and URLs), or "Backlog check: nothing to change".
