backfill 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. backfill-0.3.0/LICENSE +21 -0
  2. backfill-0.3.0/PKG-INFO +231 -0
  3. backfill-0.3.0/README.md +211 -0
  4. backfill-0.3.0/pyproject.toml +47 -0
  5. backfill-0.3.0/setup.cfg +4 -0
  6. backfill-0.3.0/src/backfill/__init__.py +6 -0
  7. backfill-0.3.0/src/backfill/__main__.py +3 -0
  8. backfill-0.3.0/src/backfill/agents/__init__.py +28 -0
  9. backfill-0.3.0/src/backfill/agents/claude.py +551 -0
  10. backfill-0.3.0/src/backfill/agents/codex.py +786 -0
  11. backfill-0.3.0/src/backfill/capture.py +174 -0
  12. backfill-0.3.0/src/backfill/clean.py +365 -0
  13. backfill-0.3.0/src/backfill/cli.py +445 -0
  14. backfill-0.3.0/src/backfill/config.py +272 -0
  15. backfill-0.3.0/src/backfill/core.py +266 -0
  16. backfill-0.3.0/src/backfill/layout.py +110 -0
  17. backfill-0.3.0/src/backfill/legacy.py +146 -0
  18. backfill-0.3.0/src/backfill/ops.py +307 -0
  19. backfill-0.3.0/src/backfill/redact.py +89 -0
  20. backfill-0.3.0/src/backfill/roots.py +84 -0
  21. backfill-0.3.0/src/backfill/runtime.py +135 -0
  22. backfill-0.3.0/src/backfill/status.py +237 -0
  23. backfill-0.3.0/src/backfill/transcript.py +269 -0
  24. backfill-0.3.0/src/backfill/util.py +276 -0
  25. backfill-0.3.0/src/backfill.egg-info/PKG-INFO +231 -0
  26. backfill-0.3.0/src/backfill.egg-info/SOURCES.txt +31 -0
  27. backfill-0.3.0/src/backfill.egg-info/dependency_links.txt +1 -0
  28. backfill-0.3.0/src/backfill.egg-info/entry_points.txt +2 -0
  29. backfill-0.3.0/src/backfill.egg-info/top_level.txt +1 -0
  30. backfill-0.3.0/tests/test_agents.py +306 -0
  31. backfill-0.3.0/tests/test_core.py +220 -0
  32. backfill-0.3.0/tests/test_features.py +276 -0
  33. backfill-0.3.0/tests/test_packaging.py +13 -0
