Skip to content
file-system logo

File System Operations

file-system

Safe filesystem operations for agents, including path normalization vs resolution, temp file handling, atomic replacement, and spooled buffers. Use when reading/writing user-supplied paths, staging outputs, or managing temporary files; triggers: filesystem, os.path, tempfile, path normalization, ...

SKILL.md

Full skill instructions

File System Operations

Overview

Apply safe path handling and temporary file patterns so reads and writes are reliable, even with untrusted input or large intermediate data.

When to Use

  • Use this skill only after the frontmatter triggers; otherwise start with a simple read/​write path.

Decision Tree

  1. Normalize or resolve the path?
    • Normalize only: use os.path.normpath() for lexical cleanup.
    • Resolve + check existence: use os.path.realpath(path, strict=True).
  2. Are you writing to a target path that may already exist?
    • Yes: write to a temp file in the same directory and replace.
  3. Is the file size unknown or potentially large?
    • Yes: use tempfile.SpooledTemporaryFile to avoid unnecessary disk writes.

Workflows

1. Normalize vs Resolve Paths

  1. Normalize user input with os.path.normpath() to collapse redundant segments.
  2. Resolve real paths with os.path.realpath(path, strict=True) when you must confirm the file exists.
  3. Reject paths that fail resolution or escape your allowed base directory.

2. Atomic Replace Write

  1. Create a temporary file in the destination directory.
  2. Write and flush content to the temp file.
  3. Replace the destination with os.replace/os.rename after the write completes.
  4. Ensure the temp file and destination are on the same filesystem.

3. Spooled Temporary Buffer

  1. Create tempfile.SpooledTemporaryFile(max_size=...).
  2. Stream data into the spooled file as you process it.
  3. Call .rollover() to force the buffer onto disk when needed.

Non-Obvious Insights

  • normpath is lexical only and can change the meaning of a path with symlinks.
  • realpath(..., strict=True) raises FileNotFoundError when the path does not exist.
  • os.rename is atomic on POSIX when successful; keep temp and destination on the same filesystem.
  • Temporary files may not have a visible name; do not rely on name visibility.
  • Spooled temp files can be forced to disk with rollover() when a file grows.

Evidence

  • "Normalize a pathname by collapsing redundant separators and up-level references so that A//B, A/​B/, A/​./​B and A/​foo/​../​B all become A/​B. This string manipulation may change the meaning of a path that contains symbolic links." - Python Docs
  • "FileNotFoundError is raised if path does not exist, or another OSError if it is otherwise inaccessible." - Python Docs
  • "If successful, the renaming will be an atomic operation (this is a POSIX requirement)." - Python Docs
  • "Rename the file or directory src to dst. If dst exists and is a file, it will be replaced silently if the user has permission. The operation may fail if src and dst are on different filesystems." - Python Docs
  • "TemporaryFile, NamedTemporaryFile, TemporaryDirectory, and SpooledTemporaryFile are high-level interfaces which provide automatic cleanup and can be used as context managers." - Python Docs
  • "should not rely on a temporary file created using this function having or not having a visible name in the file system." - Python Docs
  • "rollover() ... causes the file to roll over to an on-disk file regardless of its size." - Python Docs

Scripts

  • scripts/​file-system_tool.py: CLI for resolve, atomic write, copy, and safe reads.
  • scripts/​file-system_tool.js: Node.js CLI equivalents.

Dependencies

  • Python standard library (os, tempfile, pathlib, shutil) or Node standard library (fs, path, os).

References

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View