After a while of coding with AI, three things kept bothering me:
- Every new conversation started from zero. I had to explain again where we stopped, which approaches had already failed and which conventions we had settled on.
- Past decisions lost their reasons. Two weeks later neither I nor the AI remembered why a piece of code looked the way it did, so the AI might “improve” it back to an approach we had already rejected.
- Private details slipped into commits: real host addresses, usernames, home paths, even tokens.
So I built a rules repository called agent-system. It isn’t a program. It’s a set of rule files, a few short scripts and three commands, wired into Claude Code and Codex so that every project works the same way. This post covers how it runs, what it adds to the built-in features, and where it still falls short.
Overall structure
The architecture. Rules are maintained only in the repository at the top, linked into the tools, and generated into each project by scripts.
There are three parts:
- The rules repository (top). It lives in git at a fixed place in my home directory and holds the shared rules
RULE.md, the rules for code projectsprofiles/code.md, project templates, a few scripts, the three commands, and its own decision log and tests. - Local tool config (middle).
bin/installlinks both~/.claude/CLAUDE.mdand~/.codex/AGENTS.mdto the sameRULE.md, links the three commands into Claude Code’s skills folder, and checks that the start-of-session hook is registered. Change a rule once and every project in both tools follows. - Projects (bottom). Each project sits in a
P0NN_name/container folder that holds the project repository and amaterials/folder kept out of git. Every project repository has:AGENTS.md: rules specific to this project;CLAUDE.mdis a symlink to it, so both tools read the same file;docs/project-notes.md: at the top is the in-progress block (headed 进行中 in my files), the entry point for the next session;docs/decisions.md,pitfalls.md,log.md: decisions, pitfalls, and the stage and verification log;.git/hooks/pre-commit: a link to the shared privacy check;private-notes.md: real hosts and usernames, kept out of git; committed files use placeholders.
A new project takes one bin/new-project command. For a folder that already has content, I type /adopt in Claude: it checks first and proposes a migration plan, then carries it out after I confirm.
How a session runs
One session. Blue is what I type, orange happens on its own, and the green line shows that the state lives in git, where the next session picks it up.
- The session opens. The SessionStart hook reads the project’s in-progress block, the last 3 decisions and the git state, and injects them for the model. It also checks two things: whether commits made after the in-progress block skipped updating it (so it may be stale), and whether
AGENTS.mdor the project notes have grown past their line limits. Only the model sees this; nothing shows on screen. - The start. To see the state, I type
/pickup: it re-reads everything from disk and only reports, it doesn’t act. To keep working, I say “continue”: the agent recaps where we stopped in a few lines, then takes the next step from the in-progress block. For a quick question or a one-off review I just ask, with no recap. - Work. A decision worth recording goes into
decisions.mdon the spot, numbered D-n. Non-obvious steps come with their basis, such as “per D-12”. Checks are reported honestly: if only part of something was proven, it doesn’t count as passing. - Wrap-up. I type
/wrap: it fills in any missing decisions, rewrites the in-progress block, updates the log and todo list, checks for broken characters and links, and ends with a four-part report: what was done, how it was verified, what wasn’t done, where to start next. - Commit. Only when I say so. The pre-commit hook blocks tokens, private IPs, home paths and broken characters; for tokens it reports only the line number, so the token isn’t printed again. The commit body says
Why: D-n, tying the change to its decision.
Midway through a conversation I can type /pickup again. Then it adds one more line, “new in this session”: work that’s done but not yet in the in-progress block.
How the rules are layered and when they load
Four layers of rules; higher ones win when they conflict. The bottom two rows aren’t always loaded; they enter the context only when needed.
The more rules there are, the more context they take and the less reliably the model follows them. Claude Code’s documentation recommends keeping each CLAUDE.md file under 200 lines. So I split the rules by when they’re needed:
- What every session needs goes in
RULE.md(163 lines) and the project’sAGENTS.md, loaded every session; - What only code projects need goes in
profiles/code.md(124 lines); once a project declares it at the top ofAGENTS.md, the agent reads it on demand; - Step-by-step procedures live in the three commands. They set
disable-model-invocation, so their full text loads only when I type them, their descriptions take no context otherwise, and the model can’t invoke them on its own.
Codex gets only RULE.md. I use Codex just for code review and one-off non-coding tasks that need no handoff between sessions, so giving it the hook and commands too would only add maintenance.
The decision log: keeping the “why”
decisions.md is the part I find most useful. Each decision records the context, options, choice, reason and impact; numbers only go up and never change. When a decision is overturned, the old entry’s heading gets “replaced by D-n” and stays. Rule files and code comments cite the number instead of repeating the reason, and commit messages say Why: D-n.
Three months on, a strange-looking piece of code leads through the number in its comment to the trade-off behind it. And when an agent in a new session wants to “improve” something, it sees first why that idea was rejected.
The log can bloat, though. In the first day and a half of building this repository I recorded 28 decisions in 341 lines, and many were one-off implementation choices. So I raised the bar: record only my decisions, choices that change how later work is done, and corrections to earlier conclusions; implementation details and verification go in the commit message.
How it changed over two days
Structural decisions only. Half of what was added on day two was soon withdrawn or changed.
Looking back at the timeline, the interesting part isn’t what was added but what was taken back:
- A hook and skills for Codex (D-25). Following a “compare with the latest practices” line of thought, I felt both tools should be equal. Only afterwards did we pin down that I use Codex for one-off jobs, so it was withdrawn (D-27). Lesson: ask how a tool is actually used before adapting for it.
- A JSON summary at session start (D-26). So that I’d see the state as soon as a session opened, the hook switched to JSON output, which took about 60 lines of escaping code; and if the JSON is ever malformed, Claude drops the whole output. It went back to plain text (D-28), keeping only the fix for an encoding bug the tests had turned up along the way.
- Removing and restoring
/pickup(D-30, D-33). It was removed because the start-of-session hook already injects the state. But using the plain word “continue” to show the state isn’t precise: it also tells the agent to start working, and midway through a conversation the snapshot from the start is already stale. So it came back as a read-only command that only I can run.
The principle I ended up with is three words: simple, minimal, efficient. Before adding a mechanism, weigh how much maintenance it adds against how much trouble it saves.
Compared with Claude Code’s built-in features
| Area | agent-system | Built into Claude Code |
|---|---|---|
| Handoff between sessions | The in-progress block lives in git in a fixed format and works across machines and tools; /pickup shows it anytime |
/resume restores a conversation; /recap summarizes the current session; auto memory is written by Claude, kept on the machine, with no fixed format |
| Decision log | D-n numbers, replacement links, Why: D-n in commits |
No equivalent |
| Verification discipline | Rules separate “verified this time” from “on record”; a partial check isn’t a pass | None |
| Privacy check before commits | pre-commit blocks tokens, IPs and paths without echoing tokens | Claude Code doesn’t check what gets committed |
| Project setup | new-project and /adopt, with handoff and decision structure |
/init writes a CLAUDE.md from the code |
None of this is new technology: symlinks, git hooks, a few dozen lines of bash. What I think is worth pointing out is the combination: the handoff, the decisions and the verification, which tend to get lost with each conversation, become files in git with a fixed format, and a hook and a few commands feed them back into every session.
The rules repository is managed the same way: 36 decisions so far, and 103 regression tests for its scripts. Review, tests and scans together caught several real problems: an empty file when a project name contained /, a single bad byte in the project notes losing the whole in-progress block, the privacy check erroring on large files, and a new token rule mistaking Swift code for a token. Each fix came with a test.
Where it still falls short
- Wrapping up depends on me remembering.
/wraponly runs when I type it; if I forget, the in-progress block stays out of date. The only safety net is the “may be stale” warning at the start of the next session. - Profiles depend on the agent reading them. To save context, the code-project rules aren’t loaded automatically. I haven’t seen them skipped, but that’s no guarantee.
- Parallel sessions rely on a convention. The rule says only one session per project writes the decisions and the in-progress block. Once I had two sessions editing this repository at the same time, and both used the number D-22.
- Secret detection is my own regular expressions. It knows common token formats and assignments like
TOKEN=…, but it covers less than a dedicated scanner. - It has only run on one Mac. The scripts target the bash 3.2 that ships with macOS and haven’t been tested on Linux; the rules are written in Chinese and fit one person’s habits.
- How it interacts with the built-in
/initis untested. The project’s CLAUDE.md is a symlink, and I haven’t tried what/initdoes with it; the docs just say not to use it in these projects. - The process itself has a cost. Recording decisions, updating the in-progress block and the wrap-up report all take time. Small tasks skip the recap and the wrap-up, but overall it’s still heavier than just letting the AI write code.
The repository isn’t public, and much of it is conventions that only suit me. If you use Claude Code or Codex too, the two ideas most worth borrowing may be these: keep a “where to start next” block in each project, and write down decisions with their reasons under numbers.