backfill-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dausuva Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: backfill
3
+ Version: 0.3.0
4
+ Summary: Keeps every Claude Code and Codex session of a project in the project itself, automatically.
5
+ Author-email: Dausuva Labs <support@focsd.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/focsd/backfill
8
+ Project-URL: Issues, https://github.com/focsd/backfill/issues
9
+ Project-URL: Source, https://github.com/focsd/backfill
10
+ Keywords: claude,claude-code,codex,logging,ai-agents,transcripts
11
+ Classifier: Environment :: Console
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # backfill
22
+
23
+ Keeps every **Claude Code** and **Codex** session of every project in the project itself, automatically.
24
+ Install it once per computer; from then on each session you start, in any repo, is saved to that repo's
25
+ `.claude-logs/` or `.codex-logs/` folder: readable history, every tool call, raw transcript, per-turn summaries.
26
+ Nothing leaves your machine, the folders ignore themselves in git, and secrets are stripped from the logs by default.
27
+
28
+ ## TL;DR
29
+
30
+ ```bash
31
+ pipx install git+https://github.com/focsd/backfill # pre-release; later: pipx install backfill | brew install focsd/tap/backfill
32
+ backfill install # once per computer: hooks into Claude Code and Codex
33
+ backfill doctor # everything green? then you are done
34
+ ```
35
+
36
+ Restart open Claude Code / Codex sessions. From now on every session in any repo is saved to that repo's `.claude-logs/` / `.codex-logs/` (git-ignored, secrets removed).
37
+
38
+ | You want to | Run |
39
+ |---|---|
40
+ | see what is logged here | `backfill status` |
41
+ | read or search old sessions | `backfill search <text>`, `backfill show` |
42
+ | continue yesterday's work | `backfill digest` (paste into a new session) or `backfill recap` |
43
+ | tune this project | `backfill init --preset minimal\|standard\|everything [--layout monthly]` |
44
+ | free disk space | `backfill clean` (dry run), then `--apply` |
45
+ | stop logging here / everywhere | `backfill off` / `backfill uninstall` |
46
+
47
+ ### Details
48
+
49
+ ```bash
50
+ pipx install backfill # or: uv tool install backfill | brew install focsd/tap/backfill
51
+ backfill install # hooks into Claude Code and Codex (whichever are on this machine)
52
+ backfill status # what is installed, what is logged for the project you are in
53
+ ```
54
+
55
+ > **Status: pre-release.** backfill is not on PyPI or Homebrew yet. Until the first release, install straight from GitHub:
56
+ > `pipx install git+https://github.com/focsd/backfill`. Then run `backfill install`.
57
+
58
+ **Upgrading:** `pipx upgrade backfill` (or `brew upgrade backfill`), then run `backfill install` once more so the hooks' copy in `~/.backfill/` is refreshed.
59
+ **Removing:** `backfill uninstall` removes backfill's hooks from your agent settings (your own entries and the logs stay); `backfill uninstall --purge` also deletes `~/.backfill/`.
60
+
61
+ macOS and Windows are supported; Linux is expected to work and is built in CI, but is not yet a declared target. Needs Python 3.11+ (the Homebrew formula brings it along; on Windows install Python from python.org or the Microsoft Store and tick "Add to PATH"). No third-party Python dependencies.
62
+
63
+ ## What `backfill install` does
64
+
65
+ | Agent | Change (always backed up as `*.bak-<time>`, undone by `backfill uninstall`) |
66
+ |---|---|
67
+ | Claude Code | 8 hooks in `~/.claude/settings.json` (your own hooks stay), instruction block in `~/.claude/CLAUDE.md` |
68
+ | Codex | `notify` in `~/.codex/config.toml` (an existing notify command is **kept and chained**, not replaced), lifecycle hooks in `hooks.json`, instruction block in `AGENTS.md`; JetBrains Codex homes are found too |
69
+ | Both | a copy of the runtime in `~/.backfill/` (`%LOCALAPPDATA%\backfill` on Windows) so hooks keep working when a package manager moves or upgrades its own copy |
70
+
71
+ It also replaces the older `claude-logger` / `codex_repo_logger` hooks (any generation, including `codex_notify_fanout.py` / `codex_notify_router.py`), and imports the existing history
72
+ of the project you ran it in. If your Codex `notify` is a chain (Codex's own Computer Use plugin wraps it with `--previous-notify`), only backfill's link is replaced and the wrapper stays outermost. Hooks never block or fail a session: they always exit 0 and report problems to `~/.backfill/hook-errors.log`.
73
+
74
+ Codex may ask you to review the new lifecycle hooks once: type `/hooks` in Codex. Turn logging works through `notify` even before that.
75
+
76
+ ## Commands
77
+
78
+ | Command | |
79
+ |---|---|
80
+ | `install [--agent claude\|codex] [--codex-profile minimal\|standard\|full] [--retain-days N] [--dry-run]` | hook the agents |
81
+ | `uninstall [--purge]` | remove the hooks (logs are never touched) |
82
+ | `status [--all] [--json]` | installation + what is logged for this project (sessions, turns, size, history waiting to be imported) |
83
+ | `doctor [--json]` | checks that logging will really happen, with a fix hint per problem; exit 1 on failure |
84
+ | `init [--preset minimal\|standard\|everything] [--layout flat\|monthly]` | create `.agents/backfill.toml` for the project |
85
+ | `on` / `off` | switch logging on/off for the project |
86
+ | `sync [--all]` | import history the agents already have, plus logs of the older loggers (`_codex_logs`, `_claude_logs`, `.claude/logs`); safe to repeat, never touches the old folders |
87
+ | `summary` | sessions, turns, tool calls, tokens, models, active days |
88
+ | `search <text>` / `show [session]` | find and read past sessions |
89
+ | `digest` | markdown hand-off of the latest sessions: paste it into a fresh session to continue |
90
+ | `recap [--since 1d] [--all]` | what happened since yesterday / `7d` / a date, per project and session |
91
+ | `clean [--older-than 30] [--apply]` | map what the agents keep on this machine (transcripts, caches, scratchpads, databases, log folders) and prune it safely |
92
+ | `audit [--fix]` | find (and redact) secrets in existing logs |
93
+ | `retain --days N [--apply]` | delete old journals (dry run by default) |
94
+ | `export --output logs.zip`, `list`, `config` | archive, list projects, show effective settings |
95
+
96
+ ## Per-project config: `.agents/backfill.toml`
97
+
98
+ Commit it to share settings with a team. First existing file wins: `.agents/backfill.toml`, `.agents/backfill/config.toml`,
99
+ `.backfill.toml`, `.backfill/config.toml`. A config file also marks the project root (handy in monorepos). `backfill init` writes a commented template:
100
+
101
+ ```toml
102
+ enabled = true # false = log nothing for this project
103
+ agents = ["claude", "codex"]
104
+ [logs]
105
+ claude_dir = ".claude-logs" # one folder name inside the project; paths outside it are rejected
106
+ codex_dir = ".codex-logs"
107
+ layout = "flat" # flat | monthly (YYYY-MM/ folders for journals, histories, transcripts, artifacts)
108
+ [capture]
109
+ preset = "standard" # minimal | standard | everything; keys below override the preset
110
+ transcripts = "raw" # raw | redacted | off
111
+ scratchpad = "manifest" # off | manifest | copy: Claude scratchpad files, Codex generated images
112
+ exclude_tools = ["Read"] # leave these tools' output out of the history and journal
113
+ session_max_mb = 0 # cap on one session's readable history (0 = none); the raw transcript is never capped
114
+ [redact]
115
+ enabled = true
116
+ extra_patterns = ["ACME-[0-9]{8}"]
117
+ [retention]
118
+ days = 0 # used by `backfill retain`
119
+ [context]
120
+ announce = true # tell the agent where earlier sessions live
121
+ resume = false # also hand it a digest of the previous session
122
+ notes = ""
123
+ ```
124
+
125
+ More keys under `[capture]` (all optional): `journal_events = true`, `copy_artifacts = true`, `codex_profile = "standard"` (`minimal|standard|full`, which Codex hooks `backfill install` registers),
126
+ `scratchpad_max_mb = 5`, and the size limits `event_value_limit = 20000`, `markdown_text_limit = 20000`, `markdown_tool_input_limit = 2000`, `markdown_tool_output_limit = 4000` (characters; longer values are cut in the history and journal, never in the raw transcript).
127
+ Unknown keys and wrong types are ignored, so a typo never stops logging; `backfill doctor` lists unknown keys and invalid choices. A project config comes with the repository, so it can only change how *that project* is logged: it cannot point logs outside the project or touch your install.
128
+
129
+ Machine-wide settings live in `~/.backfill/config.toml`; `mode = "opt-in"` there logs only projects that have a config file.
130
+ Project root detection: `BACKFILL_ROOT`, then the nearest config file / `.backfill-root`, `.git`, `.idea`, a manifest
131
+ (`package.json`, `pyproject.toml`, ...), then the working directory. The home directory and the agents' own folders are never logged.
132
+ `BACKFILL_DISABLE=1` stops logging for one process; `~/.backfill/denylist.txt` / `allowlist.txt` list folders, one per line.
133
+
134
+ ## Capture presets
135
+
136
+ | Preset | What it does |
137
+ |---|---|
138
+ | `minimal` | transcript copy + readable history (shorter tool output); no event journal, no artifacts, no scratchpads |
139
+ | `standard` | the default: transcript, history, journal, per-turn summaries, edit backups/todos/subagents, scratchpad manifest |
140
+ | `everything` | standard plus scratchpad and generated-image copies, Codex `full` hook profile, long history limits |
141
+
142
+ Keys you write next to `preset` always win over the preset. `scratchpad = "manifest"` lists the files of a session's scratchpad
143
+ (names, sizes, SHA-256) in `artifacts/<session>/scratchpad-manifest.json`; `"copy"` also keeps files up to 5 MB (`scratchpad_max_mb`), text with secrets removed.
144
+ `exclude_tools` and `session_max_mb` shape the readable history and the journal; the transcript copy is separate (`transcripts = "redacted"` or `"off"` for that).
145
+ `backfill doctor` prints what is and is not covered in the current project (`covers:` lines).
146
+
147
+ ## What is kept
148
+
149
+ ```text
150
+ .claude-logs/ (or .codex-logs/)
151
+ INDEX.md one row per session
152
+ history/<session>.md readable conversation, tool calls and (capped) results
153
+ transcripts/<session>.jsonl the agent's raw transcript, refreshed every turn
154
+ events-DAY.jsonl turns-DAY.jsonl sessions-DAY.jsonl
155
+ artifacts/<session>/ edit backups, todos, subagents, scratchpad manifest/copies (Claude); generated images (Codex)
156
+ session_state/ latest-*.json .gitignore ("*") README.md
157
+ ```
158
+
159
+ With `layout = "monthly"`, everything except `INDEX.md`, `session_state/`, `latest-*.json` and the housekeeping files sits inside `YYYY-MM/` folders
160
+ (`.claude-logs/2026-12/history/...`). A session lives in the month it started; changing the layout later keeps finding earlier files.
161
+
162
+ ## Environment variables
163
+
164
+ | Variable | Effect |
165
+ |---|---|
166
+ | `BACKFILL_DISABLE=1` | log nothing in this process |
167
+ | `BACKFILL_ROOT` | use this folder as the project root |
168
+ | `BACKFILL_HOME`, `CLAUDE_CONFIG_DIR`, `CODEX_HOME` | move backfill's data folder / Claude's / Codex's home |
169
+ | `BACKFILL_ALLOWLIST`, `BACKFILL_DENYLIST` | folders (separated like `PATH`) to log only / never log |
170
+ | `BACKFILL_TAGS`, `BACKFILL_IDE`, `BACKFILL_HOST`, `BACKFILL_WORKSPACE_LABEL` | extra fields in the session records |
171
+ | `BACKFILL_TMP_DIRS` | where to look for Claude Code scratchpads (default: the system temp folders) |
172
+
173
+ ## Troubleshooting
174
+
175
+ - **Nothing is logged:** run `backfill doctor`; every failing check has a fix hint. Restart running Claude Code / Codex sessions after `backfill install`.
176
+ - **Codex logs only some events:** type `/hooks` in Codex once and approve the lifecycle hooks (turn logging works without it).
177
+ - **A session is missing:** `backfill sync` imports what the agents still have; `backfill status` shows sessions waiting to be imported.
178
+ - **Errors inside hooks:** they never break a session; they are written to `~/.backfill/hook-errors.log` (`%LOCALAPPDATA%\backfill\` on Windows).
179
+ - **Logging should stop for one project:** `backfill off` in it (or `enabled = false` in its config); for one run set `BACKFILL_DISABLE=1`.
180
+
181
+ ## Cleaning up (`backfill clean`)
182
+
183
+ Agents keep a lot: Codex rollouts and throw-away folders, Claude edit backups and shell snapshots, scratchpads in the temp folder, databases.
184
+ `backfill clean` lists them with sizes and marks what is safe to prune, always a dry run first:
185
+
186
+ - an agent's own transcript is a candidate **only** when backfill holds a complete copy of that session in a project (otherwise it says `run backfill sync --all`);
187
+ - only items older than `--older-than` days (default 30); running sessions are never that old;
188
+ - `--apply` moves them to `<backfill data>/trash/<time>/` (`--restore <batch>` puts them back, `--empty-trash` frees the space); `--delete` removes for good;
189
+ - databases, credentials, config, memory, skills and plugins are never candidates; project log folders are reported with the `backfill retain` command that prunes them;
190
+ - `--scan ~/dev` also finds log folders of projects backfill has not seen yet.
191
+
192
+ ## Built for real machines
193
+
194
+ Lessons from the earlier Claude and Codex loggers that are built in:
195
+
196
+ - **Overlapping hooks are safe.** Codex runs most hooks asynchronously; a per-session file lock (`flock` / `msvcrt`) means every transcript line is processed exactly once.
197
+ On Windows, replacing a file another process has open is retried instead of failing.
198
+ - **Nothing is overwritten silently.** If an agent rewrites a transcript so that it shrinks, the previous copy is kept as `<session>.prev-<time>.jsonl`.
199
+ - **Read-only folders are skipped quietly** (a session started in `C:\Program Files\...` is not an error).
200
+ - **Where it ran:** session records carry workspace, IDE (`TERM_PROGRAM`, `BACKFILL_IDE`), host, user and `BACKFILL_TAGS`, which helps when several IDEs share a repo.
201
+ - **Env lists:** `BACKFILL_ALLOWLIST` / `BACKFILL_DENYLIST` (paths separated like `PATH`; the old `CODEX_REPO_LOG_*` variables still work).
202
+
203
+ ## Privacy
204
+
205
+ Logs contain full conversations. Redaction removes well-known credential formats (API keys, tokens, private keys, JWTs, URL
206
+ passwords, `password=...`) from journals and histories. The raw transcript copy is byte-exact unless you choose
207
+ `transcripts = "redacted"`. Redaction is best effort: treat the folders like source credentials. `backfill audit` shows what is
208
+ in them. Claude Code deletes its own transcripts after 30 days by default; the copies here are not affected (`--retain-days` also keeps Claude's own).
209
+
210
+ ## Development
211
+
212
+ ```bash
213
+ python -m pip install pytest ruff && python -m pytest -q && ruff check src tests
214
+ python scripts/check_versions.py # the version in the code must match the tag
215
+ ```
216
+
217
+ Layout: `src/backfill/` (core, `agents/claude.py`, `agents/codex.py`), `tests/`. Needs no third-party packages.
218
+
219
+ ## Support and contributing
220
+
221
+ Questions and problems: open an issue, or write to support@focsd.com. Security reports: see `SECURITY.md`. Contributions: see `CONTRIBUTING.md`. Changes per version: `CHANGELOG.md`.
222
+
223
+ ## Releasing (maintainers)
224
+
225
+ 1. Bump `__version__` in `src/backfill/__init__.py`; `python scripts/check_versions.py`.
226
+ 2. Tag `vX.Y.Z` and push: the workflow publishes to PyPI (trusted publisher, environment `pypi`).
227
+ 3. Update `url` and `sha256` in the formula of the `homebrew-tap` repository.
228
+
229
+ ## License
230
+
231
+ MIT, see `LICENSE`.
@@ -0,0 +1,211 @@
1
+ # backfill
2
+
3
+ Keeps every **Claude Code** and **Codex** session of every project in the project itself, automatically.
4
+ Install it once per computer; from then on each session you start, in any repo, is saved to that repo's
5
+ `.claude-logs/` or `.codex-logs/` folder: readable history, every tool call, raw transcript, per-turn summaries.
6
+ Nothing leaves your machine, the folders ignore themselves in git, and secrets are stripped from the logs by default.
7
+
8
+ ## TL;DR
9
+
10
+ ```bash
11
+ pipx install git+https://github.com/focsd/backfill # pre-release; later: pipx install backfill | brew install focsd/tap/backfill
12
+ backfill install # once per computer: hooks into Claude Code and Codex
13
+ backfill doctor # everything green? then you are done
14
+ ```
15
+
16
+ Restart open Claude Code / Codex sessions. From now on every session in any repo is saved to that repo's `.claude-logs/` / `.codex-logs/` (git-ignored, secrets removed).
17
+
18
+ | You want to | Run |
19
+ |---|---|
20
+ | see what is logged here | `backfill status` |
21
+ | read or search old sessions | `backfill search <text>`, `backfill show` |
22
+ | continue yesterday's work | `backfill digest` (paste into a new session) or `backfill recap` |
23
+ | tune this project | `backfill init --preset minimal\|standard\|everything [--layout monthly]` |
24
+ | free disk space | `backfill clean` (dry run), then `--apply` |
25
+ | stop logging here / everywhere | `backfill off` / `backfill uninstall` |
26
+
27
+ ### Details
28
+
29
+ ```bash
30
+ pipx install backfill # or: uv tool install backfill | brew install focsd/tap/backfill
31
+ backfill install # hooks into Claude Code and Codex (whichever are on this machine)
32
+ backfill status # what is installed, what is logged for the project you are in
33
+ ```
34
+
35
+ > **Status: pre-release.** backfill is not on PyPI or Homebrew yet. Until the first release, install straight from GitHub:
36
+ > `pipx install git+https://github.com/focsd/backfill`. Then run `backfill install`.
37
+
38
+ **Upgrading:** `pipx upgrade backfill` (or `brew upgrade backfill`), then run `backfill install` once more so the hooks' copy in `~/.backfill/` is refreshed.
39
+ **Removing:** `backfill uninstall` removes backfill's hooks from your agent settings (your own entries and the logs stay); `backfill uninstall --purge` also deletes `~/.backfill/`.
40
+
41
+ macOS and Windows are supported; Linux is expected to work and is built in CI, but is not yet a declared target. Needs Python 3.11+ (the Homebrew formula brings it along; on Windows install Python from python.org or the Microsoft Store and tick "Add to PATH"). No third-party Python dependencies.
42
+
43
+ ## What `backfill install` does
44
+
45
+ | Agent | Change (always backed up as `*.bak-<time>`, undone by `backfill uninstall`) |
46
+ |---|---|
47
+ | Claude Code | 8 hooks in `~/.claude/settings.json` (your own hooks stay), instruction block in `~/.claude/CLAUDE.md` |
48
+ | Codex | `notify` in `~/.codex/config.toml` (an existing notify command is **kept and chained**, not replaced), lifecycle hooks in `hooks.json`, instruction block in `AGENTS.md`; JetBrains Codex homes are found too |
49
+ | Both | a copy of the runtime in `~/.backfill/` (`%LOCALAPPDATA%\backfill` on Windows) so hooks keep working when a package manager moves or upgrades its own copy |
50
+
51
+ It also replaces the older `claude-logger` / `codex_repo_logger` hooks (any generation, including `codex_notify_fanout.py` / `codex_notify_router.py`), and imports the existing history
52
+ of the project you ran it in. If your Codex `notify` is a chain (Codex's own Computer Use plugin wraps it with `--previous-notify`), only backfill's link is replaced and the wrapper stays outermost. Hooks never block or fail a session: they always exit 0 and report problems to `~/.backfill/hook-errors.log`.
53
+
54
+ Codex may ask you to review the new lifecycle hooks once: type `/hooks` in Codex. Turn logging works through `notify` even before that.
55
+
56
+ ## Commands
57
+
58
+ | Command | |
59
+ |---|---|
60
+ | `install [--agent claude\|codex] [--codex-profile minimal\|standard\|full] [--retain-days N] [--dry-run]` | hook the agents |
61
+ | `uninstall [--purge]` | remove the hooks (logs are never touched) |
62
+ | `status [--all] [--json]` | installation + what is logged for this project (sessions, turns, size, history waiting to be imported) |
63
+ | `doctor [--json]` | checks that logging will really happen, with a fix hint per problem; exit 1 on failure |
64
+ | `init [--preset minimal\|standard\|everything] [--layout flat\|monthly]` | create `.agents/backfill.toml` for the project |
65
+ | `on` / `off` | switch logging on/off for the project |
66
+ | `sync [--all]` | import history the agents already have, plus logs of the older loggers (`_codex_logs`, `_claude_logs`, `.claude/logs`); safe to repeat, never touches the old folders |
67
+ | `summary` | sessions, turns, tool calls, tokens, models, active days |
68
+ | `search <text>` / `show [session]` | find and read past sessions |
69
+ | `digest` | markdown hand-off of the latest sessions: paste it into a fresh session to continue |
70
+ | `recap [--since 1d] [--all]` | what happened since yesterday / `7d` / a date, per project and session |
71
+ | `clean [--older-than 30] [--apply]` | map what the agents keep on this machine (transcripts, caches, scratchpads, databases, log folders) and prune it safely |
72
+ | `audit [--fix]` | find (and redact) secrets in existing logs |
73
+ | `retain --days N [--apply]` | delete old journals (dry run by default) |
74
+ | `export --output logs.zip`, `list`, `config` | archive, list projects, show effective settings |
75
+
76
+ ## Per-project config: `.agents/backfill.toml`
77
+
78
+ Commit it to share settings with a team. First existing file wins: `.agents/backfill.toml`, `.agents/backfill/config.toml`,
79
+ `.backfill.toml`, `.backfill/config.toml`. A config file also marks the project root (handy in monorepos). `backfill init` writes a commented template:
80
+
81
+ ```toml
82
+ enabled = true # false = log nothing for this project
83
+ agents = ["claude", "codex"]
84
+ [logs]
85
+ claude_dir = ".claude-logs" # one folder name inside the project; paths outside it are rejected
86
+ codex_dir = ".codex-logs"
87
+ layout = "flat" # flat | monthly (YYYY-MM/ folders for journals, histories, transcripts, artifacts)
88
+ [capture]
89
+ preset = "standard" # minimal | standard | everything; keys below override the preset
90
+ transcripts = "raw" # raw | redacted | off
91
+ scratchpad = "manifest" # off | manifest | copy: Claude scratchpad files, Codex generated images
92
+ exclude_tools = ["Read"] # leave these tools' output out of the history and journal
93
+ session_max_mb = 0 # cap on one session's readable history (0 = none); the raw transcript is never capped
94
+ [redact]
95
+ enabled = true
96
+ extra_patterns = ["ACME-[0-9]{8}"]
97
+ [retention]
98
+ days = 0 # used by `backfill retain`
99
+ [context]
100
+ announce = true # tell the agent where earlier sessions live
101
+ resume = false # also hand it a digest of the previous session
102
+ notes = ""
103
+ ```
104
+
105
+ More keys under `[capture]` (all optional): `journal_events = true`, `copy_artifacts = true`, `codex_profile = "standard"` (`minimal|standard|full`, which Codex hooks `backfill install` registers),
106
+ `scratchpad_max_mb = 5`, and the size limits `event_value_limit = 20000`, `markdown_text_limit = 20000`, `markdown_tool_input_limit = 2000`, `markdown_tool_output_limit = 4000` (characters; longer values are cut in the history and journal, never in the raw transcript).
107
+ Unknown keys and wrong types are ignored, so a typo never stops logging; `backfill doctor` lists unknown keys and invalid choices. A project config comes with the repository, so it can only change how *that project* is logged: it cannot point logs outside the project or touch your install.
108
+
109
+ Machine-wide settings live in `~/.backfill/config.toml`; `mode = "opt-in"` there logs only projects that have a config file.
110
+ Project root detection: `BACKFILL_ROOT`, then the nearest config file / `.backfill-root`, `.git`, `.idea`, a manifest
111
+ (`package.json`, `pyproject.toml`, ...), then the working directory. The home directory and the agents' own folders are never logged.
112
+ `BACKFILL_DISABLE=1` stops logging for one process; `~/.backfill/denylist.txt` / `allowlist.txt` list folders, one per line.
113
+
114
+ ## Capture presets
115
+
116
+ | Preset | What it does |
117
+ |---|---|
118
+ | `minimal` | transcript copy + readable history (shorter tool output); no event journal, no artifacts, no scratchpads |
119
+ | `standard` | the default: transcript, history, journal, per-turn summaries, edit backups/todos/subagents, scratchpad manifest |
120
+ | `everything` | standard plus scratchpad and generated-image copies, Codex `full` hook profile, long history limits |
121
+
122
+ Keys you write next to `preset` always win over the preset. `scratchpad = "manifest"` lists the files of a session's scratchpad
123
+ (names, sizes, SHA-256) in `artifacts/<session>/scratchpad-manifest.json`; `"copy"` also keeps files up to 5 MB (`scratchpad_max_mb`), text with secrets removed.
124
+ `exclude_tools` and `session_max_mb` shape the readable history and the journal; the transcript copy is separate (`transcripts = "redacted"` or `"off"` for that).
125
+ `backfill doctor` prints what is and is not covered in the current project (`covers:` lines).
126
+
127
+ ## What is kept
128
+
129
+ ```text
130
+ .claude-logs/ (or .codex-logs/)
131
+ INDEX.md one row per session
132
+ history/<session>.md readable conversation, tool calls and (capped) results
133
+ transcripts/<session>.jsonl the agent's raw transcript, refreshed every turn
134
+ events-DAY.jsonl turns-DAY.jsonl sessions-DAY.jsonl
135
+ artifacts/<session>/ edit backups, todos, subagents, scratchpad manifest/copies (Claude); generated images (Codex)
136
+ session_state/ latest-*.json .gitignore ("*") README.md
137
+ ```
138
+
139
+ With `layout = "monthly"`, everything except `INDEX.md`, `session_state/`, `latest-*.json` and the housekeeping files sits inside `YYYY-MM/` folders
140
+ (`.claude-logs/2026-12/history/...`). A session lives in the month it started; changing the layout later keeps finding earlier files.
141
+
142
+ ## Environment variables
143
+
144
+ | Variable | Effect |
145
+ |---|---|
146
+ | `BACKFILL_DISABLE=1` | log nothing in this process |
147
+ | `BACKFILL_ROOT` | use this folder as the project root |
148
+ | `BACKFILL_HOME`, `CLAUDE_CONFIG_DIR`, `CODEX_HOME` | move backfill's data folder / Claude's / Codex's home |
149
+ | `BACKFILL_ALLOWLIST`, `BACKFILL_DENYLIST` | folders (separated like `PATH`) to log only / never log |
150
+ | `BACKFILL_TAGS`, `BACKFILL_IDE`, `BACKFILL_HOST`, `BACKFILL_WORKSPACE_LABEL` | extra fields in the session records |
151
+ | `BACKFILL_TMP_DIRS` | where to look for Claude Code scratchpads (default: the system temp folders) |
152
+
153
+ ## Troubleshooting
154
+
155
+ - **Nothing is logged:** run `backfill doctor`; every failing check has a fix hint. Restart running Claude Code / Codex sessions after `backfill install`.
156
+ - **Codex logs only some events:** type `/hooks` in Codex once and approve the lifecycle hooks (turn logging works without it).
157
+ - **A session is missing:** `backfill sync` imports what the agents still have; `backfill status` shows sessions waiting to be imported.
158
+ - **Errors inside hooks:** they never break a session; they are written to `~/.backfill/hook-errors.log` (`%LOCALAPPDATA%\backfill\` on Windows).
159
+ - **Logging should stop for one project:** `backfill off` in it (or `enabled = false` in its config); for one run set `BACKFILL_DISABLE=1`.
160
+
161
+ ## Cleaning up (`backfill clean`)
162
+
163
+ Agents keep a lot: Codex rollouts and throw-away folders, Claude edit backups and shell snapshots, scratchpads in the temp folder, databases.
164
+ `backfill clean` lists them with sizes and marks what is safe to prune, always a dry run first:
165
+
166
+ - an agent's own transcript is a candidate **only** when backfill holds a complete copy of that session in a project (otherwise it says `run backfill sync --all`);
167
+ - only items older than `--older-than` days (default 30); running sessions are never that old;
168
+ - `--apply` moves them to `<backfill data>/trash/<time>/` (`--restore <batch>` puts them back, `--empty-trash` frees the space); `--delete` removes for good;
169
+ - databases, credentials, config, memory, skills and plugins are never candidates; project log folders are reported with the `backfill retain` command that prunes them;
170
+ - `--scan ~/dev` also finds log folders of projects backfill has not seen yet.
171
+
172
+ ## Built for real machines
173
+
174
+ Lessons from the earlier Claude and Codex loggers that are built in:
175
+
176
+ - **Overlapping hooks are safe.** Codex runs most hooks asynchronously; a per-session file lock (`flock` / `msvcrt`) means every transcript line is processed exactly once.
177
+ On Windows, replacing a file another process has open is retried instead of failing.
178
+ - **Nothing is overwritten silently.** If an agent rewrites a transcript so that it shrinks, the previous copy is kept as `<session>.prev-<time>.jsonl`.
179
+ - **Read-only folders are skipped quietly** (a session started in `C:\Program Files\...` is not an error).
180
+ - **Where it ran:** session records carry workspace, IDE (`TERM_PROGRAM`, `BACKFILL_IDE`), host, user and `BACKFILL_TAGS`, which helps when several IDEs share a repo.
181
+ - **Env lists:** `BACKFILL_ALLOWLIST` / `BACKFILL_DENYLIST` (paths separated like `PATH`; the old `CODEX_REPO_LOG_*` variables still work).
182
+
183
+ ## Privacy
184
+
185
+ Logs contain full conversations. Redaction removes well-known credential formats (API keys, tokens, private keys, JWTs, URL
186
+ passwords, `password=...`) from journals and histories. The raw transcript copy is byte-exact unless you choose
187
+ `transcripts = "redacted"`. Redaction is best effort: treat the folders like source credentials. `backfill audit` shows what is
188
+ in them. Claude Code deletes its own transcripts after 30 days by default; the copies here are not affected (`--retain-days` also keeps Claude's own).
189
+
190
+ ## Development
191
+
192
+ ```bash
193
+ python -m pip install pytest ruff && python -m pytest -q && ruff check src tests
194
+ python scripts/check_versions.py # the version in the code must match the tag
195
+ ```
196
+
197
+ Layout: `src/backfill/` (core, `agents/claude.py`, `agents/codex.py`), `tests/`. Needs no third-party packages.
198
+
199
+ ## Support and contributing
200
+
201
+ Questions and problems: open an issue, or write to support@focsd.com. Security reports: see `SECURITY.md`. Contributions: see `CONTRIBUTING.md`. Changes per version: `CHANGELOG.md`.
202
+
203
+ ## Releasing (maintainers)
204
+
205
+ 1. Bump `__version__` in `src/backfill/__init__.py`; `python scripts/check_versions.py`.
206
+ 2. Tag `vX.Y.Z` and push: the workflow publishes to PyPI (trusted publisher, environment `pypi`).
207
+ 3. Update `url` and `sha256` in the formula of the `homebrew-tap` repository.
208
+
209
+ ## License
210
+
211
+ MIT, see `LICENSE`.
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "backfill"
7
+ dynamic = ["version"]
8
+ description = "Keeps every Claude Code and Codex session of a project in the project itself, automatically."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Dausuva Labs", email = "support@focsd.com" }]
13
+ dependencies = []
14
+ keywords = ["claude", "claude-code", "codex", "logging", "ai-agents", "transcripts"]
15
+ classifiers = [
16
+ "Environment :: Console",
17
+ "Operating System :: MacOS",
18
+ "Operating System :: Microsoft :: Windows",
19
+ "Operating System :: POSIX :: Linux",
20
+ "Programming Language :: Python :: 3",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/focsd/backfill"
25
+ Issues = "https://github.com/focsd/backfill/issues"
26
+ Source = "https://github.com/focsd/backfill"
27
+
28
+ [project.scripts]
29
+ backfill = "backfill.cli:main"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.setuptools.dynamic]
35
+ version = { attr = "backfill.__version__" }
36
+
37
+ [tool.pytest.ini_options]
38
+ testpaths = ["tests"]
39
+ pythonpath = ["src"]
40
+
41
+ [tool.ruff]
42
+ line-length = 140
43
+ target-version = "py311"
44
+
45
+ [tool.ruff.lint]
46
+ select = ["E", "F", "I", "B", "UP"]
47
+ ignore = ["E501"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """backfill: keeps every Claude Code and Codex session of a project in the project itself.
2
+
3
+ Standard library only. ``backfill --help`` lists the commands.
4
+ """
5
+
6
+ __version__ = "0.3.0"
@@ -0,0 +1,3 @@
1
+ from backfill.cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,28 @@
1
+ """Per-agent code: hook handling, installation into the agent's config, and importing existing history."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from backfill.layout import Layout
8
+
9
+
10
+ def session_context(layout: Layout, config: dict[str, Any]) -> str:
11
+ """Text handed to the agent at session start (``[context]`` in the project config)."""
12
+ section = config["context"]
13
+ parts: list[str] = []
14
+ if section["announce"]:
15
+ parts.append(
16
+ f"Session logging is active: this session is saved automatically by backfill to {layout.log_dir}, and "
17
+ f"earlier sessions of this project are listed in {layout.log_dir / 'INDEX.md'} with readable histories under "
18
+ f"{layout.log_dir} (history/ folders). Do not delete, edit or commit that folder (it ignores itself in git)."
19
+ )
20
+ if section["resume"]:
21
+ from backfill.ops import resume_digest
22
+
23
+ digest = resume_digest(layout)
24
+ if digest:
25
+ parts.append("Where the previous session stopped (from backfill):\n" + digest)
26
+ if section["notes"].strip():
27
+ parts.append(section["notes"].strip())
28
+ return "\n\n".join(parts)