# Audit Filesystem Changes

> Inspect and analyze what an agent did during a session
> Canonical HTML: https://tursodb.cn/docs/agentfs/guides/auditing/
> Upstream Source (MIT): https://docs.turso.tech/agentfs/guides/auditing
> Language: en

---
AgentFS records every file operation and tool call, giving you complete visibility into agent behavior. This is essential for debugging, compliance, and understanding how agents work.

## Viewing the Timeline

See a chronological list of tool calls:

```bash
agentfs timeline my-session
```

Output:

```
ID   TOOL                 STATUS       DURATION STARTED
4    execute_code         pending            -- 2024-01-05 09:44:20
3    api_call             error           300ms 2024-01-05 09:44:15
2    read_file            success          50ms 2024-01-05 09:44:10
1    web_search           success        1200ms 2024-01-05 09:43:45
```

### Filtering Results

Show only specific tool types:

```bash
agentfs timeline my-session --filter web_search
```

Show only errors:

```bash
agentfs timeline my-session --status error
```

Limit number of entries:

```bash
agentfs timeline my-session --limit 20
```

### JSON Output

For programmatic analysis:

```bash
agentfs timeline my-session --format json
```

```json
[
  {
    "id": 1,
    "name": "web_search",
    "status": "success",
    "started_at": 1704447825,
    "completed_at": 1704447826,
    "duration_ms": 1200,
    "parameters": {"query": "AI agents"},
    "result": {"results": ["result1", "result2"]}
  }
]
```

## Inspecting Files

List all files in a session:

```bash
agentfs fs ls my-session
```

Output:

```
d artifacts
f config.json
f output.txt
```

List a subdirectory:

```bash
agentfs fs ls my-session /artifacts
```

Read file contents:

```bash
agentfs fs cat my-session /output.txt
```

## Viewing Changes (Diff)

See what changed compared to the original filesystem:

```bash
agentfs diff my-session
```

This shows:

* New files created
* Modified files
* Deleted files

## Querying with SQL

Since AgentFS uses SQLite, you can run arbitrary queries:

<div class="doc-tabs" data-doc-tabs>
<div class="doc-tab-list" role="tablist">
<button type="button" role="tab" class="doc-tab-btn is-active" aria-selected="true" data-tab-idx="0">Turso</button>
<button type="button" role="tab" class="doc-tab-btn" aria-selected="false" data-tab-idx="1">SQLite</button>
</div>
<div class="doc-tab-panel is-active" role="tabpanel" data-tab-panel="0">

```bash
tursodb .agentfs/my-session.db
```

</div>
<div class="doc-tab-panel" role="tabpanel" data-tab-panel="1" hidden>

```bash
sqlite3 .agentfs/my-session.db
```

</div>
</div>


Example queries:

```sql
-- Find all tool calls that took longer than 1 second
SELECT name, duration_ms
FROM toolcalls
WHERE duration_ms > 1000;

-- Count tool usage by type
SELECT name, COUNT(*) as count
FROM toolcalls
GROUP BY name
ORDER BY count DESC;

-- Find files modified in the last hour
SELECT path, mtime
FROM fs_inode
WHERE mtime > strftime('%s', 'now', '-1 hour');

-- Get total bytes written
SELECT SUM(size) as total_bytes
FROM fs_inode
WHERE mode & 0170000 = 0100000;  -- regular files only
```

## Use Cases

### Debugging Agent Failures

When an agent fails, use the timeline to understand what happened:

```bash
# See recent activity
agentfs timeline my-session --limit 20

# Focus on errors
agentfs timeline my-session --status error

# Check what files were created/modified
agentfs fs ls my-session
```

### Performance Analysis

Find slow operations:

```sql
SELECT name, AVG(duration_ms) as avg_ms, COUNT(*) as count
FROM toolcalls
GROUP BY name
ORDER BY avg_ms DESC;
```

### Compliance Auditing

Export a complete record of agent activity:

```bash
agentfs timeline my-session --format json > audit-log.json
```

## Next Steps

<div class="doc-cards">
<a class="doc-card" href="/docs/agentfs/guides/overlay/"><div class="doc-card-title"><span>Overlay Filesystem</span><span class="doc-card-arrow" aria-hidden="true">→</span></div><p class="doc-card-desc">Understanding copy-on-write</p></a>
<a class="doc-card" href="/docs/agentfs/guides/sync/"><div class="doc-card-title"><span>Syncing</span><span class="doc-card-arrow" aria-hidden="true">→</span></div><p class="doc-card-desc">Sync sessions to Turso Cloud</p></a>
</div>
